Skip to content

Commit 594e8ca

Browse files
fix: support nullable GraphQL queries (#2403)
Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
1 parent cf67095 commit 594e8ca

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/core/handlers/GraphQLHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getAllRequestCookies } from '../utils/request/getRequestCookies'
2424
export type ExpectedOperationTypeNode = OperationTypeNode | 'all'
2525
export type GraphQLHandlerNameSelector = DocumentNode | RegExp | string
2626

27-
export type GraphQLQuery = Record<string, any>
27+
export type GraphQLQuery = Record<string, any> | null
2828
export type GraphQLVariables = Record<string, any>
2929

3030
export interface GraphQLHandlerInfo extends RequestHandlerDefaultInfo {

test/typings/graphql.test-d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ it('graphql query allows explicit null as the response body type for the query',
7575
})
7676
})
7777

78+
it('supports nullable queries', () => {
79+
graphql.query<{ id: string } | null>('GetUser', () => {
80+
return HttpResponse.json({
81+
data: null,
82+
})
83+
})
84+
})
85+
86+
it('supports nullable mutations', () => {
87+
graphql.mutation<{ id: string } | null>('GetUser', () => {
88+
return HttpResponse.json({
89+
data: null,
90+
})
91+
})
92+
})
93+
7894
it('graphql query does not accept invalid data type for the response body type for the query', () => {
7995
graphql.query<{ id: string }>('GetUser', () => {
8096
return HttpResponse.json({

0 commit comments

Comments
 (0)