Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interceptor doesn't get all resolved properties #320

Closed
jogelin opened this issue Jul 4, 2019 · 3 comments
Closed

Interceptor doesn't get all resolved properties #320

jogelin opened this issue Jul 4, 2019 · 3 comments

Comments

@jogelin
Copy link

jogelin commented Jul 4, 2019

I'm submitting a...


[ ] Regression 
[X] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I would like to be able to get resolved data. To put a post script when data are resolved.

To do so, I tried use an interceptor on resolvers to get data that resolvers are sending back. But the interceptor only get data returned by the query method and not all data resolved by other @ResolveProperty methods...

Expected behavior

I would like to receive the real data returned to the client and not only the data returned by the Query.

Minimal reproduction of the problem with instructions

@Resolver(type => Entity)
@UseInterceptors(EntityInterceptor)
export class EntityResolver {

  @Query(returns => [Entity])
  stationPlanList(): Observable<Plan[]> {
    return of([generateEntity()]);
  }

  @ResolveProperty()
  field(@Parent() entity: Entity): string {
    return 'blabla';
  }
}
export interface Response<T> {
  data: T;
}

@Injectable()
export class StationPlanInterceptor<T> implements NestInterceptor<T, Response<T>> {
  intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>> {
    return next.handle().pipe( tap(data => {
       console.log(data); --> the property field is not present !!
    }));
  }
}

What is the motivation / use case for changing the behavior?

Be able to make an action after the resolvers are finishing there job !

Environment


    "@nestjs/common": "6.2.4",
    "@nestjs/core": "6.2.4",
    "@nestjs/graphql": "6.2.4",

Maybe related to: #295
Could be solved by: #263

@kamilmysliwiec
Copy link
Member

Unfortunately, this is something that we cannot change at the @nestjs/graphql level. Our GraphQLModule is just a thin wrapper around the ApolloServer that creates a resolver map using reflection and decorators, providing composed context functions (instead of just "raw bindings" to method references) that allow you taking advantage of NestJS features (such as guards, interceptors etc). However, property resolvers are called apart from query methods and thus, we can't access the final response value (after aggregating all nested property resolver values) Even though this could be useful, it's entirely impossible with the existing implementation (and the primary idea of the package).

@michaelbromley
Copy link

@jogelin I had a similar requirement - I have to perform a transformation on the final result before it is returned to the client. The way I did it is by using the Apollo Server GraphQLExtension system.

However, this is being deprecated in favour of the new Apollo Server plugin system introduced in v2.2. It is currently undocumented, but you can see an open docs PR here, which gives you the idea of how to use it: apollographql/apollo-server#2008

Hope that helps!

@lock
Copy link

lock bot commented Apr 25, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants