-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Propagate graphql response regardless of the subgraph HTTP status code. #1664
Conversation
This comment has been minimized.
This comment has been minimized.
…s code. fixes: #1335, #1662 Subgraph service calls used to return an error when the received HTTP status code isn't 200. There's however no mention in the GraphQL specification that leads us to assume anything about the HTTP status code returned by a GraphQL server. This commit removes our HTTP status code check in the `subgraph_service`.
b969803
to
d1d47c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does the gateway do right now? |
Good question. The gateway uses make-fetch-happen under the hood, which invokes fetch AFAICT.
Make fetch happen also explicitely mentions they don't throw on errors:
It's worth noting the gateway's fetcher explicitly disables retries. @abernix you probably know your way around the gateway better than I do, please correct me if I'm wrong |
Sounds about right! I was curious if we'd tried running a query through it using the same subgraphs with failing status code conditions on it and observed the behavior (in case we wrap its errors or anything). |
Thanks for calling it out! I'll spin up a gateway tomorrow and make sure it behaves the same! |
I just tried to compare the router and the gateway's behavior if a subgraph returns an error: CURL command: curl --request POST \
--header 'content-type: application/json' \
--url http://localhost:<ROUTER_OR_GATEWAY_PORT> \
--data '{"query":"query Me {\n me {\n name\n username\n }\n}"}' | jq gateway response: {
"errors": [
{
"message": "400: Bad Request",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"response": {
"url": "http://localhost:8000/",
"status": 400,
"statusText": "Bad Request",
"body": {
"errors": [
{
"message": "Cannot query field \"me\" on type \"Query\".",
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Cannot query field \"me\" on type \"Query\".",
" at Object.Field (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:51:13)",
" at Object.enter (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/language/visitor.js:301:32)",
" at Object.enter (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/utilities/TypeInfo.js:391:27)",
" at visit (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/language/visitor.js:197:21)",
" at validate (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/validation/validate.js:91:24)",
" at validate (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/requestPipeline.js:186:39)",
" at processGraphQLRequest (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/requestPipeline.js:98:34)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async processHTTPRequest (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/runHttpQuery.js:220:30)"
]
}
}
}
]
}
},
"exception": {
"stacktrace": [
"Error: 400: Bad Request",
" at RemoteGraphQLDataSource.errorFromResponse (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/datasources/RemoteGraphQLDataSource.js:158:21)",
" at RemoteGraphQLDataSource.sendRequest (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/datasources/RemoteGraphQLDataSource.js:98:34)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async RemoteGraphQLDataSource.process (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/datasources/RemoteGraphQLDataSource.js:73:26)",
" at async sendOperation (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/executeQueryPlan.js:225:26)",
" at async /Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/executeQueryPlan.js:166:49",
" at async executeNode (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/executeQueryPlan.js:129:17)",
" at async /Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/executeQueryPlan.js:29:35",
" at async /Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/@apollo/gateway/dist/index.js:124:38",
" at async execute (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/gateway/node_modules/apollo-server-core/dist/requestPipeline.js:202:20)"
]
}
}
}
],
"data": {
"me": null
}
} router response: {
"data": null,
"errors": [
{
"message": "Cannot query field \"me\" on type \"Query\".",
"locations": [],
"path": null,
"extensions": {
"code": "GRAPHQL_VALIDATION_FAILED",
"exception": {
"stacktrace": [
"GraphQLError: Cannot query field \"me\" on type \"Query\".",
" at Object.Field (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:51:13)",
" at Object.enter (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/language/visitor.js:301:32)",
" at Object.enter (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/utilities/TypeInfo.js:391:27)",
" at visit (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/language/visitor.js:197:21)",
" at validate (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/graphql/validation/validate.js:91:24)",
" at validate (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/requestPipeline.js:186:39)",
" at processGraphQLRequest (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/requestPipeline.js:98:34)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async processHTTPRequest (/Users/ignition/projects/apollo/router/dockerfiles/federation2-demo/subgraphs/users/node_modules/apollo-server-core/dist/runHttpQuery.js:220:30)"
]
}
}
}
]
} The "response" field is missing in the router, but we can follow up on that (I suspect it's because of the way we deal with errors in the |
@o0Ignition0o Are we tracking this 😄 follow-up anywhere? (I'm on the right issue now!) |
Oh I see, Opening an issue! |
Fix: Propagate graphql response regardless of the subgraph HTTP status code.
fixes: #1335, fixes #1662
Subgraph service calls used to return an error when the received HTTP status code isn't 200.
There's however no mention in the GraphQL specification that leads us to assume any intent behind the HTTP status code returned by a GraphQL server.
This commit removes our HTTP status code check in the
subgraph_service
.