Skip to content

Commit

Permalink
fix(graphql): allow null for "data" and "errors" response property ty…
Browse files Browse the repository at this point in the history
…pes (#1867)
  • Loading branch information
kettanaito authored Nov 17, 2023
1 parent 28efd32 commit a7ffd32
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/handlers/GraphQLHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
}

export interface GraphQLResponseBody<BodyType extends DefaultBodyType> {
data?: BodyType
errors?: readonly Partial<GraphQLError>[]
data?: BodyType | null
errors?: readonly Partial<GraphQLError>[] | null
}

export function isDocumentNode(
Expand Down
18 changes: 18 additions & 0 deletions test/typings/graphql.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -102,6 +116,10 @@ graphql.operation<{ key: string }>(
},
)

graphql.operation<{ key: string }>(() => {
return HttpResponse.json({ data: null })
})

/**
* Variables type.
*/
Expand Down

0 comments on commit a7ffd32

Please sign in to comment.