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

GraphQLError.extensions are optional while in graphql-js those mandatory parameter. #234

Open
hiteshbal91dp opened this issue Nov 1, 2023 · 1 comment

Comments

@hiteshbal91dp
Copy link

We are using graphql-jit with Apollo Server version 4(migrating from version 3). We are facing following explained issue.

apollographql/apollo-server#7773

apollographql/apollo-server#7774

Both issue boiled down to same issue of having different definition of GraphQLError in graphql-jit library. If we have same definition of error class the issue seems to be resolved.

@casey-chow
Copy link

I was able to work around this with the following code:

        let res = await compiledQuery.query(
          undefined,
          context,
          request.variables ?? {}
        );

        if (isNotNil(res.errors)) {
          res = {
            ...res,
            errors: res.errors.map((error) => {
              if (isNotNil(error.extensions)) {
                return error;
              }

              // HACK: Recreate the error to fix the formatting, because
              // graphql-jit's error shape is non-standard.
              // https://github.com/zalando-incubator/graphql-jit/issues/234
              const newError = new GraphQLError(error.message);
              Object.assign(newError, error);
              return newError;
            }),
          };
        }

This is obviously not great, we have to re-allocate the error every time (the Object.defineProperty usage makes it impossible to overwrite, so a copy is needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants