Skip to content

Commit

Permalink
fix: use GraphQLError instead of ApolloError
Browse files Browse the repository at this point in the history
  • Loading branch information
desivi committed Feb 28, 2024
1 parent c5f8322 commit 268f1b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/i18n-error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApolloError } from 'apollo-server-core';
import { EvebleTypes, DEFAULTS } from '@eveble/eveble';
import { GraphQLError } from 'graphql';

/**
* All errors thrown in server must use or extend this error class. This allows the
Expand All @@ -10,14 +10,18 @@ import { EvebleTypes, DEFAULTS } from '@eveble/eveble';
*
* Note that this class should not be directly used in code, but should be extended by
* a more specific Error class.
*
* https://github.com/apollographql/apollo-server/blob/ce568b3ea6a02d304ca463db7b27b457a0841039/docs/source/migration.mdx#L947
*/
export abstract class I18nError extends ApolloError {
export abstract class I18nError extends GraphQLError {
protected constructor(
public message: string,
public variables: { [key: string]: string | number } = {},
public code?: string,
public logLevel: EvebleTypes.Priority = DEFAULTS.LOGGING_LEVELS.warning
) {
super(message, code);
super(message, {
extensions: { code, variables, logLevel },
});
}
}
6 changes: 3 additions & 3 deletions test/unit/i18n-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { ApolloError } from 'apollo-server-core';
import { DEFAULTS } from '@eveble/eveble';
import { GraphQLError } from 'graphql';
import { I18nError } from '../../src/i18n-error';

describe('I18nError', () => {
Expand All @@ -15,8 +15,8 @@ describe('I18nError', () => {
}
}

it('extends ApolloError', () => {
expect(I18nError.prototype).to.be.instanceof(ApolloError);
it('extends GraphQLError', () => {
expect(I18nError.prototype).to.be.instanceof(GraphQLError);
});

describe('construction', () => {
Expand Down

0 comments on commit 268f1b6

Please sign in to comment.