graphql-compose-mongoose
graphql-compose-mongoose copied to clipboard
AddFilterArg - not working
schemaComposer.rootQuery().addFields({
entityMany: EntityTC.mongooseResolvers.findMany().addFilterArg({
name: 'test',
type: 'String',
description: 'Test',
query: (query, value, resolveParams) => {
query.name = new RegExp(value, 'i');
},
});
});
When I try to use this approach to adding a filter to a resolver, it doesn't throw an error. I can confirm that the filter arg is added to the resolver. But the new filter arg is not added to the schema. Is there a better way to do this?
What is the correct approach to add a filter arg to an existing resolver?
Other clues/facts:
- I'm using the most recent versions of all graphql-compose packages.
- I discovered that addFilterArg adds the field 'test' to the filter arg when I inspect it. If I subsequently take that resolver and
.clone({name: 'sample' })
the field is not in the cloned resolver. And, similarly, the field is not added to the schema.
I know this is open source. And the library is really useful. And, I appreciate your efforts.
But, any ideas on the above issue?
- I discovered that addFilterArg adds the field 'test' to the filter arg when I inspect it.
@kstott
How did you inspect it? Did you use EntityTC.mongooseResolvers.findMany().getArgs()
anywhere in your code? This might be related to the bug causing my issue #288
I used a debugger. If I break before I build the schema, the field name is shown in the filter args through the debugger. But it still is not created in the schema.
@kstott I've just added a test case for your issue and there is no problem:
https://github.com/graphql-compose/graphql-compose-mongoose/blob/master/src/tests/github_issues/289-test.ts#L57
In the test case, you may see generated SDL and in the screenshot below you may see runtime execution with proper mongoose query:

Also, I provide some explanation to @Thammada issue about new behavior added to resolvers factory https://github.com/graphql-compose/graphql-compose-mongoose/issues/288#issuecomment-731782722
@kstott can you try to add some additional cases or modify 289-test.ts
in such a way that it breaks tests.
Thanks. There were some small differences. I was getting schemaComposer from the import statement. You imported the class, created a new instance, and added to the options. It seemed to work after I did that. Thanks, never would have figured that out.
had same issue . and then created the new instance from SchemaComposer. it added the arg to the schema correctly , but the query function never invoke. can u please help?
Update: got same issue with #228 . it was reset .