apollographql / apollographql/federation

Union federation fails when __typename is in query

Open
#254 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

**Demo repository**: https://github.com/TheAschr/federation-bug-demo

I have a specific situation where federation of a union fails. here is my query:

```gql
{
accounts {
id
user {
... on StandardUser {
id
film {
id
__typename
}
}
... on AdminUser {
id
film {
id
review {
id
}
}
}
}
}
}
```

Here is the response I get:

```gql
{
"errors": [
{
"message": "Field \"reviewId\" was not found in response.",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Field \"reviewId\" was not found in response.",
" at executeSelectionSet (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:217:27)",
" at executeSelectionSet (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:236:51)",
" at C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:121:36",
" at Array.forEach ()",
" at executeFetch (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:120:18)",
" at executeNode (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:82:23)",
" at executeNode (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:73:33)",
" at executeNode (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:56:46)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)",
" at async Object.executeQueryPlan (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\executeQueryPlan.js:22:27)",
" at async Object.ApolloGateway.executor (C:\\Users\\me\\Documents\\github\\federation-demo\\node_modules\\@apollo\\gateway\\dist\\index.js:109:30)"
]
}
}
}
],
"data": {
"accounts": [
{
"id": "1",
"user": {
"id": "1",
"film": {
"id": "1",
"review": null
}
}
},
{
"id": "2",
"user": {
"id": "2",
"film": {
"id": "1",
"__typename": "Film"
}
}
}
]
}
}
```

I believe it must be a bug because when I remove __typename the query completes:

```gql
{
accounts {
id
user {
... on StandardUser {
id
film {
id
}
}
... on AdminUser {
id
film {
id
review {
id
}
}
}
}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the query against the linked federation-bug-demo repository and compare it with the version that omits __typename. Start from the executeSelectionSet stack trace in @apollo/gateway/dist/executeQueryPlan.js; done means the union query completes without the missing reviewId error and preserves the expected response.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.