_entities resolution with duplicate representations

I maintain the absinthe_federation library for Elixir and I had an issue reported that sparked some interesting questions about the behavior of the _entities field. The github issue is here data._entities elements amount bug · Issue #32 · DivvyPayHQ/absinthe_federation · GitHub but basically the issue that we ran across is what should happen when the following query is made where two duplicate representations for the same entity are included in a _entities request. we optimized that into a single resolution but the gateway doesnt seem to like that the response is deduplicated.

query ($representations: [_Any!]!) {
  _entities(representations: $representations) {
    ... on User {
      name
      email
    }
  }
}

variables

{
  "representations": [
    {"__typename": "User", "email": "support@apollographql.com"},
    {"__typename": "User", "email": "support@apollographql.com"}
  ]
}

Hey @kdawgwilk, this is a reasonable question. Right now the gateway doesn’t support subgraphs deduping entities in this manner (as you’ve observed). We think this is an execution concern that should be resolved in the gateway/router instead (deduping before issuing the request). Going forward, my recommendation would be to stop deduping within the subgraph implementation (though maybe you can achieve the same efficiency another way if it’s critical?).

I’m not certain on the timeline for when we might resolve this in the gateway, but it’s on the router team’s radar variable deduplication · Issue #87 · apollographql/router · GitHub.

You’ll see there’s also a linked issue to resolve this very thing in the gateway in that issue thread.

I haven’t considered if / what the implications of a change like this might be, but I’d be happy to collaborate (as guidance / reviewer) on a PR with you or anyone interested in tackling this issue.

Thanks for the response, we ended up merging a change to remove the deduplication as you suggested

1 Like