Skip to content

Commit 87f6828

Browse files
committed
Don't call global fieldResolver on introspection fields
Fixes #1015
1 parent ae5b163 commit 87f6828

File tree

2 files changed

+85
-15
lines changed

2 files changed

+85
-15
lines changed

src/type/__tests__/introspection-test.js

+22
Original file line numberDiff line numberDiff line change
@@ -1446,4 +1446,26 @@ describe('Introspection', () => {
14461446
},
14471447
});
14481448
});
1449+
1450+
it('executes an introspection query without calling global fieldResolver', () => {
1451+
const QueryRoot = new GraphQLObjectType({
1452+
name: 'QueryRoot',
1453+
fields: {
1454+
onlyField: { type: GraphQLString },
1455+
},
1456+
});
1457+
1458+
const schema = new GraphQLSchema({ query: QueryRoot });
1459+
const source = getIntrospectionQuery();
1460+
1461+
const calledForFields = {};
1462+
/* istanbul ignore next */
1463+
function fieldResolver(value, _1, _2, info) {
1464+
calledForFields[`${info.parentType.name}::${info.fieldName}`] = true;
1465+
return value;
1466+
}
1467+
1468+
graphqlSync({ schema, source, fieldResolver });
1469+
expect(calledForFields).to.deep.equal({});
1470+
});
14491471
});

src/type/introspection.js

+63-15
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,17 @@ export const __Directive = new GraphQLObjectType({
8484
'conditionally including or skipping a field. Directives provide this by ' +
8585
'describing additional information to the executor.',
8686
fields: () => ({
87-
name: { type: GraphQLNonNull(GraphQLString) },
88-
description: { type: GraphQLString },
87+
name: {
88+
type: GraphQLNonNull(GraphQLString),
89+
resolve: obj => obj.name,
90+
},
91+
description: {
92+
type: GraphQLString,
93+
resolve: obj => obj.description,
94+
},
8995
locations: {
9096
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__DirectiveLocation))),
97+
resolve: obj => obj.locations,
9198
},
9299
args: {
93100
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
@@ -237,8 +244,14 @@ export const __Type = new GraphQLObjectType({
237244
throw new Error('Unknown kind of type: ' + type);
238245
},
239246
},
240-
name: { type: GraphQLString },
241-
description: { type: GraphQLString },
247+
name: {
248+
type: GraphQLString,
249+
resolve: obj => obj.name,
250+
},
251+
description: {
252+
type: GraphQLString,
253+
resolve: obj => obj.description,
254+
},
242255
fields: {
243256
type: GraphQLList(GraphQLNonNull(__Field)),
244257
args: {
@@ -294,7 +307,10 @@ export const __Type = new GraphQLObjectType({
294307
}
295308
},
296309
},
297-
ofType: { type: __Type },
310+
ofType: {
311+
type: __Type,
312+
resolve: obj => obj.ofType,
313+
},
298314
}),
299315
});
300316

@@ -305,16 +321,29 @@ export const __Field = new GraphQLObjectType({
305321
'Object and Interface types are described by a list of Fields, each of ' +
306322
'which has a name, potentially a list of arguments, and a return type.',
307323
fields: () => ({
308-
name: { type: GraphQLNonNull(GraphQLString) },
309-
description: { type: GraphQLString },
324+
name: {
325+
type: GraphQLNonNull(GraphQLString),
326+
resolve: obj => obj.name,
327+
},
328+
description: {
329+
type: GraphQLString,
330+
resolve: obj => obj.description,
331+
},
310332
args: {
311333
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
312334
resolve: field => field.args || [],
313335
},
314-
type: { type: GraphQLNonNull(__Type) },
315-
isDeprecated: { type: GraphQLNonNull(GraphQLBoolean) },
336+
type: {
337+
type: GraphQLNonNull(__Type),
338+
resolve: obj => obj.type,
339+
},
340+
isDeprecated: {
341+
type: GraphQLNonNull(GraphQLBoolean),
342+
resolve: obj => obj.isDeprecated,
343+
},
316344
deprecationReason: {
317345
type: GraphQLString,
346+
resolve: obj => obj.deprecationReason,
318347
},
319348
}),
320349
});
@@ -327,9 +356,18 @@ export const __InputValue = new GraphQLObjectType({
327356
'InputObject are represented as Input Values which describe their type ' +
328357
'and optionally a default value.',
329358
fields: () => ({
330-
name: { type: GraphQLNonNull(GraphQLString) },
331-
description: { type: GraphQLString },
332-
type: { type: GraphQLNonNull(__Type) },
359+
name: {
360+
type: GraphQLNonNull(GraphQLString),
361+
resolve: obj => obj.name,
362+
},
363+
description: {
364+
type: GraphQLString,
365+
resolve: obj => obj.description,
366+
},
367+
type: {
368+
type: GraphQLNonNull(__Type),
369+
resolve: obj => obj.type,
370+
},
333371
defaultValue: {
334372
type: GraphQLString,
335373
description:
@@ -351,11 +389,21 @@ export const __EnumValue = new GraphQLObjectType({
351389
'a placeholder for a string or numeric value. However an Enum value is ' +
352390
'returned in a JSON response as a string.',
353391
fields: () => ({
354-
name: { type: GraphQLNonNull(GraphQLString) },
355-
description: { type: GraphQLString },
356-
isDeprecated: { type: GraphQLNonNull(GraphQLBoolean) },
392+
name: {
393+
type: GraphQLNonNull(GraphQLString),
394+
resolve: obj => obj.name,
395+
},
396+
description: {
397+
type: GraphQLString,
398+
resolve: obj => obj.description,
399+
},
400+
isDeprecated: {
401+
type: GraphQLNonNull(GraphQLBoolean),
402+
resolve: obj => obj.isDeprecated,
403+
},
357404
deprecationReason: {
358405
type: GraphQLString,
406+
resolve: obj => obj.deprecationReason,
359407
},
360408
}),
361409
});

0 commit comments

Comments
 (0)