Skip to content

Commit

Permalink
Fix GraphQL v17 incompatibility issue #4468
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed May 20, 2022
1 parent 2b43f3b commit c0762ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-jars-fetch.md
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

Incoming GraphQL v17 compatibility #4468
14 changes: 12 additions & 2 deletions packages/utils/src/visitResult.ts
@@ -1,7 +1,6 @@
import { getOperationASTFromRequest } from './getOperationASTFromRequest';
import {
GraphQLSchema,
getOperationRootType,
Kind,
GraphQLObjectType,
FieldNode,
Expand Down Expand Up @@ -157,6 +156,17 @@ function visitErrorsByType(
});
}

function getOperationRootType(schema: GraphQLSchema, operationDef: OperationDefinitionNode) {
switch (operationDef.operation) {
case 'query':
return schema.getQueryType();
case 'mutation':
return schema.getMutationType();
case 'subscription':
return schema.getSubscriptionType();
}
}

function visitRoot(
root: any,
operation: OperationDefinitionNode,
Expand All @@ -167,7 +177,7 @@ function visitRoot(
errors: Maybe<ReadonlyArray<GraphQLError>>,
errorInfo: ErrorInfo
): any {
const operationRootType = getOperationRootType(schema, operation);
const operationRootType = getOperationRootType(schema, operation)!;
const collectedFields = collectFields(
schema,
fragments,
Expand Down

0 comments on commit c0762ee

Please sign in to comment.