From 0b72e7038761bec9fb5319cc08ea93ff8b071a9c Mon Sep 17 00:00:00 2001 From: Mike Solomon Date: Mon, 25 Apr 2016 11:37:25 -0700 Subject: [PATCH] Deepen introspection query (#364) --- .../__tests__/buildClientSchema-test.js | 39 +++++++++++++++---- src/utilities/introspectionQuery.js | 16 ++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/utilities/__tests__/buildClientSchema-test.js b/src/utilities/__tests__/buildClientSchema-test.js index b9ede38c61..7f711cdfc5 100644 --- a/src/utilities/__tests__/buildClientSchema-test.js +++ b/src/utilities/__tests__/buildClientSchema-test.js @@ -63,7 +63,7 @@ describe('Type System: build schema from introspection', () => { await testSchema(schema); }); - it('builds a simple schema with both operation types', async () => { + it('builds a simple schema with all operation types', async () => { const queryType = new GraphQLObjectType({ name: 'QueryType', description: 'This is a simple query type', @@ -726,17 +726,18 @@ describe('Type System: build schema from introspection', () => { }); - describe('KP: very deep decorators are not supported', () => { + describe('very deep decorators are not supported', () => { - it('fails on very deep lists', async () => { + it('fails on very deep (> 7 levels) lists', async () => { const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { foo: { type: new GraphQLList(new GraphQLList(new GraphQLList( - new GraphQLList(GraphQLString) - ))) + new GraphQLList(new GraphQLList(new GraphQLList( + new GraphQLList(new GraphQLNonNull(GraphQLString)) + )))))) } } }) @@ -748,15 +749,16 @@ describe('Type System: build schema from introspection', () => { ).to.throw('Decorated type deeper than introspection query.'); }); - it('fails on a deep non-null', async () => { + it('fails on a very deep (> 7 levels) non-null', async () => { const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', fields: { foo: { type: new GraphQLList(new GraphQLList(new GraphQLList( - new GraphQLNonNull(GraphQLString) - ))) + new GraphQLList(new GraphQLList(new GraphQLList( + new GraphQLList(new GraphQLNonNull(GraphQLString)) + )))))) } } }) @@ -768,6 +770,27 @@ describe('Type System: build schema from introspection', () => { ).to.throw('Decorated type deeper than introspection query.'); }); + it('succeeds on deep (<= 7 levels) types', async () => { + const schema = new GraphQLSchema({ + query: new GraphQLObjectType({ + name: 'Query', + fields: { + foo: { + // e.g., fully non-null 3D matrix + type: new GraphQLNonNull(new GraphQLList( + new GraphQLNonNull(new GraphQLList( + new GraphQLNonNull(new GraphQLList( + new GraphQLNonNull(GraphQLString) + )))))) + } + } + }) + }); + + const introspection = await graphql(schema, introspectionQuery); + buildClientSchema(introspection.data); + }); + }); }); diff --git a/src/utilities/introspectionQuery.js b/src/utilities/introspectionQuery.js index 73d548f1b7..63fa8fcdc8 100644 --- a/src/utilities/introspectionQuery.js +++ b/src/utilities/introspectionQuery.js @@ -83,6 +83,22 @@ export const introspectionQuery = ` ofType { kind name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + ofType { + kind + name + } + } + } + } } } }