diff --git a/.changeset/hungry-jars-fetch.md b/.changeset/hungry-jars-fetch.md new file mode 100644 index 00000000000..1b489478b1e --- /dev/null +++ b/.changeset/hungry-jars-fetch.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/utils': patch +--- + +Incoming GraphQL v17 compatibility #4468 diff --git a/packages/utils/src/visitResult.ts b/packages/utils/src/visitResult.ts index 567b3cbba16..37b64d347a6 100644 --- a/packages/utils/src/visitResult.ts +++ b/packages/utils/src/visitResult.ts @@ -1,7 +1,6 @@ import { getOperationASTFromRequest } from './getOperationASTFromRequest'; import { GraphQLSchema, - getOperationRootType, Kind, GraphQLObjectType, FieldNode, @@ -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, @@ -167,7 +177,7 @@ function visitRoot( errors: Maybe>, errorInfo: ErrorInfo ): any { - const operationRootType = getOperationRootType(schema, operation); + const operationRootType = getOperationRootType(schema, operation)!; const collectedFields = collectFields( schema, fragments,