【问题标题】:Apollo-tooling: including a defined type in another defined typeApollo-tooling:在另一个定义的类型中包含一个定义的类型
【发布时间】:2019-08-31 02:59:54
【问题描述】:

这可能是一个基本的 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 { ... }"?

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

【问题讨论】:

    标签: graphql apollo


    【解决方案1】:

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

    部分看起来像这样:

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

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

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

    工作正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      相关资源
      最近更新 更多