Skip to content
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

errors before data in payloads #4375

Open
BoD opened this issue Dec 13, 2023 · 0 comments · May be fixed by #4728
Open

errors before data in payloads #4375

BoD opened this issue Dec 13, 2023 · 0 comments · May be fixed by #4728
Assignees

Comments

@BoD
Copy link

BoD commented Dec 13, 2023

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 git@github.com: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 apollographql/apollo-kotlin#5470

@nicholascioli nicholascioli self-assigned this Feb 23, 2024
nicholascioli added a commit that referenced this issue Feb 23, 2024
resolves #4375

Previously, the router would always respond with data first, and
then show any errors in the request. The GraphQL spec suggests
having the errors show up before data, so this commit makes
errors output first before data.
@nicholascioli nicholascioli linked a pull request Feb 23, 2024 that will close this issue
6 tasks
nicholascioli added a commit that referenced this issue Mar 4, 2024
resolves #4375

Previously, the router would always respond with data first, and
then show any errors in the request. The GraphQL spec suggests
having the errors show up before data, so this commit makes
errors output first before data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants