Jul*_*eon 12 javascript apollo graphql
我的项目有问题,我在互联网上找不到任何解决方案.情况就是这样.
以下是"Zone","Teaser"和"Program"模式的部分:
type Program {
title: String
}
type Teaser {
title: String!
}
union DataResult = Teaser | Program
type Zone {
(...)
data: [DataResult!]
}
Run Code Online (Sandbox Code Playgroud)
当我尝试查询区域数据时,如下面的查询部分所述,我从graphQL得到了一个错误.
zones {
...zoneFieldsWithoutData
data {
... on Program {
...programFields
}
... on Teaser {
...teaserFields
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
Error: GraphQL error: Fields \"title\" conflict because they return conflicting types String and String!. Use different aliases on the fields to fetch both if this was intentional
Run Code Online (Sandbox Code Playgroud)
我不能使用别名,因为规范需要所有"DataResult"实体的相同属性名称.我能做什么 ?
而且,即使我为"标题"设置相同的类型,我也会在控制台中发出很多关于"缺少字段"的警告....
PS:我使用Vanilla Apollo作为graphQL客户端(在服务器端)
我知道你不能使用别名,但对于其他可以使用别名的人(包括我):
从github获取的简单答案是使用字段别名:
zones {
... on Program {
programTitle: title
}
... on Teaser {
teaserTitle: title
}
}
Run Code Online (Sandbox Code Playgroud)
它是根据规范实现的:参见 3.a: http: //facebook.github.io/graphql/draft/#SameResponseShape()
有关更多详细信息,请参阅https://github.com/graphql/graphql-js/issues/1361#issuecomment-393489320 。
| 归档时间: |
|
| 查看次数: |
1178 次 |
| 最近记录: |