apollographql / apollographql/federation

Gateway doesn't handle no data from implementing services

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

Description

I've noticed strange gateway behavior in our backend when an implementing service doesn't return `data` in the GraphQL response. Note that it's spec-compliant to return no `data`, specifically when an [error occurs before GraphQL execution](https://spec.graphql.org/June2018/#sec-Data) (in this specific case, it's an auth error).

The query here is
```graphql
query Foo {
me {
id
}
}
```

When I query the `kotlin` implementing service directly, I get back
```json
{
"errors": [
{
"message": "Failed to authenticate with PingOne. Log in to Apollo Studio in a web browser, then try again.",
"locations": [],
"extensions": {
"needsWebLogin": true,
"classification": "DataFetchingException"
}
}
],
"extensions": {
"identity": null,
"apilog-attachments": "[]"
}
}
```
and expectedly, I don't see any `data` here.

However, when I query the gateway, I get back
```json
{
"errors": [
{
"message": "Failed to authenticate with PingOne. Log in to Apollo Studio in a web browser, then try again.",
"extensions": {
"code": "DOWNSTREAM_SERVICE_ERROR",
"serviceName": "kotlin",
"query": "{me{__typename ...on InternalIdentity{id}...on Service{id}...on User{id}}}",
"variables": {},
"needsWebLogin": true,
"classification": "DataFetchingException"
}
}
],
"data": {
"me": null
}
}
```
Oddly `data` is defined in the response, and instead of `data` being `null`, it's `{ me: null }`. This feels unexpected; I could understand if gateway was querying `_entitites()` for some implementing service and that returned no `data`, then the location in the client request that gave rise to the `_entities()` call could be `null` (or it would need to be propagated toward the root if the type was non-nullable). But I'm not sure why no `data` here becomes `data: { me: null }`

Contributor guide

Open the contributing guide

Research direction

Compare the direct response from the Kotlin implementing service with the gateway response for the provided `me` query, and review the GraphQL specification section linked in the issue. Trace how the gateway handles an upstream response without `data`, including the `_entities()` case mentioned. Done means the gateway behavior is defined and matches the intended GraphQL error and null-propagation semantics, with the issue reproduced in coverage.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.