阿波罗工具:在另一个定义类型中包含一个定义类型

时间:2019-04-09 18:35:24

标签: graphql apollo

这可能是Graphql的基本问题,或者可能与Apollo Tooling相关。

我正在尝试使用Apollo Tooling从我的客户端模式生成打字稿类型。我有一个NavItem类型,看起来像这样:

type NavItem {
  id: ID!
  to: String!
  icon: String!
  text: String!
  highlight: String!
  children: [NavItemChild]
}

type NavItemChild {
  id: ID!
  to: String!
  icon: String!
  text: String!
  highlight: String!
}

NavItem基本上可以有多个NavItemChildren。当我使用apollo codegen:generate src/graphql/types --target=typescript --outputFlat生成类型时,出现错误

Field "children" of type "[NavItemChild]" must have a selection of subfields. Did you mean "children { ... }"?

我在做什么错,应该如何纠正?

1 个答案:

答案 0 :(得分:0)

问题出在我试图为以下类型生成类型的查询中:

部分看起来像这样:

links {
  to,
  icon,
  text,
  highlight,
  children,
}

由于我们将children声明为非原始类型(StringInt等),因此我们希望可以定义我们希望返回的子字段。因此将其更改为

        links {
          to,
          icon,
          text,
          highlight,
          children {
            to,
            icon,
            text,
            highlight,
          }
        }

工作正常

相关问题