6.0.0 • Published 7 months ago

@envelop/operation-field-permissions v6.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@envelop/operation-field-permissions

Disallow executing operations that select certain fields. Useful if you want to restrict the scope of certain public API users to a subset of the public GraphQL schema, without triggering execution (e.g. how graphql-shield works).

Note: This plugin and authorization on a resolver level (or via middleware) are complementary. You should still verify whether a viewer is allowed to access certain data within your resolvers.

Installation

yarn add @envelop/operation-field-permissions

Usage Example

import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine, useSchema } from '@envelop/core'
import { useOperationFieldPermissions } from '@envelop/operation-field-permissions'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    useSchema(schema),
    useOperationFieldPermissions({
      // we can access graphql context here
      getPermissions: async context => new Set(['Query.greetings', ...context.viewer.permissions])
    })
    /* ... other envelops */
  ]
})

Schema

type Query {
  greetings: [String!]!
  foo: String
}

Operation

query {
  foo
}

Response

{
  "data": null,
  "errors": [
    {
      "message": "Insufficient permissions for selecting 'Query.foo'.",
      "locations": [
        {
          "line": 2,
          "column": 2
        }
      ]
    }
  ]
}
5.0.3

8 months ago

5.0.2

8 months ago

5.0.1

9 months ago

6.0.0

7 months ago

4.0.5

1 year ago

4.0.6

1 year ago

5.0.0

12 months ago

4.0.4

1 year ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.6.0

2 years ago

3.5.0

2 years ago

3.4.0

2 years ago

3.4.2

2 years ago

3.4.1

2 years ago

3.3.4

2 years ago

3.3.3

2 years ago

3.3.2

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.1

2 years ago

2.0.0

2 years ago

3.0.0

2 years ago

3.1.0

2 years ago

1.2.0

3 years ago

1.2.3

2 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago