From ec4642081283feef617444e4123e5b0d36db8801 Mon Sep 17 00:00:00 2001 From: Jure Triglav Date: Wed, 5 Sep 2018 19:07:13 +0200 Subject: [PATCH 1/3] Extract input extensions in extractExtensionDefinitions --- package.json | 2 +- src/generate/extractExtensionDefinitions.ts | 4 +++- src/test/testSchemaGenerator.ts | 25 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2c0fdc50d14..4b0e4f8ef6c 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "chai": "^4.1.2", "dateformat": "^3.0.3", "express": "^4.16.2", - "graphql": "^0.13.0", + "graphql": "^14.0.0", "graphql-subscriptions": "^0.5.7", "graphql-type-json": "^0.1.4", "istanbul": "^0.4.5", diff --git a/src/generate/extractExtensionDefinitions.ts b/src/generate/extractExtensionDefinitions.ts index 05fb394411c..54d8dd671e6 100644 --- a/src/generate/extractExtensionDefinitions.ts +++ b/src/generate/extractExtensionDefinitions.ts @@ -2,12 +2,14 @@ import { DocumentNode, DefinitionNode } from 'graphql'; const newExtensionDefinitionKind = 'ObjectTypeExtension'; const interfaceExtensionDefinitionKind = 'InterfaceTypeExtension'; +const inputObjectExtensionDefinitionKind = 'InputObjectTypeExtension'; export default function extractExtensionDefinitions(ast: DocumentNode) { const extensionDefs = ast.definitions.filter( (def: DefinitionNode) => (def.kind as any) === newExtensionDefinitionKind || - (def.kind as any) === interfaceExtensionDefinitionKind, + (def.kind as any) === interfaceExtensionDefinitionKind || + (def.kind as any) === inputObjectExtensionDefinitionKind, ); return Object.assign({}, ast, { diff --git a/src/test/testSchemaGenerator.ts b/src/test/testSchemaGenerator.ts index 3d0e3cfd7d0..7393d3c5638 100644 --- a/src/test/testSchemaGenerator.ts +++ b/src/test/testSchemaGenerator.ts @@ -12,6 +12,7 @@ import { ExecutionResult, GraphQLError, GraphQLEnumType, + GraphQLInputObjectType, } from 'graphql'; // import { printSchema } from 'graphql'; const GraphQLJSON = require('graphql-type-json'); @@ -2777,3 +2778,27 @@ describe('unions', () => { }); }); }); + +describe('extending inputs', () => { + it.only('can extend input', () => { + const typeDefAry = [ + ` + input Input { + foo: String + }`, + ` + extend input Input { + bar: String + } + `, + ]; + + const jsSchema = makeExecutableSchema({ + typeDefs: typeDefAry, + resolvers: {}, + }); + + expect(jsSchema.getType('Input')).to.be.an.instanceof(GraphQLInputObjectType); + expect(jsSchema.getType('Input')._fields).to.have.all.keys('foo', 'bar'); + }); +}); From 3ddf52b3abdd640a83f88b6240dffbf503a4a066 Mon Sep 17 00:00:00 2001 From: Jure Triglav Date: Thu, 6 Sep 2018 11:21:25 +0200 Subject: [PATCH 2/3] Test input extension extraction more minimally --- package.json | 2 +- src/test/testExtensionExtraction.ts | 25 +++++++++++++++++++++++++ src/test/testSchemaGenerator.ts | 25 ------------------------- src/test/tests.ts | 1 + 4 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 src/test/testExtensionExtraction.ts diff --git a/package.json b/package.json index 4b0e4f8ef6c..2c0fdc50d14 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "chai": "^4.1.2", "dateformat": "^3.0.3", "express": "^4.16.2", - "graphql": "^14.0.0", + "graphql": "^0.13.0", "graphql-subscriptions": "^0.5.7", "graphql-type-json": "^0.1.4", "istanbul": "^0.4.5", diff --git a/src/test/testExtensionExtraction.ts b/src/test/testExtensionExtraction.ts new file mode 100644 index 00000000000..a5ab306c458 --- /dev/null +++ b/src/test/testExtensionExtraction.ts @@ -0,0 +1,25 @@ +import { expect } from 'chai'; +import { parse } from 'graphql'; +import extractExtensionDefinitons from '../generate/extractExtensionDefinitions'; +import 'mocha'; + +describe('Extension extraction', () => { + it('extracts extended inputs', () => { + const typeDefs = ` + input Input { + foo: String + } + + extend input Input { + bar: String + } + `; + + const astDocument = parse(typeDefs); + const extensionAst = extractExtensionDefinitons(astDocument); + + expect(extensionAst.definitions).to.have.length(1); + expect(extensionAst.definitions[0].kind).to.equal('InputObjectTypeExtension'); + }); +}); + diff --git a/src/test/testSchemaGenerator.ts b/src/test/testSchemaGenerator.ts index 7393d3c5638..3d0e3cfd7d0 100644 --- a/src/test/testSchemaGenerator.ts +++ b/src/test/testSchemaGenerator.ts @@ -12,7 +12,6 @@ import { ExecutionResult, GraphQLError, GraphQLEnumType, - GraphQLInputObjectType, } from 'graphql'; // import { printSchema } from 'graphql'; const GraphQLJSON = require('graphql-type-json'); @@ -2778,27 +2777,3 @@ describe('unions', () => { }); }); }); - -describe('extending inputs', () => { - it.only('can extend input', () => { - const typeDefAry = [ - ` - input Input { - foo: String - }`, - ` - extend input Input { - bar: String - } - `, - ]; - - const jsSchema = makeExecutableSchema({ - typeDefs: typeDefAry, - resolvers: {}, - }); - - expect(jsSchema.getType('Input')).to.be.an.instanceof(GraphQLInputObjectType); - expect(jsSchema.getType('Input')._fields).to.have.all.keys('foo', 'bar'); - }); -}); diff --git a/src/test/tests.ts b/src/test/tests.ts index edc4fabca67..7da887e0719 100755 --- a/src/test/tests.ts +++ b/src/test/tests.ts @@ -12,3 +12,4 @@ import './testMocking'; import './testResolution'; import './testSchemaGenerator'; import './testTransforms'; +import './testExtensionExtraction'; From d1d22ed1c1e77c19d7e7fe51251bab77c3004a82 Mon Sep 17 00:00:00 2001 From: Jure Triglav Date: Thu, 6 Sep 2018 14:46:39 +0200 Subject: [PATCH 3/3] Add CHANGELOG entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8825b8985ca..c226590297d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### vNEXT -* ... +* Extracts input extensions [PR #948](https://github.com/apollographql/graphql-tools/pull/948) ### v3.1.1