Skip to content

Commit

Permalink
Don't call global fieldResolver on introspection fields (#1329)
Browse files Browse the repository at this point in the history
Fixes #1015
  • Loading branch information
IvanGoncharov authored and leebyron committed Apr 30, 2018
1 parent 4c6e0a9 commit 2eccaad
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/type/__tests__/introspection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,4 +1446,26 @@ describe('Introspection', () => {
},
});
});

it('executes an introspection query without calling global fieldResolver', () => {
const QueryRoot = new GraphQLObjectType({
name: 'QueryRoot',
fields: {
onlyField: { type: GraphQLString },
},
});

const schema = new GraphQLSchema({ query: QueryRoot });
const source = getIntrospectionQuery();

const calledForFields = {};
/* istanbul ignore next */
function fieldResolver(value, _1, _2, info) {
calledForFields[`${info.parentType.name}::${info.fieldName}`] = true;
return value;
}

graphqlSync({ schema, source, fieldResolver });
expect(calledForFields).to.deep.equal({});
});
});
78 changes: 63 additions & 15 deletions src/type/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,17 @@ export const __Directive = new GraphQLObjectType({
'conditionally including or skipping a field. Directives provide this by ' +
'describing additional information to the executor.',
fields: () => ({
name: { type: GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString },
name: {
type: GraphQLNonNull(GraphQLString),
resolve: obj => obj.name,
},
description: {
type: GraphQLString,
resolve: obj => obj.description,
},
locations: {
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__DirectiveLocation))),
resolve: obj => obj.locations,
},
args: {
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
Expand Down Expand Up @@ -237,8 +244,14 @@ export const __Type = new GraphQLObjectType({
throw new Error('Unknown kind of type: ' + type);
},
},
name: { type: GraphQLString },
description: { type: GraphQLString },
name: {
type: GraphQLString,
resolve: obj => obj.name,
},
description: {
type: GraphQLString,
resolve: obj => obj.description,
},
fields: {
type: GraphQLList(GraphQLNonNull(__Field)),
args: {
Expand Down Expand Up @@ -294,7 +307,10 @@ export const __Type = new GraphQLObjectType({
}
},
},
ofType: { type: __Type },
ofType: {
type: __Type,
resolve: obj => obj.ofType,
},
}),
});

Expand All @@ -305,16 +321,29 @@ export const __Field = new GraphQLObjectType({
'Object and Interface types are described by a list of Fields, each of ' +
'which has a name, potentially a list of arguments, and a return type.',
fields: () => ({
name: { type: GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString },
name: {
type: GraphQLNonNull(GraphQLString),
resolve: obj => obj.name,
},
description: {
type: GraphQLString,
resolve: obj => obj.description,
},
args: {
type: GraphQLNonNull(GraphQLList(GraphQLNonNull(__InputValue))),
resolve: field => field.args || [],
},
type: { type: GraphQLNonNull(__Type) },
isDeprecated: { type: GraphQLNonNull(GraphQLBoolean) },
type: {
type: GraphQLNonNull(__Type),
resolve: obj => obj.type,
},
isDeprecated: {
type: GraphQLNonNull(GraphQLBoolean),
resolve: obj => obj.isDeprecated,
},
deprecationReason: {
type: GraphQLString,
resolve: obj => obj.deprecationReason,
},
}),
});
Expand All @@ -327,9 +356,18 @@ export const __InputValue = new GraphQLObjectType({
'InputObject are represented as Input Values which describe their type ' +
'and optionally a default value.',
fields: () => ({
name: { type: GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString },
type: { type: GraphQLNonNull(__Type) },
name: {
type: GraphQLNonNull(GraphQLString),
resolve: obj => obj.name,
},
description: {
type: GraphQLString,
resolve: obj => obj.description,
},
type: {
type: GraphQLNonNull(__Type),
resolve: obj => obj.type,
},
defaultValue: {
type: GraphQLString,
description:
Expand All @@ -351,11 +389,21 @@ export const __EnumValue = new GraphQLObjectType({
'a placeholder for a string or numeric value. However an Enum value is ' +
'returned in a JSON response as a string.',
fields: () => ({
name: { type: GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString },
isDeprecated: { type: GraphQLNonNull(GraphQLBoolean) },
name: {
type: GraphQLNonNull(GraphQLString),
resolve: obj => obj.name,
},
description: {
type: GraphQLString,
resolve: obj => obj.description,
},
isDeprecated: {
type: GraphQLNonNull(GraphQLBoolean),
resolve: obj => obj.isDeprecated,
},
deprecationReason: {
type: GraphQLString,
resolve: obj => obj.deprecationReason,
},
}),
});
Expand Down

0 comments on commit 2eccaad

Please sign in to comment.