Skip to content

Commit 62d074b

Browse files
Fix error when visiting __type fields (#5016)
* Add test case * Fix error when visiting __type fields * Add changeset
1 parent a94217e commit 62d074b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.changeset/fluffy-masks-develop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
Fixes introspection query issues when visiting field '\_\_type'

packages/utils/src/visitResult.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isObjectType,
1212
OperationDefinitionNode,
1313
GraphQLError,
14+
TypeMetaFieldDef,
1415
TypeNameMetaFieldDef,
1516
FragmentDefinitionNode,
1617
SchemaMetaFieldDef,
@@ -240,6 +241,9 @@ function visitObjectValue(
240241
case '__schema':
241242
fieldType = SchemaMetaFieldDef.type;
242243
break;
244+
case '__type':
245+
fieldType = TypeMetaFieldDef.type;
246+
break;
243247
}
244248
}
245249

packages/utils/tests/visitResult.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ describe('visiting results', () => {
5858
expect(() => visitResult(result, introspectionRequest, schema, undefined)).not.toThrow();
5959
});
6060

61+
it('should visit with type query and visitor map without throwing', async () => {
62+
const introspectionRequest: ExecutionRequest = {
63+
document: parse('{ __type(name: "Test") { __typename name } }'),
64+
variables: {},
65+
};
66+
67+
const result = {
68+
data: {
69+
__type: {
70+
__typename: '__Type',
71+
},
72+
},
73+
};
74+
expect(() => visitResult(result, introspectionRequest, schema, {})).not.toThrow();
75+
});
76+
6177
it('should visit with a request with introspection fields without throwing', async () => {
6278
const introspectionRequest: ExecutionRequest = {
6379
document: parse(getIntrospectionQuery()),

0 commit comments

Comments
 (0)