Skip to content

kkemple/graphql-resolver-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Resolver Middleware

⨠ GraphQL resolver middleware composer

Build Status codecov styled with prettier NPM version

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.

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) => { ... })
    )
  }
}

About

⨠ GraphQL resolver middleware composer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages