⨠ GraphQL resolver middleware composer
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.
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.
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) => { ... })
)
}
}