@@ -9,17 +9,12 @@ import invariant from '../../jsutils/invariant';
9
9
import { Kind } from '../../language/kinds' ;
10
10
import { parse } from '../../language/parser' ;
11
11
import { print } from '../../language/printer' ;
12
- import { DirectiveLocation } from '../../language/directiveLocation' ;
13
12
14
13
import { graphqlSync } from '../../graphql' ;
15
14
16
15
import { GraphQLSchema } from '../../type/schema' ;
17
16
import { validateSchema } from '../../type/validate' ;
18
- import {
19
- assertDirective ,
20
- GraphQLDirective ,
21
- specifiedDirectives ,
22
- } from '../../type/directives' ;
17
+ import { assertDirective } from '../../type/directives' ;
23
18
import {
24
19
GraphQLID ,
25
20
GraphQLInt ,
@@ -34,120 +29,60 @@ import {
34
29
assertUnionType ,
35
30
assertInterfaceType ,
36
31
assertScalarType ,
37
- GraphQLList ,
38
- GraphQLNonNull ,
39
- GraphQLScalarType ,
40
32
GraphQLObjectType ,
41
- GraphQLInterfaceType ,
42
- GraphQLUnionType ,
43
- GraphQLEnumType ,
44
- GraphQLInputObjectType ,
45
33
} from '../../type/definition' ;
46
34
47
35
import { printSchema } from '../schemaPrinter' ;
48
36
import { extendSchema } from '../extendSchema' ;
49
37
import { buildSchema } from '../buildASTSchema' ;
50
38
51
39
// 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
+ ` ) ;
151
86
152
87
function extendTestSchema ( sdl , options ) {
153
88
const originalPrint = printSchema ( testSchema ) ;
@@ -1203,10 +1138,10 @@ describe('extendSchema', () => {
1203
1138
} ) ;
1204
1139
1205
1140
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
+ ` ) ;
1210
1145
expect ( schema . getQueryType ( ) ) . to . equal ( undefined ) ;
1211
1146
1212
1147
const extensionSDL = dedent `
0 commit comments