context: ExecutionContext and GqlExecutionContext gives undefined req
req should give FastifyRequest object, similar to what Express Request provides.
canActivate(context: ExecutionContext), you can inspect the context, but req is undefinedGqlExecutionContext.create(context).getContext() which still gives undefined reqAdditionally: there are FastifyDeprecation notices, see below:
(node:39933) [FSTDEP003] FastifyDeprecation: You are using the legacy Content Type Parser function signature. Use the one suggested in the documentation instead.
(node:39933) [FSTDEP001] FastifyDeprecation: You are accessing the Node.js core request object via "request.req", Use "request.raw" instead.
context= ExecutionContextHost {
args: [
undefined,
{
where: [Object: null prototype],
limit: 20,
start: 0,
sort: 'createdAt:desc'
},
{ req: undefined, _extensionStack: [GraphQLExtensionStack] },
{
fieldName: 'users',
fieldNodes: [Array],
returnType: [User!]!,
parentType: Query,
path: [Object],
schema: [GraphQLSchema],
fragments: [Object: null prototype] {},
rootValue: undefined,
operation: [Object],
variableValues: [Object],
cacheControl: [Object]
}
],
constructorRef: [class UsersResolver],
handler: [AsyncFunction: users],
contextType: 'graphql'
}
gqlCtx= {
req: undefined,
_extensionStack: GraphQLExtensionStack { extensions: [] }
}
Fix bug.
Nest version:
- @nestjs/[email protected]
- @nestjs/[email protected]
- apollo-server-fastify 2.18.2
- [email protected], also happens with 3.7.0 and 3.0.3
For Tooling issues:
- Node version: v12.19.0
- Platform: Ubuntu 20.04.1
Others:
- Always reproducible as long as using fastify
Would you like to create a PR for this issue?
@kamilmysliwiec I hope so, but I need some pointer on what function/file I should fix?
@ceefour
Not sure you got same my problem, I'm also using the apollo-server-fastify, And look like the data now store at request instead of req
My GqlAuthGuard
import { Injectable, ExecutionContext } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport'
import { GqlExecutionContext } from '@nestjs/graphql'
@Injectable()
export class GqlAuthGuard extends AuthGuard('jwt') {
getRequest(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context)
return ctx.getContext().req
}
}
@phattranky I'm not sure too. As you can see from my log, req is undefined while request doesn't exist at all.
This should be fixed in 7.8.1
I am having this same issue with the latest version 7.10.6 of @nestjs/graphql. req and request are both undefined. I am using express with nestjs.
You can see my code at the link below.
Context is an empty object {}.
@clayrisser
Hello. You really shouldn't post in Github like this. Because.....
Thanks for your understanding!
Scott