1010
1111import invariant from '../jsutils/invariant' ;
1212import isNullish from '../jsutils/isNullish' ;
13- import keyMap from '../jsutils/keyMap' ;
1413import { ENUM } from '../language/kinds' ;
1514import { assertValidName } from '../utilities/assertValidName' ;
1615import type {
@@ -321,7 +320,6 @@ export class GraphQLObjectType {
321320 }
322321 this . isTypeOf = config . isTypeOf ;
323322 this . _typeConfig = config ;
324- addImplementationToInterfaces ( this ) ;
325323 }
326324
327325 getFields ( ) : GraphQLFieldDefinitionMap {
@@ -444,18 +442,6 @@ function isPlainObj(obj) {
444442 return obj && typeof obj === 'object ' && ! Array . isArray ( obj ) ;
445443}
446444
447- /**
448- * Update the interfaces to know about this implementation.
449- * This is an rare and unfortunate use of mutation in the type definition
450- * implementations, but avoids an expensive "getPossibleTypes"
451- * implementation for Interface types.
452- */
453- function addImplementationToInterfaces ( impl ) {
454- impl . getInterfaces ( ) . forEach ( type => {
455- type . _implementations . push ( impl ) ;
456- } ) ;
457- }
458-
459445export type GraphQLObjectTypeConfig = {
460446 name : string ;
461447 interfaces ?: GraphQLInterfacesThunk | Array < GraphQLInterfaceType > ;
@@ -565,8 +551,6 @@ export class GraphQLInterfaceType {
565551
566552 _typeConfig : GraphQLInterfaceTypeConfig ;
567553 _fields : GraphQLFieldDefinitionMap ;
568- _implementations : Array < GraphQLObjectType > ;
569- _possibleTypes : { [ typeName : string ] : GraphQLObjectType } ;
570554
571555 constructor ( config : GraphQLInterfaceTypeConfig ) {
572556 invariant ( config . name , 'Type must be named . ') ;
@@ -581,25 +565,13 @@ export class GraphQLInterfaceType {
581565 }
582566 this . resolveType = config . resolveType ;
583567 this . _typeConfig = config ;
584- this . _implementations = [ ] ;
585568 }
586569
587570 getFields ( ) : GraphQLFieldDefinitionMap {
588571 return this . _fields ||
589572 ( this . _fields = defineFieldMap ( this , this . _typeConfig . fields ) ) ;
590573 }
591574
592- getPossibleTypes ( ) : Array < GraphQLObjectType > {
593- return this . _implementations ;
594- }
595-
596- isPossibleType ( type : GraphQLObjectType ) : boolean {
597- const possibleTypes = this . _possibleTypes || ( this . _possibleTypes =
598- keyMap ( this . getPossibleTypes ( ) , possibleType => possibleType . name )
599- ) ;
600- return Boolean ( possibleTypes [ type . name ] ) ;
601- }
602-
603575 toString ( ) : string {
604576 return this . name ;
605577 }
@@ -686,22 +658,10 @@ export class GraphQLUnionType {
686658 this . _typeConfig = config ;
687659 }
688660
689- getPossibleTypes ( ) : Array < GraphQLObjectType > {
661+ getTypes ( ) : Array < GraphQLObjectType > {
690662 return this . _types ;
691663 }
692664
693- isPossibleType ( type : GraphQLObjectType ) : boolean {
694- let possibleTypeNames = this . _possibleTypeNames ;
695- if ( ! possibleTypeNames ) {
696- this . _possibleTypeNames = possibleTypeNames =
697- this . getPossibleTypes ( ) . reduce (
698- ( map , possibleType ) => ( ( map [ possibleType . name ] = true ) , map ) ,
699- { }
700- ) ;
701- }
702- return possibleTypeNames [ type . name ] === true ;
703- }
704-
705665 toString ( ) : string {
706666 return this . name ;
707667 }
0 commit comments