router
router copied to clipboard
`errors` before `data` in payloads
Describe the bug
The GraphQL spec recommends having errors first in the payloads.
However the router does the opposite (data first) even when the original subgraph payload has the preferred order.
To Reproduce
# Clone the repo
git clone [email protected]:apollographql/apollo-kotlin.git
cd apollo-kotlin
git checkout a02f2f34bcead68dee75b6a4512f8e0227f29367
# Start subgraph on 4001
(cd tests/defer/router/subgraphs/computers && npm install && APOLLO_PORT=4001 npm start)&
# Start router on 4000
/Tmp/router/router --supergraph tests/defer/router/simple-supergraph.graphqls &
# Query the subgraph
curl --request POST --header 'content-type: application/json' --url 'http://127.0.0.1:4001/' --data '{"query":"query HandlesErrorsThrownInDeferredFragmentsQuery { computer(id: \"Computer1\") { id errorField } }"}'
# Query the router
curl --request POST --header 'content-type: application/json' --url 'http://127.0.0.1:4000/' --data '{"query":"query HandlesErrorsThrownInDeferredFragmentsQuery { computer(id: \"Computer1\") { id errorField } }"}'
Result from subgraph:
{
"errors": [
{
"message": "Error field",
"locations": [
{
"line": 1,
"column": 84
}
],
"path": [
"computer",
"errorField"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Error field",
" at Object.errorField (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/computers.js:28:19)",
" at field.resolve (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:56:26)",
" at executeField (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:481:20)",
" at executeFields (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:413:20)",
" at completeObjectValue (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:914:10)",
" at completeValue (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:635:12)",
" at executeField (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:489:19)",
" at executeFields (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:413:20)",
" at executeOperation (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:344:14)",
" at execute (/Users/bod/gitrepo/apollo-kotlin-0/tests/defer/router/subgraphs/computers/node_modules/graphql/execution/execute.js:136:20)"
]
}
}
}
],
"data": {
"computer": {
"id": "Computer1",
"errorField": null
}
}
}
errors are first.
Result from router:
{"data":{"computer":{"id":"Computer1","errorField":null}},"errors":[{"message":"Subgraph errors redacted","locations":[{"line":1,"column":93}],"path":["computer","errorField"]}]}
data is first.
Expected behavior The spec recommendation should be followed.
Tested on 1.35.0
Additional context Related to https://github.com/apollographql/apollo-kotlin/issues/5470