【问题标题】:Is it possible to have nested union types in TypeGraphQL?TypeGraphQL 中是否可以有嵌套的联合类型?
【发布时间】:2021-03-20 17:21:53
【问题描述】:

假设我有两种联合类型,如下所示:

import { createUnionType } from "type-graphql";

const InstagramUnion = createUnionType({
  name: "Instagram",
  types: () => [InstagramWidget1, InstagramWidget2] as const,
});

const SpotifyUnion = createUnionType({
  name: "Spotify",
  types: () => [SpotifyWidget1, SpotifyWidget2] as const,
});

目前,我无法创建上述两个联合的联合:

const WidgetUnion = createUnionType({
  name: "Widget",
  types: () => [SpotifyUnion, InstagramUnion] as const, // error, not assignable
});

可以这样做吗?基本上,我需要一个如下所示的联合:

InstagramWidget1 | InstagramWidget2 | SpotifyWidget1 | SpotifyWidget2

【问题讨论】:

  • 您找到解决方案了吗?如果是这样,请在此处分享。

标签: typescript graphql typegraphql


【解决方案1】:

不,在任何 GraphQL 实现中都不可能,因为 GraphQL 规范不支持它。

【讨论】:

    猜你喜欢
    • 2020-12-20
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2018-07-26
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多