Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update operation helpers to use raw strings instead of OperationTypeN…
…ode (#11071)
- Loading branch information
1 parent
213bde2
commit 4473e92
Showing
2 changed files
with
12 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/client': patch | ||
--- | ||
|
||
[#10509](https://github.com/apollographql/apollo-client/pull/10509) introduced some helpers for determining the type of operation for a GraphQL query. This imported the `OperationTypeNode` from graphql-js which is not available in GraphQL 14. To maintain compatibility with graphql-js v14, this has been reverted to use plain strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import { OperationTypeNode } from 'graphql'; | ||
import type { DocumentNode } from '../../core/index.js'; | ||
import { getOperationDefinition } from './getFromAST.js'; | ||
|
||
function isOperation(document: DocumentNode, operation: OperationTypeNode) { | ||
function isOperation( | ||
document: DocumentNode, | ||
operation: 'query' | 'mutation' | 'subscription' | ||
) { | ||
return getOperationDefinition(document)?.operation === operation; | ||
} | ||
|
||
export function isMutationOperation(document: DocumentNode) { | ||
return isOperation(document, OperationTypeNode.MUTATION); | ||
return isOperation(document, 'mutation'); | ||
} | ||
|
||
export function isQueryOperation(document: DocumentNode) { | ||
return isOperation(document, OperationTypeNode.QUERY); | ||
return isOperation(document, 'query'); | ||
} | ||
|
||
export function isSubscriptionOperation(document: DocumentNode) { | ||
return isOperation(document, OperationTypeNode.SUBSCRIPTION); | ||
return isOperation(document, 'subscription'); | ||
} |