Skip to content

Don't call global fieldResolver on introspection fields #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/type/__tests__/introspection-test.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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))),
@@ -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: {
@@ -294,7 +307,10 @@ export const __Type = new GraphQLObjectType({
}
},
},
ofType: { type: __Type },
ofType: {
type: __Type,
resolve: obj => obj.ofType,
},
}),
});

@@ -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,
},
}),
});
@@ -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:
@@ -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,
},
}),
});