gpt4 book ai didi

graphql 未使用别名时出现 FieldsConflict 类型的验证错误

转载 作者:行者123 更新时间:2023-12-02 03:21:18 24 4
gpt4 key购买 nike

当我在请求中未使用别名时,收到错误“FieldsConflict 类型的验证错误”。请确认这是否符合预期或是否有解决方法

{
person(search: [{firstname: "DAN", lastname: "WATLER", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}

person(search: [{firstname: "FRANK", lastname: "TEE", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
}

上面的代码给出了验证错误,但如果我使用下面所示的别名,错误不会出现,并且我会得到成功的响应。

我不想使用别名,请建议是否有任何解决方法。谢谢!

{
dan: person(search: [{firstname: "DAN", lastname: "WATLER", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}

frank: person(search: [{firstname: "FRANK", lastname: "TEE", country: "FRANCE"}])
{
firstname
lastname
country
age
address
}
}

最佳答案

通常 GraphQL 以 JSON 对象的形式返回数据,并且 JSON 文档中不可能有 2 个具有相同键的(有效)对象(在您的情况下 person )。因此,实现您所描述的目标几乎是不可能的。

您的第一个查询的结果将类似于:

{
"data": {
"person": {
"firstname": "DAN",
...
},
"person": { // this is not valid
"firstname": "FRANK"
...
}
}
}

这就是为什么你必须使用别名

另一个选项是查看 GraphQL 服务器是否有一个返回 person 列表的查询,并且结果将位于数组内部,例如:

{
"data": [
{
"firstname": "DAN",
...
},
{
"firstname": "FRANK",
...
}
[
}

关于graphql 未使用别名时出现 FieldsConflict 类型的验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54705734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com