From 47d6c01ae5cdeb0c1638f7a4c66fbe59ad0def13 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 18 Aug 2019 23:13:30 +0300 Subject: [PATCH] extendSchema-test: replace 'GraphQL*' types with SDL --- src/utilities/__tests__/extendSchema-test.js | 167 ++++++------------- 1 file changed, 51 insertions(+), 116 deletions(-) diff --git a/src/utilities/__tests__/extendSchema-test.js b/src/utilities/__tests__/extendSchema-test.js index 360cd82d34..5e115cbe13 100644 --- a/src/utilities/__tests__/extendSchema-test.js +++ b/src/utilities/__tests__/extendSchema-test.js @@ -9,17 +9,12 @@ import invariant from '../../jsutils/invariant'; import { Kind } from '../../language/kinds'; import { parse } from '../../language/parser'; import { print } from '../../language/printer'; -import { DirectiveLocation } from '../../language/directiveLocation'; import { graphqlSync } from '../../graphql'; import { GraphQLSchema } from '../../type/schema'; import { validateSchema } from '../../type/validate'; -import { - assertDirective, - GraphQLDirective, - specifiedDirectives, -} from '../../type/directives'; +import { assertDirective } from '../../type/directives'; import { GraphQLID, GraphQLInt, @@ -34,14 +29,7 @@ import { assertUnionType, assertInterfaceType, assertScalarType, - GraphQLList, - GraphQLNonNull, - GraphQLScalarType, GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, - GraphQLEnumType, - GraphQLInputObjectType, } from '../../type/definition'; import { printSchema } from '../schemaPrinter'; @@ -49,105 +37,52 @@ import { extendSchema } from '../extendSchema'; import { buildSchema } from '../buildASTSchema'; // Test schema. -const SomeScalarType = new GraphQLScalarType({ name: 'SomeScalar' }); - -const SomeInterfaceType = new GraphQLInterfaceType({ - name: 'SomeInterface', - fields: () => ({ - name: { type: GraphQLString }, - some: { type: SomeInterfaceType }, - }), -}); - -const FooType = new GraphQLObjectType({ - name: 'Foo', - interfaces: [SomeInterfaceType], - fields: () => ({ - name: { type: GraphQLString }, - some: { type: SomeInterfaceType }, - tree: { type: GraphQLNonNull(GraphQLList(FooType)) }, - }), -}); - -const BarType = new GraphQLObjectType({ - name: 'Bar', - interfaces: [SomeInterfaceType], - fields: () => ({ - name: { type: GraphQLString }, - some: { type: SomeInterfaceType }, - foo: { type: FooType }, - }), -}); - -const BizType = new GraphQLObjectType({ - name: 'Biz', - fields: () => ({ - fizz: { type: GraphQLString }, - }), -}); - -const SomeUnionType = new GraphQLUnionType({ - name: 'SomeUnion', - types: [FooType, BizType], -}); - -const SomeEnumType = new GraphQLEnumType({ - name: 'SomeEnum', - values: { - ONE: { value: 1 }, - TWO: { value: 2 }, - }, -}); - -const SomeInputType = new GraphQLInputObjectType({ - name: 'SomeInput', - fields: () => ({ - fooArg: { type: GraphQLString }, - }), -}); - -const FooDirective = new GraphQLDirective({ - name: 'foo', - args: { - input: { type: SomeInputType }, - }, - isRepeatable: true, - 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, - ], -}); - -const testSchema = new GraphQLSchema({ - query: new GraphQLObjectType({ - name: 'Query', - fields: () => ({ - foo: { type: FooType }, - someScalar: { type: SomeScalarType }, - someUnion: { type: SomeUnionType }, - someEnum: { type: SomeEnumType }, - someInterface: { - args: { id: { type: GraphQLNonNull(GraphQLID) } }, - type: SomeInterfaceType, - }, - someInput: { - args: { input: { type: SomeInputType } }, - type: GraphQLString, - }, - }), - }), - types: [FooType, BarType], - directives: specifiedDirectives.concat([FooDirective]), -}); +const testSchema = buildSchema(` + scalar SomeScalar + + interface SomeInterface { + name: String + some: SomeInterface + } + + type Foo implements SomeInterface { + name: String + some: SomeInterface + tree: [Foo]! + } + + type Bar implements SomeInterface { + name: String + some: SomeInterface + foo: Foo + } + + type Biz { + fizz: String + } + + union SomeUnion = Foo | Biz + + enum SomeEnum { + ONE + TWO + } + + input SomeInput { + fooArg: String + } + + directive @foo(input: SomeInput) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION + + type Query { + foo: Foo + someScalar: SomeScalar + someUnion: SomeUnion + someEnum: SomeEnum + someInterface(id: ID!): SomeInterface + someInput(input: SomeInput): String + } +`); function extendTestSchema(sdl, options) { const originalPrint = printSchema(testSchema); @@ -1203,10 +1138,10 @@ describe('extendSchema', () => { }); it('adds schema definition missing in the original schema', () => { - let schema = new GraphQLSchema({ - directives: [FooDirective], - types: [FooType], - }); + let schema = buildSchema(` + directive @foo on SCHEMA + type Foo + `); expect(schema.getQueryType()).to.equal(undefined); const extensionSDL = dedent`