lucasconstantino / graphql-resolvers

:electric_plug: Resolver composition library for GraphQL.
MIT License
282 stars 16 forks source link

combineResolvers always throws "cannot read property 'apply' of undefined" #39

Open vpaul18 opened 3 years ago

vpaul18 commented 3 years ago

I am trying to attach the following guard:

export const isSupplier=(_,__,{me})=>{

  me.role==="supplier" ? skip : new ForbiddenError('Not authenticated as supplier.');
}

To a resolver, like this:

addProductNow:combineResolvers(
            isSupplier,
            async (_,{name,price,description,url,stock},{dataSources,me})=>{

            const supplierId=me.id
            console.log(supplierId)
            const supplier=await dataSources.SupplierAPI.findSupplierById(supplierId)

            const newProduct=await dataSources.ProductAPI.addProduct(name,price,description,url,stock,supplierId,{ttlInSeconds:60*20})
            return newProduct
        }),

Yet it always returns the error "cannot read property 'apply' of undefined". I have tried to log something in the guard , yet it seems like it never gets executed. After removing the guard from the resolver everything works fine and logging 'me' shows the expected value. Am I doing something wrong ? Thanks !