From 4473e925ac5d6a53dc2b34867f034eda1b05aa00 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 17 Jul 2023 09:35:05 -0600 Subject: [PATCH] Update operation helpers to use raw strings instead of OperationTypeNode (#11071) --- .changeset/seven-needles-remember.md | 5 +++++ src/utilities/graphql/operations.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 .changeset/seven-needles-remember.md diff --git a/.changeset/seven-needles-remember.md b/.changeset/seven-needles-remember.md new file mode 100644 index 00000000000..7b738e2c5f1 --- /dev/null +++ b/.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. diff --git a/src/utilities/graphql/operations.ts b/src/utilities/graphql/operations.ts index ef390e8f631..680991d0e6a 100644 --- a/src/utilities/graphql/operations.ts +++ b/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'); }