graphql-compose-mongoose DiscriminatorTypeComposer with mongooseResolvers – Stack Overflow

I’m trying to define a DiscriminatorTypeComposer using composeWithMongooseDiscriminators, but I’ve run into an issue. Unlike the ObjectTypeComposerWithMongooseResolvers returned by composeMongoose, the DiscriminatorTypeComposer doesn’t have the mongooseResolvers property. I’m currently using composeMongoose and need to establish a relation between two models in my GraphQL schema.

Here’s how I currently define the relation using dataLoaderMany with Model1 and Model2:

Model1.addRelation('model2', {
  resolver: () => Model2TC.mongooseResolvers.dataLoaderMany({ lean: true }),
  prepareArgs: { _ids: (source) => source.model2 },
  projection: { model2: 1 },
});

However, I am facing issues implementing a similar relation using the DiscriminatorTypeComposer. I attempted to use the getResolver method, but I couldn’t find a way to set the lean flag to true.

Can anyone provide a solution or point me in the right direction to achieve this with the DiscriminatorTypeComposer?

Read more here: Source link