movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 55 forks source link

Repeated selections for distinct field names are dropped during merge #87

Closed gmac closed 2 years ago

gmac commented 2 years ago

Low-priority edge case: when making a query selection with multiple selections on a distinct field, data is only returned for the first selection...

query {
  shop1 {
    products {
      name
    }
    products {
      manufacturer {
        name
      }
    }
  }
}

This query only returns data for the first field selection, while technically it should return a union of the two:

{
  "data": {
    "shop1": {
      "products": [
        {
          "name": "iPhone"
        },
        {
          "name": "Apple Watch"
        }
      ]
    }
  }
}

The query plan looks about like I'd expect, and my remote servers are executing the appropriate steps:

{
    "RootSteps": [{
        "ServiceURL": "http://localhost:4003/graphql",
        "ParentType": "Query",
        "SelectionSet": "{ shop1 { _id: id products { _id: id } products { _id: id } } }",
        "InsertionPoint": null,
        "Then": [{
            "ServiceURL": "http://localhost:4002/graphql",
            "ParentType": "Product",
            "SelectionSet": "{ _id: id name }",
            "InsertionPoint": ["shop1", "products"],
            "Then": null
        }, {
            "ServiceURL": "http://localhost:4002/graphql",
            "ParentType": "Product",
            "SelectionSet": "{ _id: id manufacturer { _id: id } }",
            "InsertionPoint": ["shop1", "products"],
            "Then": [{
                "ServiceURL": "http://localhost:4001/graphql",
                "ParentType": "Manufacturer",
                "SelectionSet": "{ _id: id name }",
                "InsertionPoint": ["shop1", "products", "manufacturer"],
                "Then": null
            }]
        }]
    }]
}

Therefore, I'd venture to guess that the loss of data happens in the post-request assembly process. Logging this here as a backlog item.

nmaquet commented 2 years ago

Thanks for reporting this! We'll look into it in the coming days.