import { GraphQLFieldResolver } from 'graphql' ; export type ComposableResolver < TSource , TOutput > = ( fn : GraphQLFieldResolver < TSource , TOutput > ) => GraphQLFieldResolver < TSource , TOutput > ; export function compose < TSource , TOutput > ( ... funcs ) { if ( funcs . length === 0 ) { return o => o ; } if ( funcs . length === 1 ) { return funcs [ 0 ] ; } const last = funcs [ funcs . length - 1 ] ; return ( f ) => { let result = last ( f ) ; for ( let index = funcs . length - 2 ; index >= 0 ; index -- ) { const fn = funcs [ index ] ; result = fn ( result ) ; } return result ; } ; } export function CompositeResolver < TSource , TOutput > ( ... funcs ) { return compose ( ... funcs ) ; }