簡體   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