graphql-compose-mongoose icon indicating copy to clipboard operation
graphql-compose-mongoose copied to clipboard

If a TC's findMany resolver is added to schema multiple times, filter options for subsequent resolvers are ignored

Open hagabaka opened this issue 3 years ago • 2 comments

When you use a TC's findMany resolver multiple times in schema, for example, first to add a relation, then to add a findMany query, and then to add a pagination query:

X.addRelation('y', {
  resolver: X.mongooseResolvers.findMany({filter: filterOptions1})
}),
schemaComposer.Query.addFields({
  xFindMany: X.mongooseResolvers.findMany({filter: filterOptions2}),
  xPaginate: X.mongooseResolvers.paginate({
   findManyOpts: {filter: filteroptions3}
  })
});

Then xFindMany and xPaginate queries will use filterOptions1, but not filterOptions2 or filterOptions3.

It seems that by default the generated filter input type for all the findMany resolvers of the same model share the same name, so the type is created for the first findMany, and reused for all other ones. If this default behavior can't be changed, it would be nice to at least have a run time warning and/or FAQ entry in documentation about the limitation.

hagabaka avatar Nov 09 '22 23:11 hagabaka

I also ran into this issue and I thought I was going crazy because passing the options was doing nothing, but now I see why this is happening.

And actually, I can't track down which is running first, so I'm unable to add any options at all?

ZachFontenot avatar Mar 09 '23 16:03 ZachFontenot

I think a workaround is using baseTypeName, prefix, and/or suffix options of FilterHelperArgsOpts to have different type names for different usages of findMany. https://github.com/graphql-compose/graphql-compose-mongoose#filterhelperargsopts

hagabaka avatar Mar 09 '23 22:03 hagabaka