Skip to content

Commit

Permalink
Update operation helpers to use raw strings instead of OperationTypeN…
Browse files Browse the repository at this point in the history
…ode (#11071)
  • Loading branch information
jerelmiller committed Jul 17, 2023
1 parent 213bde2 commit 4473e92
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-needles-remember.md
@@ -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.
12 changes: 7 additions & 5 deletions src/utilities/graphql/operations.ts
@@ -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');
}

0 comments on commit 4473e92

Please sign in to comment.