88 */
99
1010import invariant from '../jsutils/invariant' ;
11+ import keyMap from '../jsutils/keyMap' ;
1112import keyValMap from '../jsutils/keyValMap' ;
1213import type { ObjMap } from '../jsutils/ObjMap' ;
1314import { valueFromAST } from './valueFromAST' ;
@@ -39,15 +40,9 @@ import type {
3940 DirectiveDefinitionNode ,
4041} from '../language/ast' ;
4142
42- import { GraphQLSchema } from '../type/schema' ;
43-
44- import {
45- GraphQLString ,
46- GraphQLInt ,
47- GraphQLFloat ,
48- GraphQLBoolean ,
49- GraphQLID ,
50- } from '../type/scalars' ;
43+ import type {
44+ DirectiveLocationEnum
45+ } from '../language/directiveLocation' ;
5146
5247import {
5348 GraphQLScalarType ,
@@ -62,35 +57,26 @@ import {
6257 assertOutputType ,
6358} from '../type/definition' ;
6459
65- import type {
66- GraphQLType ,
67- GraphQLNamedType ,
68- GraphQLInputType ,
69- GraphQLOutputType ,
70- GraphQLFieldConfig ,
71- } from '../type/definition' ;
72-
7360import {
7461 GraphQLDirective ,
7562 GraphQLSkipDirective ,
7663 GraphQLIncludeDirective ,
7764 GraphQLDeprecatedDirective ,
7865} from '../type/directives' ;
7966
80- import type {
81- DirectiveLocationEnum
82- } from '../language/directiveLocation' ;
67+ import { introspectionTypes } from '../type/introspection' ;
8368
84- import {
85- __Schema ,
86- __Directive ,
87- __DirectiveLocation ,
88- __Type ,
89- __Field ,
90- __InputValue ,
91- __EnumValue ,
92- __TypeKind ,
93- } from '../type/introspection' ;
69+ import { specifiedScalarTypes } from '../type/scalars' ;
70+
71+ import { GraphQLSchema } from '../type/schema' ;
72+
73+ import type {
74+ GraphQLType ,
75+ GraphQLNamedType ,
76+ GraphQLInputType ,
77+ GraphQLOutputType ,
78+ GraphQLFieldConfig ,
79+ } from '../type/definition' ;
9480
9581type Options = { | commentDescriptions ?: boolean | } ;
9682
@@ -260,7 +246,7 @@ export class ASTDefinitionBuilder {
260246 _typeDefinitionsMap : TypeDefinitionsMap ;
261247 _options : ?Options ;
262248 _resolveType : TypeResolver ;
263- _cache : { [ typeName : string ] : GraphQLNamedType } ;
249+ _cache : ObjMap < GraphQLNamedType > ;
264250
265251 constructor (
266252 typeDefinitionsMap : TypeDefinitionsMap ,
@@ -271,21 +257,10 @@ export class ASTDefinitionBuilder {
271257 this . _options = options ;
272258 this . _resolveType = resolveType ;
273259 // Initialize to the GraphQL built in scalars and introspection types.
274- this . _cache = {
275- String : GraphQLString ,
276- Int : GraphQLInt ,
277- Float : GraphQLFloat ,
278- Boolean : GraphQLBoolean ,
279- ID : GraphQLID ,
280- __Schema,
281- __Directive,
282- __DirectiveLocation,
283- __Type,
284- __Field,
285- __InputValue,
286- __EnumValue,
287- __TypeKind,
288- } ;
260+ this . _cache = keyMap (
261+ specifiedScalarTypes . concat ( introspectionTypes ) ,
262+ type => type . name
263+ ) ;
289264 }
290265
291266 _buildType ( typeName : string , typeNode ?: ?NamedTypeNode ) : GraphQLNamedType {
0 commit comments