【问题标题】:Req and Res parameters not being received on passport app.use() callback在护照 app.use() 回调中未收到 Req 和 Res 参数
【发布时间】:2020-01-14 17:32:10
【问题描述】:

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

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

路由通过护照进行验证,然后调用我的 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 代码?

【问题讨论】:

    标签: javascript node.js express graphql passport.js


    【解决方案1】:

    你正在立即执行appGraphQL

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

    【讨论】:

    • 确实它正在执行,但它需要为了处理我的 GraphQL 请求。我试过appGraphQL(req, res)也没有成功...
    • 我忘了用arrow function包装
    猜你喜欢
    • 1970-01-01
    • 2018-04-20
    • 2014-03-18
    • 2018-01-28
    • 1970-01-01
    • 2011-06-09
    • 2015-04-29
    • 2016-12-24
    • 1970-01-01
    相关资源
    最近更新 更多