-
Notifications
You must be signed in to change notification settings - Fork 420
Description
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
The @ResolveReference decorator doesn't pass the request that was set in the context in the GraphQlGatewayModule like described in the shared context documentation under federation chapter.
Also when adding an @Context() as a parameter in the method of the resolver where @ResolveReference is the decorator, the parameter reference: reference: { __typename: string; id: string } becomes undefined.
Expected behavior
We expect to receive the context that we set when following the documentation of the shared context in the Federation - NestJS GraphQL chapter.
Context to include the request object which has the custom headers that were set by the gateway and the reference to not become undefined.
Minimal reproduction of the problem with instructions
So the context is defined but it is not the one that was set by the gateway module.
We set it as described in the shared context chapter of Federation documentation with the
context: ({ req }) => ({ req })
class AuthenticatedDataSource extends RemoteGraphQLDataSource {
willSendRequest({ request, context }) {
request.http.headers.set('x-custom-id', 'custom_id');
}
}
@ResolveReference()
async resolveReference(reference: { __typename: string; id: string }, @Context() ctx): Promise<Post> {
console.log(ctx.req); // undefined
console.log(reference); // undefined
return await this.repository.getById(ctx.req.headers['x-custom-info'], reference.id));
}I already tried setting the repository provider scope to Scope.REQUEST, but that didn't fix the problem
What is the motivation / use case for changing the behavior?
Consistency with the other methods to pass the complete context
Environment
Nest version: 7.1.0
For Tooling issues:
- Node version: 12
- Platform: Mac
Others: