繁体   English   中英

express-graphql:上下文始终未定义

[英]express-graphql : context is always undefined

我在我的 api 上有一个简单的 graphQl 实现,但似乎无法从解析器中获得任何其他 arguments 参数。 代码非常简单,所以它不应该引起任何问题:

const bindGraphqlModule = (app) => {
  app.use(
    "/graphql",
    graphqlHTTP(() => {
      return {
        schema: graphQLSchema,
        rootValue: resolvers,
        context: {
          test: "hi ?"
        },
        graphiql: process.env.NODE_ENV !== "production",
      };
    })
  );
};

然后是我的解析器:

const resolver = async (args, context, test) => {
  console.log(context, test);
  const { email, password } = args;
  ...

参数可以正常访问,但上下文和测试都是未定义的。 有什么线索吗?

我的错,我实际上在 function 中加入了解析器来处理错误,并且没有完全传递上下文。 解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM