我的项目有问题,我在互联网上找不到任何解决方案 . 这是情况 .
-
我是两种类型的联盟("DataResult")("Teaser"&"Program")
-
我的"Zone"类型带有"data"字段(数组"DataResult")
-
"Teaser"&"Program"具有相同的"title"字段,具有不同的类型(String vs String!)
以下是“Zone”,“Teaser”和“Program”模式的部分:
type Program {
title: String
}
type Teaser {
title: String!
}
union DataResult = Teaser | Program
type Zone {
(...)
data: [DataResult!]
}
当我尝试查询区域数据时,如下面的查询部分所述,我从graphQL得到了一个错误 .
zones {
...zoneFieldsWithoutData
data {
... on Program {
...programFields
}
... on Teaser {
...teaserFields
}
}
}
这是错误:
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
我不能使用别名,因为规范需要所有“DataResult”实体的相同属性名称 . 我能做什么 ?
而且,即使我为“ Headers ”设置了相同的类型,我也会在控制台中发出很多关于“缺少字段”的警告....
PS:我使用Vanilla Apollo作为graphQL客户端(在服务器端)
1 回答
它是根据规范实现的:见3.a at:http://facebook.github.io/graphql/draft/#SameResponseShape()
有关详细信息,请参阅https://github.com/graphql/graphql-js/issues/1361#issuecomment-393489320 .