无法读取未定义的属性"授权"



请不要将此问题标记为"重复"。我在其他地方也发现了类似的问题,但找不到合适的解决方案。

当我在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],
})

最终,在更新Nest和Graphql包后,问题自动解决。

我想知道!

这表明有时包本身可能存在任何错误。