naver/graphql-dataloader-mongoose

MongooseDataloaderFactory is not defined

GimignanoF opened this issue · 2 comments

I imported the library where my GraphQL resolvers are, but when i try to execute the query using the dataloader i get the error in the title. The library is imported like this
const DataLoader = require("graphql-dataloader-mongoose"); const dataloaderFactory = new MongooseDataloaderFactory();

and I try to use it like this
dataloaderFactory.mongooseLoader(ProductModel).dataloader("_id");
where ProductModel is a mongoose model previously defined. Am I missing something or is the package not working?

@GimignanoF
If you change your code like below, it will be working

const { MongooseDataloaderFactory } = require("graphql-dataloader-mongoose");
const dataloaderFactory = new MongooseDataloaderFactory();

const productDataloder = dataloaderFactory
    .mongooseLoader(ProductModel)
    .dataloader('_id');

const result = await productDataloder.load(someId);

Thank you, in the end I figured it out by myself that this was the working solution 😅