【发布时间】:2020-12-24 17:07:10
【问题描述】:
请不要将此问题标记为“重复”。我在其他地方发现了类似的问题,但找不到任何合适的解决方案。
当我在 Nestjs 应用程序配置中的 GraphQLModule 中使用 context 时,我从未找到 req。当我安慰这个req 时,它是未定义的。在这个问题上花费了很多时间,但有条不紊。
/src/app.module.ts
@Module({
imports: [
ProductModule,
GraphQLModule.forRoot({
debug: true,
typePaths: ["./**/*.gql"],
definitions: {
path: join(process.cwd(), "src/schemas/graphql.d.ts"),
},
installSubscriptionHandlers: true,
context: ({ req }) => {
console.log(req); <======================== undefined !!!!
return {req}
},
}),
MongooseModule.forRoot(MONGO_URI),
AuthModule,
UsersModule,
],
controllers: [AppController],
providers: [AppService],
})
【问题讨论】:
-
这里可能有一些提示:github.com/nestjs/graphql/issues/48
-
你是用express还是fastify作为底层http引擎?
标签: graphql nestjs nestjs-config graphql-config