GatoGraphQL / GatoGraphQL

Interact with all your data in WordPress using GraphQL

Home Page:https://gatographql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnionTypeResolvers: Querying the same field multiple times, or different fields with same alias, override each other

leoloso opened this issue · comments

When executing this query:

{
  customPosts {
    __typename
    id
    title @upperCase
    self {
      title
    }
  }
}

The response should be:

{
  "data": {
    "customPosts": [
      {
        "__typename": "Page",
        "id": 2,
        "title": "SAMPLE PAGE",
        "self": {
          "title": "Sample Page"
        }
      },
      {
        "__typename": "Post",
        "id": 1,
        "title": "HELLO WORLD!",
        "self": {
          "title": "Hello world!"
        }
      }
    ]
  }
}

But instead it is:

{
  "data": {
    "customPosts": [
      {
        "__typename": "Page",
        "id": 2,
        "self": {
          "title": "Sample Page"
        }
      },
      {
        "__typename": "Post",
        "id": 1,
        "self": {
          "title": "Hello world!"
        }
      }
    ]
  }
}

In this case, the title field under self is overriding the value of the first title field. Hence, the value "Hello world!" is overriding value "HELLO WORLD!". That's a bug.

To test in GraphQL by PoP, use query:

?query=customPosts.__typename|id|title%3CupperCase%3E|self.title