import { GraphQLDirective , DirectiveLocationEnum , ObjectTypeDefinitionNode , FieldDefinitionNode , SchemaDefinitionNode , InterfaceTypeDefinitionNode , EnumTypeDefinitionNode , UnionTypeDefinitionNode , DirectiveLocation , } from 'graphql' ; function assertValidLocation ( directive , term ) { for ( let s of directive . locations ) { if ( s === term ) { return true ; } } throw new Error ( `Invalid directive location: @${ directive . name } found on definition of kind ` + `'${ term }'. Expecting [ ${ directive . locations . join ( ', ' ) } ].` ) ; } export function locationForDirectiveDefinition ( directive , def ) { switch ( def . kind ) { case 'ObjectTypeDefinition' : assertValidLocation ( directive , DirectiveLocation . OBJECT ) ; return DirectiveLocation . OBJECT ; case 'FieldDefinition' : assertValidLocation ( directive , DirectiveLocation . FIELD_DEFINITION ) ; return DirectiveLocation . FIELD_DEFINITION ; case 'SchemaDefinition' : assertValidLocation ( directive , DirectiveLocation . SCHEMA ) ; return DirectiveLocation . SCHEMA ; case 'InterfaceTypeDefinition' : assertValidLocation ( directive , DirectiveLocation . INTERFACE ) ; return DirectiveLocation . INTERFACE ; case 'EnumTypeDefinition' : assertValidLocation ( directive , DirectiveLocation . ENUM ) ; return DirectiveLocation . ENUM ; case 'UnionTypeDefinition' : assertValidLocation ( directive , DirectiveLocation . UNION ) ; return DirectiveLocation . UNION ; default : throw new Error ( 'Invalid definition for directive.' ) ; } }