简体   繁体   中英

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. 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. Solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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