[ ] Regression
[x] Bug report
[x] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
When interceptor is applied to a GraphQL resolver class, it is correctly applied to all it's methods. However, if we take the logging interceptor example from the docs (https://docs.nestjs.com/interceptors), we will soon find out that once we ask our GraphQL server for something like this
query {
comments {
id
text
author {
id
name
}
}
}
the interceptor is actually called multiple times for each comment's author as the author is a (most likely) @PropertyResolver method on the @Resolver class, which is correctly called for each comment. This makes the logger log "Before" and "After" multiple times in parallel for a single request and then it's impossible to use the interceptor as required.
We should have a way to bind custom execution logic to before and after GraphQL request.
Or at least document how to do this. I was thinking of using a regular controller with a @Post route method on which an interceptor would be used and would work as an entry point to the GraphQL module, but I don't understand how to do this while using the GraphQLModule (not to mention how it works with subscriptions). Any suggestions?
The interceptor lose some of their usefulness when used on GraphQL resolvers. One example is if we had a transactional request-scoped database connection provider and wanted to commit the transaction after each GraphQL mutation. If the mutation returns data in any format similar to what's described above, the interceptor would try to commit the transaction multiple times.
Nest version: 6.1.1
It should be fixed in the @next version ($ npm i @nestjs/graphql@next). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/[email protected])
Published as 6.2.0 ($ npm i @nestjs/graphql@latest). You will also have to update @nestjs/core to 6.2.0 ($ npm i @nestjs/core@latest)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
It should be fixed in the @next version (
$ npm i @nestjs/graphql@next). You will also have to update@nestjs/coreto 6.2.0 ($ npm i @nestjs/[email protected])