import { GraphQLType } from 'graphql' ; import { defaultInputFieldInstantiator , Instantiator } from '../types' ; import { TypeExpression } from './TypeExpression' ; import { Definition } from '../metadata/Definition' ; import { TypeResolvingContext } from './types' ; /**
 * Contain an argument which can be resolved to GraphQLType instance.
 */ export class DefinitionTypeExpression extends TypeExpression { constructor ( protected typeArg ) { super ( ) ; } getTypeName ( context ) { return this . resolveDefinition ( context ) . definitionName ; } public getType ( context ) { return this . resolveDefinition ( context ) . getOrCreateTypeInstance ( context ) ; } public getInstantiator ( context ) { let def ; try { def = this . resolveDefinition ( context ) ; } catch ( err ) { } return def ? def . buildInstantiator ( context ) : defaultInputFieldInstantiator ; } protected resolveDefinition ( context ) { const def = context . storage . getDefinition ( Definition , this . typeArg , context . kind ) ; if ( ! def ) { throw new Error ( `Cannot resolve type: ${ this . typeArg }` ) ; } return def ; } }