Skip to content

Commit

Permalink
Fix error when visiting __type fields (#5016)
Browse files Browse the repository at this point in the history
* Add test case

* Fix error when visiting __type fields

* Add changeset
  • Loading branch information
mayrn-techdivision authored Feb 1, 2023
1 parent a94217e commit 62d074b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-masks-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

Fixes introspection query issues when visiting field '\_\_type'
4 changes: 4 additions & 0 deletions packages/utils/src/visitResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isObjectType,
OperationDefinitionNode,
GraphQLError,
TypeMetaFieldDef,
TypeNameMetaFieldDef,
FragmentDefinitionNode,
SchemaMetaFieldDef,
Expand Down Expand Up @@ -240,6 +241,9 @@ function visitObjectValue(
case '__schema':
fieldType = SchemaMetaFieldDef.type;
break;
case '__type':
fieldType = TypeMetaFieldDef.type;
break;
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/utils/tests/visitResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 62d074b

Please sign in to comment.