zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 615 forks source link

Invalid result data when two list items nearly identical #1406

Closed rpekarek-tc closed 7 months ago

rpekarek-tc commented 7 months ago

I have a complex data structure being returned from our CMS via graphql. Inside this structure there is a list of items each with a nested sublist. Two of these items are exactly the same, with the exception of the contents of their sublist. When I execute my query in the apollo graphQL playground, my data is returned as expected (two items returned, each with different sublists).

However when I run the same query with the graphql package in Flutter, the latter of the two items is returned twice. I've verified this by reversing the order they are listed in our CMS. Whichever one is last is returned twice, and the first is not returned at all. See query and return values below:

query:

  query getCMSPage() {
    CMS_pageCollection(limit: 1, where: {  id: "my_page_id" }) {
      items {
        id
        sectionsCollection(limit: 2)  {
          items {
            id
            nestedSublist {
              items {
                name
              }
            }
          }
        }
      }
    }
  }

result:

{
  "data": {
    "CMS_pageCollection": {
      "items": [
        {
          "id": "my_page_id",
          "sectionsCollection": {
            "items": [
              {
                "id": "identical_item_id",
                "nestedSublist": {
                  "items": [
                    {
                      "name": "Unique ONE" // With Apollo Playground (expected)
                      // OR                      
                      "name": "Unique TWO" // With graphql package
                    }
                  ]
                }
              },
              {
                "id": "identical_item_id",
                "nestedSublist": {
                  "items": [
                    {
                      "name": "Unique TWO"
                    }
                  ]
                }
              },
            ]
          }
        }
      ]
    }
  }
}

Expected behavior The unique sublists should be returned on each item, rather than two duplicate items

device / execution context Tested on an iOS simulator, bug reported on a physical iOS device.

additional context We use Contentful for content management, this issue is not present on our adjacent web app using the same query

additional notes This seems like an over-optimization issue. Is id by chance a keyword that would cause these two items to return the same json? When I change the id of one of the two items, they return as expected

rpekarek-tc commented 7 months ago

Update: This appears to be working according to design, as specified here: https://github.com/zino-hofmann/graphql-flutter/blob/41cd27ea2c849dd286bf328793c9679472a0e483/packages/graphql/README.md?plain=1#L574-L587