Skip to content

Commit 849c9ab

Browse files
authored
feat: Make extractIsMutation work with graphql@15 (#1355)
1 parent b732f45 commit 849c9ab

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/legacy/helpers/analyzeDocument.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { RequestDocument } from './types.js'
66
* instead of the entire package (greater than 500KiB) where tree-shaking is not supported.
77
* @see https://github.com/jasonkuhrt/graphql-request/pull/543
88
*/
9-
import { type DocumentNode, OperationTypeNode } from 'graphql'
9+
import type { DocumentNode } from 'graphql'
1010
import { parse } from 'graphql'
1111
import { print } from 'graphql'
1212

@@ -32,7 +32,11 @@ const extractIsMutation = (document: DocumentNode): boolean => {
3232
const defs = document.definitions.filter(isOperationDefinitionNode)
3333

3434
if (defs.length === 1) {
35-
isMutation = defs[0]!.operation === OperationTypeNode.MUTATION
35+
/* eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison --
36+
* graphql@15's `OperationTypeNode` is a type, but graphql@16's `OperationTypeNode` is a native TypeScript enum
37+
* Therefore, we cannot use `OperationTypeNode.MUTATION` here because it wouldn't work with graphql@15
38+
**/
39+
isMutation = defs[0]!.operation === `mutation`
3640
}
3741

3842
return isMutation

0 commit comments

Comments
 (0)