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

AddFilterArg - not working

Open kstott opened this issue 4 years ago • 6 comments

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.

kstott avatar Nov 17 '20 14:11 kstott

I know this is open source. And the library is really useful. And, I appreciate your efforts.

But, any ideas on the above issue?

kstott avatar Nov 21 '20 11:11 kstott

  • 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

Thammada avatar Nov 21 '20 20:11 Thammada

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 avatar Nov 21 '20 21:11 kstott

@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:

Screen Shot 2020-11-23 at 00 04 39

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.

nodkz avatar Nov 22 '20 18:11 nodkz

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.

kstott avatar Nov 22 '20 23:11 kstott

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 .

rojectsky avatar Jun 12 '21 11:06 rojectsky