I have a query for getting projects from the DB which has args as shown below for filtering projects. How would I use the same args in the @resolveField for filtering form values of the project
@Query(() => [Project])
async getProjects(@Args() projectArgs: ProjectArgs) {
return await this.projectsService.find(projectArgs);
}
@ResolveField("formValues", () => [FormValues])
async getFormValues(@Parent() project: Project) {
const { id } = project;
return await this.formsService.findValues({ projectId: id});
}
I have faced this problem before and through thorough searching, I have come to the conclusion that the best and scalable way of doing this is to define the args for the field resolver itself. Here is how you do it
@ResolveField("formValues", () => [FormValues])
async getFormValues(@Args() projectArgs: ProjectArgs) {
..../////
}
This way you will have to pass the args just as you pass it in the parent query. Or you could leave them out if you don't want to filter the form values
There are other approaches that you can use. One of them is by setting the info as
@Query(() => [Project])
async getProjects(@Args() projectArgs: ProjectArgs, @Info() info) {
info.variableValues.some_key = value
return await this.projectsService.find(projectArgs);
}
But this won't scale and make it very tightly coupled