Skip to content
Discussion options

You must be logged in to vote

See this section:

You can replace this with

import { GraphQLError } from 'graphql';
import { ApolloServerErrorCode } from '@apollo/server/errors';
throw new GraphQLError("some error", {
  extensions: {
    code:  ApolloServerErrorCode.GRAPHQL_VALIDATION_FAILED',
  },
);

Or if you'd like, just define your own class:

import { GraphQLError } from 'graphql';
import { ApolloServerErrorCode } from '@apollo/server/errors';
class ValidationError extends GraphQLError {
  constructor(message: string) {
    super(message, { extensions: { code: ApolloServerErrorCode.GRAPHQL_VALIDATION_FAILED } });
  }
}

We wanted to move away from the exported error class approach because it led to people trying to…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alexbjorlig
Comment options

Answer selected by alexbjorlig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants