New Prog Mixtape

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

    4.0.4 • 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 { parse, validate, specifiedRules, execute, subscribe } from 'graphql'
    import { envelop, useEngine } from '@envelop/core'
    import { useGraphQLMiddleware } from '@envelop/graphql-middleware'
    import { rule, shield, and, or, not } from 'graphql-shield'
    
    // ...
    // 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])
      ]
    })

    Keywords

    none

    Install

    npm i @envelop/graphql-middleware

    DownloadsWeekly Downloads

    1,725

    Version

    4.0.4

    License

    MIT

    Unpacked Size

    5.17 kB

    Total Files

    7

    Last publish

    Collaborators

    • dotansimha