Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Expose Express middleware function #3

Open
kbrandwijk opened this issue Jul 23, 2017 · 0 comments
Open

FR: Expose Express middleware function #3

kbrandwijk opened this issue Jul 23, 2017 · 0 comments

Comments

@kbrandwijk
Copy link

Many usecases for graphcool-lib use the library in an Express webtask. It would be nice if the library could expose an Express middleware function (like bodyParser.json()) to easily use it in Express. I now use this middleware function to make the api available directly from the req object:

app.use((req, res, next) => {
  if (req.body.context.graphcool) {
    req.api = fromEvent(req.body).api('simple/v1')
  };
  next()
})

With the function exposed from graphcool-lib, this can become:

app.use(graphcool.initApi())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant