prisma-archive / graphcool-lib

A convenient tool to use in Graphcool functions to make requests against your Graphcool API
33 stars 6 forks source link

FR: Expose Express middleware function #3

Open kbrandwijk opened 7 years ago

kbrandwijk commented 7 years ago

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())