@@ -13,7 +13,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
13
13
14
14
import { isObjectType , isInterfaceType , isUnionType , isInputObjectType , isWrappingType } from './definition' ;
15
15
16
- import { GraphQLDirective , specifiedDirectives } from './directives' ;
16
+ import { GraphQLDirective , isDirective , specifiedDirectives } from './directives' ;
17
17
18
18
import { __Schema } from './introspection' ;
19
19
import find from '../jsutils/find' ;
@@ -88,7 +88,17 @@ export var GraphQLSchema = function () {
88
88
initialTypes = initialTypes . concat ( types ) ;
89
89
}
90
90
91
- this . _typeMap = initialTypes . reduce ( typeMapReducer , Object . create ( null ) ) ;
91
+ // Keep track of all types referenced within the schema.
92
+ var typeMap = Object . create ( null ) ;
93
+
94
+ // First by deeply visiting all initial types.
95
+ typeMap = initialTypes . reduce ( typeMapReducer , typeMap ) ;
96
+
97
+ // Then by deeply visiting all directive types.
98
+ typeMap = this . _directives . reduce ( typeMapDirectiveReducer , typeMap ) ;
99
+
100
+ // Storing the resulting map for reference by the schema.
101
+ this . _typeMap = typeMap ;
92
102
93
103
// Keep track of all implementations by interface name.
94
104
this . _implementations = Object . create ( null ) ;
@@ -213,4 +223,14 @@ function typeMapReducer(map, type) {
213
223
}
214
224
215
225
return reducedMap ;
226
+ }
227
+
228
+ function typeMapDirectiveReducer ( map , directive ) {
229
+ // Directives are not validated until validateSchema() is called.
230
+ if ( ! isDirective ( directive ) ) {
231
+ return map ;
232
+ }
233
+ return directive . args . reduce ( function ( _map , arg ) {
234
+ return typeMapReducer ( _map , arg . type ) ;
235
+ } , map ) ;
216
236
}
0 commit comments