From 1753f9894b1370e9afc1a046812938dee3629971 Mon Sep 17 00:00:00 2001 From: Albert Still Date: Thu, 9 Jul 2015 11:06:17 +0100 Subject: [PATCH] Add missing `description` to field args --- src/__tests__/starWarsIntrospectionTests.js | 77 +++++++++++++++++++++ src/__tests__/starWarsSchema.js | 14 +++- src/type/definition.js | 1 + 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/__tests__/starWarsIntrospectionTests.js b/src/__tests__/starWarsIntrospectionTests.js index fc51362a2e..0d49ac7b0b 100644 --- a/src/__tests__/starWarsIntrospectionTests.js +++ b/src/__tests__/starWarsIntrospectionTests.js @@ -298,6 +298,83 @@ describe('Star Wars Introspection Tests', () => { return testQuery(query, expected); }); + it('Allows querying the schema for field args', () => { + var query = ` + query IntrospectionQueryTypeQuery { + __schema { + queryType { + fields { + name + args { + name + description + type { + name + kind + ofType { + name + kind + } + } + defaultValue + } + } + } + } + } + `; + var expected = { + __schema: { + queryType: { + fields: [ + { + name: 'hero', + args: [] + }, + { + name: 'human', + args: [ + { + name: 'id', + description: 'id of the human', + type: { + kind: 'NON_NULL', + name: null, + ofType: { + kind: 'SCALAR', + name: 'String' + } + }, + defaultValue: null + } + ] + }, + { + name: 'droid', + args: [ + { + name: 'id', + description: 'id of the droid', + type: { + kind: 'NON_NULL', + name: null, + ofType: { + kind: 'SCALAR', + name: 'String' + } + }, + defaultValue: null + } + ] + } + ] + } + } + }; + + return testQuery(query, expected); + }); + it('Allows querying the schema for documentation', () => { var query = ` query IntrospectionDroidDescriptionQuery { diff --git a/src/__tests__/starWarsSchema.js b/src/__tests__/starWarsSchema.js index cff4cab45f..2839747bfa 100644 --- a/src/__tests__/starWarsSchema.js +++ b/src/__tests__/starWarsSchema.js @@ -243,12 +243,22 @@ var queryType = new GraphQLObjectType({ }, human: { type: humanType, - args: {id: { name: 'id', type: new GraphQLNonNull(GraphQLString)}}, + args: { + id: { + description: 'id of the human', + type: new GraphQLNonNull(GraphQLString) + } + }, resolve: (root, {id}) => starWarsData.Humans[id], }, droid: { type: droidType, - args: {id: { name: 'id', type: new GraphQLNonNull(GraphQLString)}}, + args: { + id: { + description: 'id of the droid', + type: new GraphQLNonNull(GraphQLString) + } + }, resolve: (root, {id}) => starWarsData.Droids[id], }, }) diff --git a/src/type/definition.js b/src/type/definition.js index 874b146ff0..cf8933f69c 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -300,6 +300,7 @@ function defineFieldMap( ); return { name: argName, + description: arg.description === undefined ? null : arg.description, type: arg.type, defaultValue: arg.defaultValue === undefined ? null : arg.defaultValue };