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

Error from resolver without extensions[V3 was not adding extensions in any error type from resolvers] #7773

Closed
hiteshbal91dp opened this issue Oct 31, 2023 · 2 comments

Comments

@hiteshbal91dp
Copy link

hiteshbal91dp commented Oct 31, 2023

Issue Description

While migrating from V3 to V4, we haven't changed any code in datasources as migration doc suggest no real changes are required.

Once we upgraded to V4, one of our resolvers throws an error(Normal HTTP error of timeout request). We started receiving following error.

{
  "data": {},
  "errors": [
    {
      "message": "Internal server error",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
  ]
}

Upon debugging we identified the following issue, where error is in "errorNormalize.ts" file where function enrichError has following condition which causes following error.

    const extensions: GraphQLErrorExtensions = {
      ...graphqlError.extensions,
      code:
        graphqlError.extensions.code ??
        ApolloServerErrorCode.INTERNAL_SERVER_ERROR,
    };

Error: "code" of undefined, where extensions does not exists on error.

I would recommend to either add graphqlError.extensions.code with graphqlError.extensions?.code or in ensureGraphQLError function add extensions if error does not has those fields.

Link to Reproduction

https://codesandbox.io/p/sandbox/funny-haibt-s4r82s?file=%2Fsrc%2Findex.ts%3A34%2C14

Reproduction Steps

Note: Somehow above code is not working while it does work on my local machine and as explained in above description we are facing this issue.

@glasser
Copy link
Member

glasser commented Oct 31, 2023

This looks like a bug in graphql-jit.

graphql-jit claims to support any version of graphql >= 15, and did actually have a GraphQL v16 compatibility PR.

Starting with graphql v16.0.0, GraphQLError.extensions is always present.

But graphql-jit defines a subclass of GraphQLError (which it also calls GraphQLError) which sometimes sets extensions to `undefined.

That means this subclass is an incorrect subclass implementation for graphql@16: if the superclass guarantees that a field is always defined, the subclass should never set it to undefined.

I encourage you to file a bug with graphql-jit asking them to ensure that their GraphQLError subclass never creates errors that fail to fit the requirements of a graphql@16 GraphQLError.

Copy link
Contributor

github-actions bot commented Dec 1, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants