Skip to content

Commit

Permalink
type(formatErrors): accept GraphQLError, return GraphQLFormattedError
Browse files Browse the repository at this point in the history
  • Loading branch information
cheapsteak committed Feb 20, 2019
1 parent d56d1e0 commit 13c9a6a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/apollo-server-core/src/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions';
import { formatApolloErrors, ApolloError } from 'apollo-server-errors';
import { formatApolloErrors } from 'apollo-server-errors';
import { GraphQLError, GraphQLFormattedError } from 'graphql';

export class FormatErrorExtension<TContext = any> extends GraphQLExtension {
private formatError?: (error: ApolloError) => ApolloError;
private formatError?: (error: GraphQLError) => GraphQLFormattedError;
private debug: boolean;

public constructor(
formatError?: (error: ApolloError) => ApolloError,
formatError?: (error: GraphQLError) => GraphQLFormattedError,
debug: boolean = false,
) {
super();
Expand Down
5 changes: 3 additions & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import {
ValidationContext,
GraphQLFieldResolver,
DocumentNode,
GraphQLError,
GraphQLFormattedError,
} from 'graphql';
import { GraphQLExtension } from 'graphql-extensions';
import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching';
import { DataSource } from 'apollo-datasource';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import { GraphQLParseOptions } from 'graphql-tools';
import { ApolloError } from 'apollo-server-errors';

/*
* GraphQLServerOptions
Expand All @@ -32,7 +33,7 @@ export interface GraphQLServerOptions<
TRootValue = any
> {
schema: GraphQLSchema;
formatError?: (error: ApolloError) => ApolloError;
formatError?: (error: GraphQLError) => GraphQLFormattedError;
rootValue?: ((parsedQuery: DocumentNode) => TRootValue) | TRootValue;
context?: TContext | (() => never);
validationRules?: Array<(context: ValidationContext) => any>;
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-server-core/src/requestPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ExecutionArgs,
ExecutionResult,
GraphQLError,
GraphQLFormattedError,
} from 'graphql';
import * as graphql from 'graphql';
import {
Expand Down Expand Up @@ -75,7 +76,7 @@ export interface GraphQLRequestPipelineConfig<TContext> {
persistedQueries?: PersistedQueryOptions;
cacheControl?: CacheControlExtensionOptions;

formatError?: (error: ApolloError) => ApolloError;
formatError?: (error: GraphQLError) => GraphQLFormattedError;
formatResponse?: Function;

plugins?: ApolloServerPlugin[];
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-errors/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLError } from 'graphql';
import { GraphQLError, GraphQLFormattedError } from 'graphql';

export class ApolloError extends Error implements GraphQLError {
public extensions: Record<string, any>;
Expand Down Expand Up @@ -213,7 +213,7 @@ export class UserInputError extends ApolloError {
export function formatApolloErrors(
errors: Array<Error>,
options?: {
formatter?: (error: ApolloError) => ApolloError;
formatter?: (error: GraphQLError) => GraphQLFormattedError;
debug?: boolean;
},
): Array<ApolloError> {
Expand Down

0 comments on commit 13c9a6a

Please sign in to comment.