import { QueryReducer } from '../execution/QueryReducer' ; import { GraphQLDirectiveValue } from '../type/directives' ; import { GraphQLExtResolveInfo , } from '../execution/GraphQLExtResolveInfo' ; import { GraphQLFieldExt , } from '../type/object' ; export default class DirectiveCollector < ReducedDirective > implements QueryReducer < Array < ReducedDirective > , Object > { public initial : Array < ReducedDirective > ; constructor ( private handleDirective , private reduceContext ) { this . initial = [ ] ; } public reduceField ( parent , child , _ctx , info ) { const reduced = ( info . field as GraphQLFieldExt < mixed , mixed > ) . directives . map ( directive => this . handleDirective ( directive ) ) ; return [ ... parent , ... reduced , ... child ] ; } public reduceScalar ( ) { return [ ] ; } public reduceEnum ( ) { return [ ] ; } public reduceCtx ( acc , ctx ) { return this . reduceContext ( acc , ctx ) ; } }