Skip to content

Commit 57e7e1b

Browse files
extendSchema-test: replace 'GraphQL*' types with SDL (#2095)
1 parent 68d6402 commit 57e7e1b

File tree

1 file changed

+51
-116
lines changed

1 file changed

+51
-116
lines changed

src/utilities/__tests__/extendSchema-test.js

Lines changed: 51 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ import invariant from '../../jsutils/invariant';
99
import { Kind } from '../../language/kinds';
1010
import { parse } from '../../language/parser';
1111
import { print } from '../../language/printer';
12-
import { DirectiveLocation } from '../../language/directiveLocation';
1312

1413
import { graphqlSync } from '../../graphql';
1514

1615
import { GraphQLSchema } from '../../type/schema';
1716
import { validateSchema } from '../../type/validate';
18-
import {
19-
assertDirective,
20-
GraphQLDirective,
21-
specifiedDirectives,
22-
} from '../../type/directives';
17+
import { assertDirective } from '../../type/directives';
2318
import {
2419
GraphQLID,
2520
GraphQLInt,
@@ -34,120 +29,60 @@ import {
3429
assertUnionType,
3530
assertInterfaceType,
3631
assertScalarType,
37-
GraphQLList,
38-
GraphQLNonNull,
39-
GraphQLScalarType,
4032
GraphQLObjectType,
41-
GraphQLInterfaceType,
42-
GraphQLUnionType,
43-
GraphQLEnumType,
44-
GraphQLInputObjectType,
4533
} from '../../type/definition';
4634

4735
import { printSchema } from '../schemaPrinter';
4836
import { extendSchema } from '../extendSchema';
4937
import { buildSchema } from '../buildASTSchema';
5038

5139
// Test schema.
52-
const SomeScalarType = new GraphQLScalarType({ name: 'SomeScalar' });
53-
54-
const SomeInterfaceType = new GraphQLInterfaceType({
55-
name: 'SomeInterface',
56-
fields: () => ({
57-
name: { type: GraphQLString },
58-
some: { type: SomeInterfaceType },
59-
}),
60-
});
61-
62-
const FooType = new GraphQLObjectType({
63-
name: 'Foo',
64-
interfaces: [SomeInterfaceType],
65-
fields: () => ({
66-
name: { type: GraphQLString },
67-
some: { type: SomeInterfaceType },
68-
tree: { type: GraphQLNonNull(GraphQLList(FooType)) },
69-
}),
70-
});
71-
72-
const BarType = new GraphQLObjectType({
73-
name: 'Bar',
74-
interfaces: [SomeInterfaceType],
75-
fields: () => ({
76-
name: { type: GraphQLString },
77-
some: { type: SomeInterfaceType },
78-
foo: { type: FooType },
79-
}),
80-
});
81-
82-
const BizType = new GraphQLObjectType({
83-
name: 'Biz',
84-
fields: () => ({
85-
fizz: { type: GraphQLString },
86-
}),
87-
});
88-
89-
const SomeUnionType = new GraphQLUnionType({
90-
name: 'SomeUnion',
91-
types: [FooType, BizType],
92-
});
93-
94-
const SomeEnumType = new GraphQLEnumType({
95-
name: 'SomeEnum',
96-
values: {
97-
ONE: { value: 1 },
98-
TWO: { value: 2 },
99-
},
100-
});
101-
102-
const SomeInputType = new GraphQLInputObjectType({
103-
name: 'SomeInput',
104-
fields: () => ({
105-
fooArg: { type: GraphQLString },
106-
}),
107-
});
108-
109-
const FooDirective = new GraphQLDirective({
110-
name: 'foo',
111-
args: {
112-
input: { type: SomeInputType },
113-
},
114-
isRepeatable: true,
115-
locations: [
116-
DirectiveLocation.SCHEMA,
117-
DirectiveLocation.SCALAR,
118-
DirectiveLocation.OBJECT,
119-
DirectiveLocation.FIELD_DEFINITION,
120-
DirectiveLocation.ARGUMENT_DEFINITION,
121-
DirectiveLocation.INTERFACE,
122-
DirectiveLocation.UNION,
123-
DirectiveLocation.ENUM,
124-
DirectiveLocation.ENUM_VALUE,
125-
DirectiveLocation.INPUT_OBJECT,
126-
DirectiveLocation.INPUT_FIELD_DEFINITION,
127-
],
128-
});
129-
130-
const testSchema = new GraphQLSchema({
131-
query: new GraphQLObjectType({
132-
name: 'Query',
133-
fields: () => ({
134-
foo: { type: FooType },
135-
someScalar: { type: SomeScalarType },
136-
someUnion: { type: SomeUnionType },
137-
someEnum: { type: SomeEnumType },
138-
someInterface: {
139-
args: { id: { type: GraphQLNonNull(GraphQLID) } },
140-
type: SomeInterfaceType,
141-
},
142-
someInput: {
143-
args: { input: { type: SomeInputType } },
144-
type: GraphQLString,
145-
},
146-
}),
147-
}),
148-
types: [FooType, BarType],
149-
directives: specifiedDirectives.concat([FooDirective]),
150-
});
40+
const testSchema = buildSchema(`
41+
scalar SomeScalar
42+
43+
interface SomeInterface {
44+
name: String
45+
some: SomeInterface
46+
}
47+
48+
type Foo implements SomeInterface {
49+
name: String
50+
some: SomeInterface
51+
tree: [Foo]!
52+
}
53+
54+
type Bar implements SomeInterface {
55+
name: String
56+
some: SomeInterface
57+
foo: Foo
58+
}
59+
60+
type Biz {
61+
fizz: String
62+
}
63+
64+
union SomeUnion = Foo | Biz
65+
66+
enum SomeEnum {
67+
ONE
68+
TWO
69+
}
70+
71+
input SomeInput {
72+
fooArg: String
73+
}
74+
75+
directive @foo(input: SomeInput) repeatable on SCHEMA | SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
76+
77+
type Query {
78+
foo: Foo
79+
someScalar: SomeScalar
80+
someUnion: SomeUnion
81+
someEnum: SomeEnum
82+
someInterface(id: ID!): SomeInterface
83+
someInput(input: SomeInput): String
84+
}
85+
`);
15186

15287
function extendTestSchema(sdl, options) {
15388
const originalPrint = printSchema(testSchema);
@@ -1203,10 +1138,10 @@ describe('extendSchema', () => {
12031138
});
12041139

12051140
it('adds schema definition missing in the original schema', () => {
1206-
let schema = new GraphQLSchema({
1207-
directives: [FooDirective],
1208-
types: [FooType],
1209-
});
1141+
let schema = buildSchema(`
1142+
directive @foo on SCHEMA
1143+
type Foo
1144+
`);
12101145
expect(schema.getQueryType()).to.equal(undefined);
12111146

12121147
const extensionSDL = dedent`

0 commit comments

Comments
 (0)