diff --git a/src/core/handlers/GraphQLHandler.ts b/src/core/handlers/GraphQLHandler.ts index 577d8d08d..cd92393fd 100644 --- a/src/core/handlers/GraphQLHandler.ts +++ b/src/core/handlers/GraphQLHandler.ts @@ -50,8 +50,8 @@ export interface GraphQLJsonRequestBody { } export interface GraphQLResponseBody { - data?: BodyType - errors?: readonly Partial[] + data?: BodyType | null + errors?: readonly Partial[] | null } export function isDocumentNode( diff --git a/test/typings/graphql.test-d.ts b/test/typings/graphql.test-d.ts index 488b4e467..3f7a4b4c0 100644 --- a/test/typings/graphql.test-d.ts +++ b/test/typings/graphql.test-d.ts @@ -53,6 +53,13 @@ graphql.query<{ id: string }>('GetUser', () => { }) }) +graphql.query<{ id: string }>('GetUser', () => { + return HttpResponse.json({ + // Explicit null must be allowed. + data: null, + }) +}) + graphql.query<{ id: string }>( 'GetUser', // @ts-expect-error "id" type is incorrect @@ -87,6 +94,13 @@ graphql.query<{ key: string }>( }, ) +graphql.mutation<{ key: string }>('MutateData', () => { + return HttpResponse.json({ + // Explicit null in mutations must also be allowed. + data: null, + }) +}) + graphql.mutation<{ key: string }>( 'MutateData', // @ts-expect-error Response data doesn't match the query type. @@ -102,6 +116,10 @@ graphql.operation<{ key: string }>( }, ) +graphql.operation<{ key: string }>(() => { + return HttpResponse.json({ data: null }) +}) + /** * Variables type. */