From 15f2f5baf231c6cc898b9e037b7771d19ea494c7 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Sat, 15 Aug 2020 11:34:15 -0500 Subject: [PATCH] Fix errorFormatter's TypeScript typing. (#255) * Fix errorFormatter's TypeScript typing. * It looks like statusCode should be required too. * Add errorFormatter to the types test. --- index.d.ts | 10 ++++------ test/types/index.ts | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9f518826..fcd0aca4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -160,13 +160,11 @@ export interface FastifyGQLCommonOptions { * Change the default error formatter. */ errorFormatter?: (( - error: FastifyError | GraphQLError | Error + execution: ExecutionResult, + context: any, ) => { - statusCode?: number - response?: { - data?: object - errors: any[] - } + statusCode: number, + response: ExecutionResult, }); /** * The maximum depth allowed for a single query. diff --git a/test/types/index.ts b/test/types/index.ts index de3038da..602a7b42 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -54,6 +54,11 @@ app.register(fastifyGQL, { prefix: '/prefix', defineMutation: false, errorHandler: true, + errorFormatter: (result, context) => { + result.data + result.errors?.forEach(e => e.message) + return { statusCode: 200, response: result } + }, queryDepth: 8, cache: true })