Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specify type better for context arg in defaultErrorFormatter #690

Merged
merged 2 commits into from Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -470,7 +470,7 @@ export interface MercuriusCommonOptions {
/**
* Change the default error formatter.
*/
errorFormatter?: <TContext extends Record<string,any> = MercuriusContext>(
errorFormatter?: <TContext extends MercuriusContext = MercuriusContext>(
execution: ExecutionResult,
context: TContext
) => {
Expand Down Expand Up @@ -614,7 +614,7 @@ declare namespace mercurius {
*/
const defaultErrorFormatter: (
execution: ExecutionResult,
context: any
context: MercuriusContext
) => { statusCode: number; response: ExecutionResult };

/**
Expand Down
10 changes: 10 additions & 0 deletions test/types/index.ts
Expand Up @@ -629,3 +629,13 @@ declare module 'fastify' {
graphql: MercuriusPlugin
}
}

mercurius.defaultErrorFormatter({}, {} as MercuriusContext)

expectError(() => {
return mercurius.defaultErrorFormatter({}, null)
})

expectError(() => {
return mercurius.defaultErrorFormatter({}, undefined)
})