这可能是一个基本的Graphql问题,也可能与Apollo工具有关。
我正试图使用Apollo工具从我的客户端模式生成类型脚本类型。我有一个 NavItem 类型如下:
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 我有个错误
导航
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 { ... }"?
我做错了什么?我该怎么纠正?
问题出在我试图为以下对象生成类型的查询中:
在某种程度上,它看起来像这样:
links { to, icon, text, highlight, children, }
自从我们宣布 children 作为非基元类型( String , Int 它期望我们定义我们期望得到的子字段。所以改成
children
String
Int
links { to, icon, text, highlight, children { to, icon, text, highlight, } }
工作正常