@envelop/graphql-middleware 3.4.0-alpha-26c4ae2.0 → 3.4.0-alpha-8a8cd36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
## `@envelop/graphql-middleware`
|
|
2
|
+
|
|
3
|
+
This plugins wraps [`graphql-middleware`](https://github.com/maticzav/graphql-middleware) and allow you to apply schema middlewares that uses the standard defined by `graphql-middleware`.
|
|
4
|
+
|
|
5
|
+
> You can find an awesome [list of middlewares here](https://github.com/maticzav/graphql-middleware#awesome-middlewares-)
|
|
6
|
+
|
|
7
|
+
## Getting Started
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
yarn add graphql-middleware @envelop/graphql-middleware
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage Example
|
|
14
|
+
|
|
15
|
+
You can use any type of middleware defined for `graphql-middleware`, here's an example for doing that with [`graphql-shield`](https://github.com/maticzav/graphql-shield):
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { envelop } from '@envelop/core';
|
|
19
|
+
import { useGraphQLMiddleware } from '@envelop/graphql-middleware';
|
|
20
|
+
import { rule, shield, and, or, not } from 'graphql-shield';
|
|
21
|
+
|
|
22
|
+
// ...
|
|
23
|
+
// You can find a complete example here: https://github.com/maticzav/graphql-shield#graphql-yoga
|
|
24
|
+
// ...
|
|
25
|
+
|
|
26
|
+
const permissions = shield({
|
|
27
|
+
Query: {
|
|
28
|
+
fruits: and(isAuthenticated, or(isAdmin, isEditor)),
|
|
29
|
+
},
|
|
30
|
+
Mutation: {
|
|
31
|
+
addFruitToBasket: isAuthenticated,
|
|
32
|
+
},
|
|
33
|
+
Fruit: isAuthenticated,
|
|
34
|
+
Customer: isAdmin,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const getEnveloped = envelop({
|
|
38
|
+
plugins: [
|
|
39
|
+
// ... other plugins ...
|
|
40
|
+
useSchema(mySchema),
|
|
41
|
+
useGraphQLMiddleware([permissions]),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
```
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/graphql-middleware",
|
|
3
|
-
"version": "3.4.0-alpha-
|
|
3
|
+
"version": "3.4.0-alpha-8a8cd36.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-8a8cd36.0",
|
|
7
7
|
"graphql-middleware": "^6.0.0",
|
|
8
8
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
9
9
|
},
|