Skip to content

Commit

Permalink
Extract input extensions in extractExtensionDefinitions (#948)
Browse files Browse the repository at this point in the history
* Extract input extensions in extractExtensionDefinitions

* Test input extension extraction more minimally

* Add CHANGELOG entry
  • Loading branch information
jure authored and hwillson committed Sep 7, 2018
1 parent 3bf761c commit 4bdc1fb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[@nagelflorian](https://github.com/nagelflorian) in [#936](https://github.com/apollographql/graphql-tools/pull/936)
* Update `IFieldResolver` to allow typed input args. <br/>
[@luk3thomas](https://github.com/luk3thomas) in [#932](https://github.com/apollographql/graphql-tools/pull/932)
* Changes to `extractExtensionDefinitions` to properly support `graphql-js` input extensions. <br/>
[@jure](https://github.com/jure) in [#948](https://github.com/apollographql/graphql-tools/pull/948)
* Documentation updates. <br/>
[@Amorites](https://github.com/Amorites) in [#944](https://github.com/apollographql/graphql-tools/pull/944) <br/>
[@trevor-scheer](https://github.com/trevor-scheer) in [#946](https://github.com/apollographql/graphql-tools/pull/946) <br/>
Expand Down
4 changes: 3 additions & 1 deletion src/generate/extractExtensionDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
25 changes: 25 additions & 0 deletions src/test/testExtensionExtraction.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});

1 change: 1 addition & 0 deletions src/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ import './testMocking';
import './testResolution';
import './testSchemaGenerator';
import './testTransforms';
import './testExtensionExtraction';

0 comments on commit 4bdc1fb

Please sign in to comment.