护照 app.use() 回调中未收到 Req 和 Res 参数

Req and Res parameters not being received on passport app.use() callback

我正在我的 express 中间件上构建以下路由:

app.use(
    "/graphql",
    passport.authenticate("jwt", { session: false }),
    appGraphQL()
);

路由通过 passport 进行验证,然后调用我的 GraphQL 服务器。

我的 GraphQL 服务器入口代码是:

export default (req, res) => {
    console.log("RECEIVED PARAMETERS:")
    console.log(req)
    console.log(res)

    return graphqlHTTP({
        schema: schema,
        graphiql: true,
        pretty: true,
        context: {
            resolvers: null, // Will add my resolvers here
            req: req,
            res: res
        },
        formatError: error => ({
            message: error.message,
            locations: error.locations,
            stack: error.stack,
            path: error.path
        })
    });
};

我得到的 reqres 参数为 null。

如何正确地将 reqres 发送到我的 GraphQL 代码?

您正在立即执行appGraphQL

app.use(
    "/graphql",
    passport.authenticate("jwt", { session: false }),
    (req,res) => appGraphQL(req,res)
);