Skip to content

Commit

Permalink
Fix errorFormatter's TypeScript typing. (#255)
Browse files Browse the repository at this point in the history
* Fix errorFormatter's TypeScript typing.

* It looks like statusCode should be required too.

* Add errorFormatter to the types test.
  • Loading branch information
stephenh authored Aug 15, 2020
1 parent 0c1f6ef commit 15f2f5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 4 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit 15f2f5b

Please sign in to comment.