Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hagabaka opened this issue Nov 9, 2022 · 2 comments

Comments

@hagabaka
Copy link

hagabaka commented Nov 9, 2022

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.

@ZachFontenot
Copy link

ZachFontenot commented Mar 9, 2023

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?

@hagabaka
Copy link
Author

hagabaka commented Mar 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants