Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Using prepare and extraContext is confusing #91

Open
wujashek opened this issue Mar 27, 2018 · 0 comments
Open

Using prepare and extraContext is confusing #91

wujashek opened this issue Mar 27, 2018 · 0 comments

Comments

@wujashek
Copy link

Thanks for a great library !

While checking how to extract schema from gramps I've found great example here: https://gramps.js.org/api/gramps/

I had an issue with this part, seems context doesn't get a request object in such setup:

app.use('/graphql',
  bodyParser.json(),
  gramps.addContext,         // Add the extra context
  graphqlExpress({
    schema,                  // Use the merged schema...
    context: gramps.context, // ...and the GrAMPS context object
  }),
);

So I had to rewrite it to:

app.use('/graphql',
  bodyParser.json(),
  gramps.addContext,         // Add the extra context
  graphqlExpress(req => ({
    schema,                  // Use the merged schema...
    context: gramps.context(req), // ...and the GrAMPS context object
  })),
);

Also I've noticed extraContext callback is called twice for a single query.

addContext: (req, res, next) => {
      req.gramps = getContext(req);
      next();
    }

Maybe the idea is to pass req.gramps to apollo express middleware as config object ?

It would be great to see some clarification on above so I can work on PR to improve that ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant