简体   繁体   English

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

[英]express-graphql : context is always undefined

I have a simple implementation of graphQl on my api, but can't seem to get any other arguments than args from the resolvers.我在我的 api 上有一个简单的 graphQl 实现,但似乎无法从解析器中获得任何其他 arguments 参数。 The code is pretty simple, so it shouldn't cause any issue:代码非常简单,所以它不应该引起任何问题:

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

and then my resolver:然后是我的解析器:

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

Args are accessible normally, but context and test are both undefined.参数可以正常访问,但上下文和测试都是未定义的。 Any clue?有什么线索吗?

My bad, i actually englobed resolvers in a function to handle error, and didn't pass the context through totally.我的错,我实际上在 function 中加入了解析器来处理错误,并且没有完全传递上下文。 Solved解决了

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

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