Closed YannisSerli closed 1 year ago
Hey! I'll take a look.
@YannisSerli can you give more information please. I want to know typeorm and graphql versions. Also attach some code snippet.
The typeorm and graphql versions:
"@nestjs/typeorm": "^9.0.1"
"@nestjs/graphql": "^10.1.7"
A code snippet that doesn't work:
/**
* Find all persons
* @returns all persons
*/
@Query(() => [Person], { name: 'persons' })
@UseGuards(GqlAuthGuard, CoachResearcherGuard)
@GraphqlFilter()
@GraphqlSorting()
async findAll(
@Filter(() => Person) filter: Brackets,
@Sorting(() => Person) sorting: SortArgs<Person>,
@Paginator() paginator,
): Promise<Person[]> {
const query = repository.createQueryBuilder();
query.where(filter);
query.orderBy(sorting);
query.offset(paginator.page * paginator.per_page).limit(paginator.per_page);
return query.getMany();
}
@YannisSerli Can you please look at src/entities/user/user.resolver. There's no guards here. Probably UseGuards overrides all the rest guards. Can you please try to move you UseGuards after @GraphqlSorting()?
Another thing what you can do is to change the logic in GqlAuthGuard and CoachResearcherGuard. You need to call action and spread all parameters to it. Also, make sure that you don't override initial method there, because in this case you will loose the context.
I moved UseGuards after @GraphqlSorting and even removed the UseGuards but the problem stay the same.
I think the problem comes from lib/filters/query.builder.ts
line 19: if (parameters && 'whereFactory' in parameters) return parameters;
Because using Brackets the if
condition became true but whereFactory
is undefined.
That's super strange and if you run example that inside of src folder it will work. You mentioned that having any type instead of bracket makes it works. At the same time types don't exist in the final bundle as it compiles to js. How it can break?
Closing due to inactivity.
I've had the same problem since I added validations to bootstrap:
app.useGlobalPipes(new ValidationPipe({ transform: true }));
@KyDenZ Oh, it looks like global pipes override results of controllers pipes. I'll take a look. For now, you can try to use pipes locally wrapping the methods in the controller. The first pipe should be yours, and after all the following decorators that comes fom the library.
I was able to reproduce the issue, working on it.
@KyDenZ @YannisSerli I hope it was fixed in the version 0.8.0 https://github.com/Adrinalin4ik/Nestjs-Graphql-Tools/releases/tag/0.8.0
In the release 0.7.17, when we follow the readme adding @Filter() parameter with type of
Brackets
from typeorm library, an error is throw:where.whereFactory is not a function
.Changing the type
Brackets
intoany
solve the problems.