diff --git a/.changeset/fluffy-masks-develop.md b/.changeset/fluffy-masks-develop.md new file mode 100644 index 00000000000..decdf6b3f52 --- /dev/null +++ b/.changeset/fluffy-masks-develop.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/utils': patch +--- + +Fixes introspection query issues when visiting field '\_\_type' diff --git a/packages/utils/src/visitResult.ts b/packages/utils/src/visitResult.ts index cbeb8f18dc5..d3c980857dc 100644 --- a/packages/utils/src/visitResult.ts +++ b/packages/utils/src/visitResult.ts @@ -11,6 +11,7 @@ import { isObjectType, OperationDefinitionNode, GraphQLError, + TypeMetaFieldDef, TypeNameMetaFieldDef, FragmentDefinitionNode, SchemaMetaFieldDef, @@ -240,6 +241,9 @@ function visitObjectValue( case '__schema': fieldType = SchemaMetaFieldDef.type; break; + case '__type': + fieldType = TypeMetaFieldDef.type; + break; } } diff --git a/packages/utils/tests/visitResult.test.ts b/packages/utils/tests/visitResult.test.ts index ed75de80e66..77f8267257b 100644 --- a/packages/utils/tests/visitResult.test.ts +++ b/packages/utils/tests/visitResult.test.ts @@ -58,6 +58,22 @@ describe('visiting results', () => { expect(() => visitResult(result, introspectionRequest, schema, undefined)).not.toThrow(); }); + it('should visit with type query and visitor map without throwing', async () => { + const introspectionRequest: ExecutionRequest = { + document: parse('{ __type(name: "Test") { __typename name } }'), + variables: {}, + }; + + const result = { + data: { + __type: { + __typename: '__Type', + }, + }, + }; + expect(() => visitResult(result, introspectionRequest, schema, {})).not.toThrow(); + }); + it('should visit with a request with introspection fields without throwing', async () => { const introspectionRequest: ExecutionRequest = { document: parse(getIntrospectionQuery()),