@@ -8,15 +8,26 @@ import {
8
8
GraphQLNonNull ,
9
9
GraphQLBoolean ,
10
10
GraphQLID ,
11
+ DirectiveLocation ,
12
+ GraphQLDirective ,
11
13
} from 'graphql/type' ;
12
14
import { parse } from 'graphql/language' ;
13
15
import { expectTypesEqual , expectSchemasEqual } from './comparators' ;
14
- import build , { buildTypes } from '../' ;
16
+ import build , { buildTypes , SCHEMA_CONFIG_KEY } from '../' ;
15
17
18
+ const CustomDirective = new GraphQLDirective ( {
19
+ name : 'CustomDirective' ,
20
+ locations : [ DirectiveLocation . FIELD ] ,
21
+ } ) ;
16
22
const querySource = `
17
- type Query {
18
- ok: Boolean!
19
- }
23
+ type Query {
24
+ ok: Boolean!
25
+ }
26
+ ` ;
27
+ const queryWithDirectiveSource = `
28
+ type Query {
29
+ ok: Boolean! @CustomDirective
30
+ }
20
31
` ;
21
32
const generateQuery = ( resolve ) => new GraphQLObjectType ( {
22
33
name : 'Query' ,
@@ -28,6 +39,10 @@ const schemaSource = `
28
39
}
29
40
` ;
30
41
const Schema = new GraphQLSchema ( { query : generateQuery ( ) } ) ;
42
+ const SchemaWithDirective = new GraphQLSchema ( {
43
+ directives : [ CustomDirective ] ,
44
+ query : generateQuery ( ) ,
45
+ } ) ;
31
46
const timestampSource = `
32
47
scalar Timestamp
33
48
` ;
@@ -149,4 +164,11 @@ describe('build()', () => {
149
164
Timestamp : { serialize } ,
150
165
} , undefined , false ) ) . forEach ( ( type , i ) => expectTypesEqual ( type , [ Record , Timestamp ] [ i ] ) ) ;
151
166
} ) ;
167
+
168
+ it ( 'should allow schema configuration using SCHEMA_CONFIG_KEY' , ( ) => {
169
+ const config = { } ;
170
+ config [ SCHEMA_CONFIG_KEY ] = { directives : [ CustomDirective ] } ;
171
+ const target = build ( schemaSource + queryWithDirectiveSource , config ) ;
172
+ expectSchemasEqual ( target , SchemaWithDirective ) ;
173
+ } ) ;
152
174
} ) ;
0 commit comments