Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extendSchema-test: replace 'GraphQL*' types with SDL #2095

Merged
merged 1 commit into from Aug 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
167 changes: 51 additions & 116 deletions src/utilities/__tests__/extendSchema-test.js
Expand Up @@ -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,
Expand All @@ -34,120 +29,60 @@ import {
assertUnionType,
assertInterfaceType,
assertScalarType,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLUnionType,
GraphQLEnumType,
GraphQLInputObjectType,
} from '../../type/definition';

import { printSchema } from '../schemaPrinter';
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);
Expand Down Expand Up @@ -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`
Expand Down