@@ -8,15 +8,26 @@ import {
88 GraphQLNonNull ,
99 GraphQLBoolean ,
1010 GraphQLID ,
11+ DirectiveLocation ,
12+ GraphQLDirective ,
1113} from 'graphql/type' ;
1214import { parse } from 'graphql/language' ;
1315import { expectTypesEqual , expectSchemasEqual } from './comparators' ;
14- import build , { buildTypes } from '../' ;
16+ import build , { buildTypes , SCHEMA_CONFIG_KEY } from '../' ;
1517
18+ const CustomDirective = new GraphQLDirective ( {
19+ name : 'CustomDirective' ,
20+ locations : [ DirectiveLocation . FIELD ] ,
21+ } ) ;
1622const 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+ }
2031` ;
2132const generateQuery = ( resolve ) => new GraphQLObjectType ( {
2233 name : 'Query' ,
@@ -28,6 +39,10 @@ const schemaSource = `
2839 }
2940` ;
3041const Schema = new GraphQLSchema ( { query : generateQuery ( ) } ) ;
42+ const SchemaWithDirective = new GraphQLSchema ( {
43+ directives : [ CustomDirective ] ,
44+ query : generateQuery ( ) ,
45+ } ) ;
3146const timestampSource = `
3247 scalar Timestamp
3348` ;
@@ -149,4 +164,11 @@ describe('build()', () => {
149164 Timestamp : { serialize } ,
150165 } , undefined , false ) ) . forEach ( ( type , i ) => expectTypesEqual ( type , [ Record , Timestamp ] [ i ] ) ) ;
151166 } ) ;
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+ } ) ;
152174} ) ;
0 commit comments