graphql-resolver-middleware
v0.0.1
Published
GraphQL resolvers middleware composer
Downloads
3
Maintainers
Readme
GraphQL Resolver Middleware
⨠ GraphQL resolver middleware composer
What does it do?
Adding all the functionality needed for individual resolvers can end up in a lot of boilerplate code and messy resolver functions. graphql-resolver-middleware
solves this problem by allowing you to compose middleware for each resolver, allowing you to create complex workflows around your data in a clean manner.
Some common problems you can solve with resolver middleware are authentication, authorization, logging, timing, analytics gathering, extending context, etc.
Check out the launchpad examples below!
How does it do it?
graphql-resolver-middleware
exports a single function that takes N number of middleware and applies them serially to the resolver parameters, allowing you to either error out if certain conditions are not met or extend functionality by extending/mutating the context property.
compose()
import auth from 'graphql-auth';
import log from 'graphql-log';
import statsd from 'graphql-statsd';
const middleware = compose(statsd, log);
const resolvers = {
Query: {
hello: middleware(
// accepts any function that meets resolver API
auth(['view:hello'], (parent, args, context) => { ... })
)
}
}