diff --git a/src/type/definition.js b/src/type/definition.js index 05028bbbaf..2d668a26c2 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -28,6 +28,9 @@ import type { InputObjectTypeDefinitionNode, ObjectTypeExtensionNode, InterfaceTypeExtensionNode, + UnionTypeExtensionNode, + EnumTypeExtensionNode, + InputObjectTypeExtensionNode, OperationDefinitionNode, FieldNode, FragmentDefinitionNode, @@ -972,7 +975,7 @@ export class GraphQLUnionType { name: string; description: ?string; astNode: ?UnionTypeDefinitionNode; - extensionASTNodes: ?$ReadOnlyArray; + extensionASTNodes: ?$ReadOnlyArray; resolveType: ?GraphQLTypeResolver<*, *>; _typeConfig: GraphQLUnionTypeConfig<*, *>; @@ -982,6 +985,7 @@ export class GraphQLUnionType { this.name = config.name; this.description = config.description; this.astNode = config.astNode; + this.extensionASTNodes = config.extensionASTNodes; this.resolveType = config.resolveType; this._typeConfig = config; invariant(typeof config.name === 'string', 'Must provide name.'); @@ -1032,6 +1036,7 @@ export type GraphQLUnionTypeConfig = { resolveType?: ?GraphQLTypeResolver, description?: ?string, astNode?: ?UnionTypeDefinitionNode, + extensionASTNodes?: ?$ReadOnlyArray, }; /** @@ -1059,7 +1064,7 @@ export class GraphQLEnumType /* */ { name: string; description: ?string; astNode: ?EnumTypeDefinitionNode; - extensionASTNodes: ?$ReadOnlyArray; + extensionASTNodes: ?$ReadOnlyArray; _values: Array */>; _valueLookup: Map; @@ -1069,6 +1074,7 @@ export class GraphQLEnumType /* */ { this.name = config.name; this.description = config.description; this.astNode = config.astNode; + this.extensionASTNodes = config.extensionASTNodes; this._values = defineEnumValues(this, config.values); this._valueLookup = new Map( this._values.map(enumValue => [enumValue.value, enumValue]), @@ -1157,6 +1163,7 @@ export type GraphQLEnumTypeConfig /* */ = { values: GraphQLEnumValueConfigMap /* */, description?: ?string, astNode?: ?EnumTypeDefinitionNode, + extensionASTNodes?: ?$ReadOnlyArray, }; export type GraphQLEnumValueConfigMap /* */ = ObjMap< @@ -1203,7 +1210,7 @@ export class GraphQLInputObjectType { name: string; description: ?string; astNode: ?InputObjectTypeDefinitionNode; - extensionASTNodes: ?$ReadOnlyArray; + extensionASTNodes: ?$ReadOnlyArray; _typeConfig: GraphQLInputObjectTypeConfig; _fields: GraphQLInputFieldMap; @@ -1212,6 +1219,7 @@ export class GraphQLInputObjectType { this.name = config.name; this.description = config.description; this.astNode = config.astNode; + this.extensionASTNodes = config.extensionASTNodes; this._typeConfig = config; invariant(typeof config.name === 'string', 'Must provide name.'); } @@ -1257,6 +1265,7 @@ export type GraphQLInputObjectTypeConfig = { fields: Thunk, description?: ?string, astNode?: ?InputObjectTypeDefinitionNode, + extensionASTNodes?: ?$ReadOnlyArray, }; export type GraphQLInputFieldConfig = { diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index 5a439d4a55..f962393a97 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -9,7 +9,7 @@ import { describe, it } from 'mocha'; import { expect } from 'chai'; import dedent from '../../jsutils/dedent'; import { extendSchema } from '../extendSchema'; -import { parse, print } from '../../language'; +import { parse, print, DirectiveLocation } from '../../language'; import { printSchema } from '../schemaPrinter'; import { Kind } from '../../language/kinds'; import { graphqlSync } from '../../'; @@ -24,9 +24,11 @@ import { GraphQLInputObjectType, GraphQLNonNull, GraphQLList, + GraphQLDirective, isScalarType, isNonNullType, validateSchema, + specifiedDirectives, } from '../../type'; // Test schema. @@ -103,6 +105,27 @@ const testSchema = new GraphQLSchema({ }), }), types: [FooType, BarType], + directives: specifiedDirectives.concat([ + new GraphQLDirective({ + name: 'foo', + args: { + input: { type: SomeInputType }, + }, + locations: [ + DirectiveLocation.SCHEMA, + DirectiveLocation.SCALAR, + DirectiveLocation.OBJECT, + DirectiveLocation.FIELD_DEFINITION, + DirectiveLocation.ARGUMENT_DEFINITION, + DirectiveLocation.INTERFACE, + DirectiveLocation.UNION, + DirectiveLocation.ENUM, + DirectiveLocation.ENUM_VALUE, + DirectiveLocation.INPUT_OBJECT, + DirectiveLocation.INPUT_FIELD_DEFINITION, + ], + }), + ]), }); function extendTestSchema(sdl, options) { @@ -151,7 +174,9 @@ describe('extendSchema', () => { const result = graphqlSync(extendedSchema, '{ newField }', { newField: 123, }); - expect(result.data).to.deep.equal({ newField: '123' }); + expect(result).to.deep.equal({ + data: { newField: '123' }, + }); }); it('can describe the extended fields', () => { @@ -210,6 +235,10 @@ describe('extendSchema', () => { newField: String } `); + + const fooType = extendedSchema.getType('Foo'); + const fooField = extendedSchema.getType('Query').getFields()['foo']; + expect(fooField.type).to.equal(fooType); }); it('extends enums by adding new values', () => { @@ -225,23 +254,23 @@ describe('extendSchema', () => { NEW_ENUM } `); + + const someEnumType = extendedSchema.getType('SomeEnum'); + const enumField = extendedSchema.getType('Query').getFields()['someEnum']; + expect(enumField.type).to.equal(someEnumType); }); it('extends unions by adding new types', () => { const extendedSchema = extendTestSchema(` - extend union SomeUnion = TestNewType - - type TestNewType { - foo: String - } + extend union SomeUnion = Bar `); expect(printTestSchemaChanges(extendedSchema)).to.equal(dedent` - union SomeUnion = Foo | Biz | TestNewType - - type TestNewType { - foo: String - } + union SomeUnion = Foo | Biz | Bar `); + + const someUnionType = extendedSchema.getType('SomeUnion'); + const unionField = extendedSchema.getType('Query').getFields()['someUnion']; + expect(unionField.type).to.equal(someUnionType); }); it('extends inputs by adding new fields', () => { @@ -256,6 +285,13 @@ describe('extendSchema', () => { newField: String } `); + + const someInputType = extendedSchema.getType('SomeInput'); + const inputField = extendedSchema.getType('Query').getFields()['someInput']; + expect(inputField.args[0].type).to.equal(someInputType); + + const fooDirective = extendedSchema.getDirective('foo'); + expect(fooDirective.args[0].type).to.equal(someInputType); }); it('correctly assign AST nodes to new and extended types', () => { @@ -264,6 +300,20 @@ describe('extendSchema', () => { newField(testArg: TestInput): TestEnum } + extend enum SomeEnum { + NEW_VALUE + } + + extend union SomeUnion = Bar + + extend input SomeInput { + newField: String + } + + extend interface SomeInterface { + newField: String + } + enum TestEnum { TEST_VALUE } @@ -272,11 +322,25 @@ describe('extendSchema', () => { testInputField: TestEnum } `); - const secondExtensionAST = parse(` + const ast = parse(` extend type Query { oneMoreNewField: TestUnion } + extend enum SomeEnum { + ONE_MORE_NEW_VALUE + } + + extend union SomeUnion = TestType + + extend input SomeInput { + oneMoreNewField: String + } + + extend interface SomeInterface { + oneMoreNewField: String + } + union TestUnion = TestType interface TestInterface { @@ -289,12 +353,14 @@ describe('extendSchema', () => { directive @test(arg: Int) on FIELD `); - const extendedTwiceSchema = extendSchema( - extendedSchema, - secondExtensionAST, - ); + const extendedTwiceSchema = extendSchema(extendedSchema, ast); const query = extendedTwiceSchema.getType('Query'); + const someEnum = extendedTwiceSchema.getType('SomeEnum'); + const someUnion = extendedTwiceSchema.getType('SomeUnion'); + const someInput = extendedTwiceSchema.getType('SomeInput'); + const someInterface = extendedTwiceSchema.getType('SomeInterface'); + const testInput = extendedTwiceSchema.getType('TestInput'); const testEnum = extendedTwiceSchema.getType('TestEnum'); const testUnion = extendedTwiceSchema.getType('TestUnion'); @@ -303,12 +369,25 @@ describe('extendSchema', () => { const testDirective = extendedTwiceSchema.getDirective('test'); expect(query.extensionASTNodes).to.have.lengthOf(2); + expect(someEnum.extensionASTNodes).to.have.lengthOf(2); + expect(someUnion.extensionASTNodes).to.have.lengthOf(2); + expect(someInput.extensionASTNodes).to.have.lengthOf(2); + expect(someInterface.extensionASTNodes).to.have.lengthOf(2); + expect(testType.extensionASTNodes).to.equal(undefined); + expect(testEnum.extensionASTNodes).to.equal(undefined); + expect(testUnion.extensionASTNodes).to.equal(undefined); + expect(testInput.extensionASTNodes).to.equal(undefined); + expect(testInterface.extensionASTNodes).to.equal(undefined); const restoredExtensionAST = { kind: Kind.DOCUMENT, definitions: [ ...query.extensionASTNodes, + ...someEnum.extensionASTNodes, + ...someUnion.extensionASTNodes, + ...someInput.extensionASTNodes, + ...someInterface.extensionASTNodes, testInput.astNode, testEnum.astNode, testUnion.astNode, @@ -329,6 +408,23 @@ describe('extendSchema', () => { expect(print(query.getFields().oneMoreNewField.astNode)).to.equal( 'oneMoreNewField: TestUnion', ); + expect(print(someEnum.getValue('NEW_VALUE').astNode)).to.equal('NEW_VALUE'); + expect(print(someEnum.getValue('ONE_MORE_NEW_VALUE').astNode)).to.equal( + 'ONE_MORE_NEW_VALUE', + ); + expect(print(someInput.getFields().newField.astNode)).to.equal( + 'newField: String', + ); + expect(print(someInput.getFields().oneMoreNewField.astNode)).to.equal( + 'oneMoreNewField: String', + ); + expect(print(someInterface.getFields().newField.astNode)).to.equal( + 'newField: String', + ); + expect(print(someInterface.getFields().oneMoreNewField.astNode)).to.equal( + 'oneMoreNewField: String', + ); + expect(print(testInput.getFields().testInputField.astNode)).to.equal( 'testInputField: TestEnum', ); @@ -884,11 +980,11 @@ describe('extendSchema', () => { }); it('does not allow replacing a default directive', () => { - const ast = parse(` + const sdl = ` directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD - `); + `; - expect(() => extendSchema(testSchema, ast)).to.throw( + expect(() => extendTestSchema(sdl)).to.throw( 'Directive "include" already exists in the schema. It cannot be ' + 'redefined.', ); @@ -909,167 +1005,150 @@ describe('extendSchema', () => { }); it('does not allow replacing an existing type', () => { - const typeAst = parse(` - type Bar { - baz: String - } - `); - expect(() => extendSchema(testSchema, typeAst)).to.throw( - 'Type "Bar" already exists in the schema. It cannot also be defined ' + - 'in this type definition.', + const existingTypeError = type => + `Type "${type}" already exists in the schema.` + + ' It cannot also be defined in this type definition.'; + + const typeSDL = ` + type Bar + `; + expect(() => extendTestSchema(typeSDL)).to.throw(existingTypeError('Bar')); + + const interfaceSDL = ` + interface SomeInterface + `; + expect(() => extendTestSchema(interfaceSDL)).to.throw( + existingTypeError('SomeInterface'), ); - const enumAst = parse(` - enum SomeEnum { - FOO - } - `); - expect(() => extendSchema(testSchema, enumAst)).to.throw( - 'Type "SomeEnum" already exists in the schema. It cannot also be defined ' + - 'in this type definition.', + const enumSDL = ` + enum SomeEnum + `; + expect(() => extendTestSchema(enumSDL)).to.throw( + existingTypeError('SomeEnum'), ); - const unionAst = parse(` - union SomeUnion = Foo - `); - expect(() => extendSchema(testSchema, unionAst)).to.throw( - 'Type "SomeUnion" already exists in the schema. It cannot also be defined ' + - 'in this type definition.', + const unionSDL = ` + union SomeUnion + `; + expect(() => extendTestSchema(unionSDL)).to.throw( + existingTypeError('SomeUnion'), ); - const inputAst = parse(` - input SomeInput { - some: String - } - `); - expect(() => extendSchema(testSchema, inputAst)).to.throw( - 'Type "SomeInput" already exists in the schema. It cannot also be defined ' + - 'in this type definition.', + const inputSDL = ` + input SomeInput + `; + expect(() => extendTestSchema(inputSDL)).to.throw( + existingTypeError('SomeInput'), ); }); it('does not allow replacing an existing field', () => { - const typeAst = parse(` + const existingFieldError = (type, field) => + `Field "${type}.${field}" already exists in the schema.` + + ' It cannot also be defined in this type extension.'; + + const typeSDL = ` extend type Bar { foo: Foo } - `); - expect(() => extendSchema(testSchema, typeAst)).to.throw( - 'Field "Bar.foo" already exists in the schema. It cannot also be ' + - 'defined in this type extension.', + `; + expect(() => extendTestSchema(typeSDL)).to.throw( + existingFieldError('Bar', 'foo'), ); - const enumAst = parse(` - extend enum SomeEnum { - ONE + const interfaceSDL = ` + extend interface SomeInterface { + some: Foo } - `); - expect(() => extendSchema(testSchema, enumAst)).to.throw( - 'Enum value "SomeEnum.ONE" already exists in the schema. It cannot ' + - 'also be defined in this type extension.', + `; + expect(() => extendTestSchema(interfaceSDL)).to.throw( + existingFieldError('SomeInterface', 'some'), ); - const inputAst = parse(` + const inputSDL = ` extend input SomeInput { fooArg: String } - `); - expect(() => extendSchema(testSchema, inputAst)).to.throw( - 'Field "SomeInput.fooArg" already exists in the schema. It cannot also be ' + - 'defined in this type extension.', + `; + expect(() => extendTestSchema(inputSDL)).to.throw( + existingFieldError('SomeInput', 'fooArg'), ); }); - it('does not allow referencing an unknown type', () => { - const typeAst = parse(` - extend type Bar { - quix: Quix + it('does not allow replacing an existing enum value', () => { + const sdl = ` + extend enum SomeEnum { + ONE } - `); - expect(() => extendSchema(testSchema, typeAst)).to.throw( - 'Unknown type: "Quix". Ensure that this type exists either in the ' + - 'original schema, or is added in a type definition.', + `; + expect(() => extendTestSchema(sdl)).to.throw( + 'Enum value "SomeEnum.ONE" already exists in the schema. It cannot ' + + 'also be defined in this type extension.', ); + }); - const unionAst = parse(` - extend union SomeUnion = Quix - `); - expect(() => extendSchema(testSchema, unionAst)).to.throw( + it('does not allow referencing an unknown type', () => { + const unknownTypeError = 'Unknown type: "Quix". Ensure that this type exists either in the ' + - 'original schema, or is added in a type definition.', - ); + 'original schema, or is added in a type definition.'; - const inputAst = parse(` - extend input SomeInput { + const typeSDL = ` + extend type Bar { quix: Quix } - `); - expect(() => extendSchema(testSchema, inputAst)).to.throw( - 'Unknown type: "Quix". Ensure that this type exists either in the ' + - 'original schema, or is added in a type definition.', - ); - }); - - it('does not allow extending an unknown type', () => { - const ast = parse(` - extend type UnknownType { - baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend type "UnknownType" because it does not exist in the ' + - 'existing schema.', - ); - }); - - it('does not allow extending an unknown interface type', () => { - const ast = parse(` - extend interface UnknownInterfaceType { - baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend type "UnknownInterfaceType" because it does not ' + - 'exist in the existing schema.', - ); - }); + `; + expect(() => extendTestSchema(typeSDL)).to.throw(unknownTypeError); - it('does not allow extending an unknown enum type', () => { - const ast = parse(` - extend enum UnknownEnumType { - BAZ + const intefaceSDL = ` + extend interface SomeInterface { + quix: Quix } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend type "UnknownEnumType" because it does not ' + - 'exist in the existing schema.', - ); - }); + `; + expect(() => extendTestSchema(intefaceSDL)).to.throw(unknownTypeError); - it('does not allow extending an unknown union type', () => { - const ast = parse(` - extend union UnknownUnionType = Baz + const unionSDL = ` + extend union SomeUnion = Quix + `; + expect(() => extendTestSchema(unionSDL)).to.throw(unknownTypeError); - type Baz { - foo: String + const inputSDL = ` + extend input SomeInput { + quix: Quix } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend type "UnknownUnionType" because it does not ' + - 'exist in the existing schema.', - ); + `; + expect(() => extendTestSchema(inputSDL)).to.throw(unknownTypeError); }); - it('does not allow extending an unknown input object type', () => { - const ast = parse(` - extend input UnknownInputObjectType { - foo: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend type "UnknownInputObjectType" because it does not ' + - 'exist in the existing schema.', - ); + it('does not allow extending an unknown type', () => { + const unknownTypeError = + 'Cannot extend type "UnknownType" because it does not exist in the ' + + 'existing schema.'; + + const typeSDL = ` + extend type UnknownType @foo + `; + expect(() => extendTestSchema(typeSDL)).to.throw(unknownTypeError); + + const intefaceSDL = ` + extend interface UnknownType @foo + `; + expect(() => extendTestSchema(intefaceSDL)).to.throw(unknownTypeError); + + const enumSDL = ` + extend enum UnknownType @foo + `; + expect(() => extendTestSchema(enumSDL)).to.throw(unknownTypeError); + + const unionSDL = ` + extend union UnknownType @foo + `; + expect(() => extendTestSchema(unionSDL)).to.throw(unknownTypeError); + + const inputSDL = ` + extend input UnknownType @foo + `; + expect(() => extendTestSchema(inputSDL)).to.throw(unknownTypeError); }); it('maintains configuration of the original schema object', () => { @@ -1088,7 +1167,7 @@ describe('extendSchema', () => { } `); const schema = extendSchema(testSchemaWithLegacyNames, ast); - expect(schema.__allowedLegacyNames).to.deep.equal(['__badName']); + expect(schema).to.have.deep.property('__allowedLegacyNames', ['__badName']); }); it('adds to the configuration of the original schema object', () => { @@ -1109,95 +1188,61 @@ describe('extendSchema', () => { const schema = extendSchema(testSchemaWithLegacyNames, ast, { allowedLegacyNames: ['__anotherBadName'], }); - expect(schema.__allowedLegacyNames).to.deep.equal([ + expect(schema).to.have.deep.property('__allowedLegacyNames', [ '__badName', '__anotherBadName', ]); }); - describe('does not allow extending a non-object type', () => { - it('not an object', () => { - const ast = parse(` - extend type SomeInterface { - baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-object type "SomeInterface".', - ); - }); - - it('not an interface', () => { - const ast = parse(` - extend interface Foo { - baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-interface type "Foo".', - ); - }); - - it('not a scalar', () => { - const ast = parse(` - extend type String { - baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-object type "String".', - ); - }); + describe('does not allow extending a mismatch type', () => { + const typeSDL = ` + extend type SomeInterface @foo + `; + expect(() => extendTestSchema(typeSDL)).to.throw( + 'Cannot extend non-object type "SomeInterface".', + ); - it('not an enum', () => { - const ast = parse(` - extend enum Foo { - BAZ - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-enum type "Foo".', - ); - }); + const intefaceSDL = ` + extend interface Foo @foo + `; + expect(() => extendTestSchema(intefaceSDL)).to.throw( + 'Cannot extend non-interface type "Foo".', + ); - it('not an union', () => { - const ast = parse(` - extend union Foo = Baz + const enumSDL = ` + extend enum Foo @foo + `; + expect(() => extendTestSchema(enumSDL)).to.throw( + 'Cannot extend non-enum type "Foo".', + ); - type Baz { - foo: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-union type "Foo".', - ); - }); + const unionSDL = ` + extend union Foo @foo + `; + expect(() => extendTestSchema(unionSDL)).to.throw( + 'Cannot extend non-union type "Foo".', + ); - it('not an input object', () => { - const ast = parse(` - extend input Foo { - Baz: String - } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( - 'Cannot extend non-input object type "Foo".', - ); - }); + const inputSDL = ` + extend input Foo @foo + `; + expect(() => extendTestSchema(inputSDL)).to.throw( + 'Cannot extend non-input object type "Foo".', + ); }); describe('can add additional root operation types', () => { it('does not automatically include common root type names', () => { - const ast = parse(` + const schema = extendTestSchema(` type Mutation { doSomething: String } `); - const schema = extendSchema(testSchema, ast); expect(schema.getMutationType()).to.equal(null); }); it('does not allow new schema within an extension', () => { - const ast = parse(` + const sdl = ` schema { mutation: Mutation } @@ -1205,14 +1250,14 @@ describe('extendSchema', () => { type Mutation { doSomething: String } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( + `; + expect(() => extendTestSchema(sdl)).to.throw( 'Cannot define a new schema within a schema extension.', ); }); it('adds new root types via schema extension', () => { - const ast = parse(` + const schema = extendTestSchema(` extend schema { mutation: Mutation } @@ -1221,13 +1266,12 @@ describe('extendSchema', () => { doSomething: String } `); - const schema = extendSchema(testSchema, ast); const mutationType = schema.getMutationType(); - expect(mutationType && mutationType.name).to.equal('Mutation'); + expect(mutationType).to.have.property('name', 'Mutation'); }); it('adds multiple new root types via schema extension', () => { - const ast = parse(` + const schema = extendTestSchema(` extend schema { mutation: Mutation subscription: Subscription @@ -1241,17 +1285,14 @@ describe('extendSchema', () => { hearSomething: String } `); - const schema = extendSchema(testSchema, ast); const mutationType = schema.getMutationType(); const subscriptionType = schema.getSubscriptionType(); - expect(mutationType && mutationType.name).to.equal('Mutation'); - expect(subscriptionType && subscriptionType.name).to.equal( - 'Subscription', - ); + expect(mutationType).to.have.property('name', 'Mutation'); + expect(subscriptionType).to.have.property('name', 'Subscription'); }); it('applies multiple schema extensions', () => { - const ast = parse(` + const schema = extendTestSchema(` extend schema { mutation: Mutation } @@ -1268,17 +1309,14 @@ describe('extendSchema', () => { hearSomething: String } `); - const schema = extendSchema(testSchema, ast); const mutationType = schema.getMutationType(); const subscriptionType = schema.getSubscriptionType(); - expect(mutationType && mutationType.name).to.equal('Mutation'); - expect(subscriptionType && subscriptionType.name).to.equal( - 'Subscription', - ); + expect(mutationType).to.have.property('name', 'Mutation'); + expect(subscriptionType).to.have.property('name', 'Subscription'); }); it('schema extension AST are available from schema object', () => { - const ast = parse(` + let schema = extendTestSchema(` extend schema { mutation: Mutation } @@ -1295,14 +1333,11 @@ describe('extendSchema', () => { hearSomething: String } `); - let schema = extendSchema(testSchema, ast); - const secondAST = parse(` + const ast = parse(` extend schema @foo - - directive @foo on SCHEMA `); - schema = extendSchema(schema, secondAST); + schema = extendSchema(schema, ast); const nodes = schema.extensionASTNodes; expect(nodes.map(n => print(n) + '\n').join('')).to.equal(dedent` @@ -1317,7 +1352,7 @@ describe('extendSchema', () => { }); it('does not allow redefining an existing root type', () => { - const ast = parse(` + const sdl = ` extend schema { query: SomeType } @@ -1325,14 +1360,14 @@ describe('extendSchema', () => { type SomeType { seeSomething: String } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( + `; + expect(() => extendTestSchema(sdl)).to.throw( 'Must provide only one query type in schema.', ); }); it('does not allow defining a root operation type twice', () => { - const ast = parse(` + const sdl = ` extend schema { mutation: Mutation } @@ -1344,14 +1379,14 @@ describe('extendSchema', () => { type Mutation { doSomething: String } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( + `; + expect(() => extendTestSchema(sdl)).to.throw( 'Must provide only one mutation type in schema.', ); }); it('does not allow defining a root operation type with different types', () => { - const ast = parse(` + const sdl = ` extend schema { mutation: Mutation } @@ -1367,8 +1402,8 @@ describe('extendSchema', () => { type SomethingElse { doSomethingElse: String } - `); - expect(() => extendSchema(testSchema, ast)).to.throw( + `; + expect(() => extendTestSchema(sdl)).to.throw( 'Must provide only one mutation type in schema.', ); });