代码之家  ›  专栏  ›  技术社区  ›  stoebelj

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

  •  0
  • stoebelj  · 技术社区  · 7 年前

    这可能是一个基本的Graphql问题,也可能与Apollo工具有关。

    我正试图使用Apollo工具从我的客户端模式生成类型脚本类型。我有一个 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!
    }
    

    基本上是 导航 可以有多个 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 { ... }"?
    

    我做错了什么?我该怎么纠正?

    0 回复  |  直到 7 年前
        1
  •  0
  •   stoebelj    7 年前

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

    在某种程度上,它看起来像这样:

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

    自从我们宣布 children 作为非基元类型( String , Int 它期望我们定义我们期望得到的子字段。所以改成

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

    工作正常