@envelop/graphql-middleware
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

@envelop/graphql-middleware

This plugins wraps graphql-middleware and allow you to apply schema middlewares that uses the standard defined by graphql-middleware.

You can find an awesome list of middlewares here

Getting Started

yarn add graphql-middleware @envelop/graphql-middleware

Usage Example

You can use any type of middleware defined for graphql-middleware, here's an example for doing that with graphql-shield:

import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { and, not, or, rule, shield } from 'graphql-shield'
import { envelop, useEngine } from '@envelop/core'
import { useGraphQLMiddleware } from '@envelop/graphql-middleware'

// ...
// You can find a complete example here: https://github.com/maticzav/graphql-shield#graphql-yoga
// ...

const permissions = shield({
  Query: {
    fruits: and(isAuthenticated, or(isAdmin, isEditor))
  },
  Mutation: {
    addFruitToBasket: isAuthenticated
  },
  Fruit: isAuthenticated,
  Customer: isAdmin
})

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    // ... other plugins ...
    useSchema(mySchema),
    useGraphQLMiddleware([permissions])
  ]
})

Readme

Keywords

none

Package Sidebar

Install

npm i @envelop/graphql-middleware

Weekly Downloads

3,242

Version

6.0.0

License

MIT

Unpacked Size

6.29 kB

Total Files

8

Last publish

Collaborators

  • dotansimha