You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-5Lines changed: 26 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Please see the related [issue](https://github.com/Sytten/nexus-shield/issues/50)
11
11
12
12
## Overview
13
13
14
-
Nexus Shield is a [nexus](https://github.com/graphql-nexus/nexus) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of it's familiar ruling system. It takes full advantage of the type safety provided by nexus.
14
+
Nexus Shield is a [nexus](https://github.com/graphql-nexus/nexus) plugin that helps you create an authorization layer for your application. It is a replacement for the provided authorization plugin. It is heavily inspired by [Graphql Shield](https://github.com/maticzav/graphql-shield) and reuses most of its familiar ruling system. It takes full advantage of the type safety provided by nexus.
15
15
16
16
## Install
17
17
@@ -50,9 +50,30 @@ const schema = makeSchema({
50
50
});
51
51
```
52
52
53
+
#### Subscriptions configuration
54
+
55
+
- When using subscriptions with a server that is not integrated directly into your "main" GraphQL server, you **must** make sure that you pass in a valid context.
56
+
- This context should contain all the information needed to evaluate the rules. Ideally, it is the same as the context for your "main" server otherwise the typing won't reflect the data available to the rules.
57
+
58
+
For example, using [GraphQL-WS](https://github.com/enisdenjo/graphql-ws):
59
+
60
+
```typescript
61
+
useServer(
62
+
{
63
+
schema,
64
+
context: (ctx, msg, args) => {
65
+
// That will return the same context that was passed when the
66
+
// server received the subscription request
67
+
returnctx;
68
+
},
69
+
},
70
+
wsServer
71
+
);
72
+
```
73
+
53
74
### Styles
54
75
55
-
Two interfaces styles are provided for convenience: `Graphql-Shield` and `Nexus`.
76
+
Two interface styles are provided for convenience: `Graphql-Shield` and `Nexus`.
However, if you specify it directly in the `shield` field, there is not need for an helper thus no need for a parameter.
258
+
However, if you specify it directly in the `shield` field, there is no need for a helper thus no need for a parameter.
238
259
239
260
```typescript
240
261
t.string('prop', {
@@ -244,7 +265,7 @@ t.string('prop', {
244
265
245
266
### Caching
246
267
247
-
- The result of a rule can be cached to maximize performances. This is important when using generic or partial rules that require access to external data.
268
+
- The result of a rule can be cached to maximize performance. This is important when using generic or partial rules that require access to external data.
248
269
- The caching is **always** scoped to the request
249
270
250
271
The plugin offers 3 levels of caching:
@@ -270,7 +291,7 @@ ruleType({
270
291
271
292
### Known issues / limitations
272
293
273
-
- Currently the typing of the `shield` parameter on `objectType` doesn't work. Tracked by issue: https://github.com/Sytten/nexus-shield/issues/50
294
+
- Currently, the typing of the `shield` parameter on `objectType` doesn't work. Tracked by issue: https://github.com/Sytten/nexus-shield/issues/50
274
295
275
296
- It is not possible to pass directly an `objectType` to the parameter `type` of a `ruleType`. Tracked by issue: https://github.com/graphql-nexus/schema/issues/451
0 commit comments