简体   繁体   English

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

[英]graphql Validation error of type FieldsConflict coming when alias is not used

I am getting the error "Validation error of type FieldsConflict" when i am not using aliases in my request. 当我在请求中未使用别名时,出现错误“ FieldsConflict类型的验证错误”。 kindly confirm if this is expected or if there is a workaround 请确认是否符合预期或有解决方法

{
    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      
    }
}

Above code gives validation error but if I use aliases shown below, error doesn't come and I get successful response. 上面的代码给出了验证错误,但是如果我使用下面显示的别名,则错误不会出现,并且我将获得成功的响应。

I dont want to use aliases, please suggest if any workaround. 我不想使用别名,请提出任何解决方法。 Thanks ! 谢谢 !

{
    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      
    }
}

Usually GraphQL returns data as JSON objects, and it is not possible to have 2 (valid) objects in a JSON document with the same key (in your case person ). 通常, GraphQL将数据作为JSON对象返回,并且在JSON文档中不可能有两个具有相同键的(有效)对象(在您的情况下为person )。 Hence, it is pretty impossible to achieve what you are describing. 因此,要实现您所描述的内容几乎是不可能的。

The result of your first query would be something like: 您的第一个查询的结果将类似于:

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

And that is why you have to use alias . 这就是为什么您必须使用alias

Another option would be to see if the GraphQL server has a query that returns a list of person and the result would be inside of an array, like: 另一个选择是查看GraphQL服务器是否具有返回person列表的查询,并且结果将在数组内部,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM