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
@@ -123,6 +122,94 @@ type Post @authorization(validate: [
123
122
In case there is no `operations` argument with a list of operations, the GraphQL Library treats the authorization configuration as if the full list of operations had been provided.
124
123
====
125
124
125
+
=== When
126
+
127
+
Validation can be configured to only be performed before or after an operation is executed.
128
+
This is done using the `when` argument which accepts an array of the following values:
129
+
130
+
* `BEFORE`
131
+
* `AFTER`
132
+
133
+
Additionally, some operations only support validation either before or after them, which is summarised in this table:
134
+
135
+
[cols="2,5"]
136
+
|===
137
+
| `operation` | `when`
138
+
139
+
| `READ`
140
+
| `BEFORE`
141
+
142
+
| `AGGREGATE`
143
+
| `BEFORE`
144
+
145
+
| `CREATE`
146
+
| `AFTER`
147
+
148
+
| `UPDATE`
149
+
| `BEFORE`, `AFTER`
150
+
151
+
| `DELETE`
152
+
| `BEFORE`
153
+
154
+
| `CREATE_RELATIONSHIP`
155
+
| `BEFORE`, `AFTER`
156
+
157
+
| `DELETE_RELATIONSHIP`
158
+
| `BEFORE`, `AFTER`
159
+
160
+
|===
161
+
162
+
As a brief example, if you wanted anybody to be able to attempt to update any post, but wanted to check that after the update, the author it is connected to is still the current user, you could do the following:
The `@authorization` directive can be used either on either object types or their fields, with the former being used in examples for the most part on this page. When applied to a field, the authorization rules are only evaluated if the matching operations are performed on that field. For example, consider a `User` type with a `password` field:
When executing the following query, a valid identity is not needed:
189
+
190
+
[source, graphql, indent=0]
191
+
----
192
+
{
193
+
users {
194
+
username
195
+
}
196
+
}
197
+
----
198
+
199
+
However, consider the following query:
200
+
201
+
[source, graphql, indent=0]
202
+
----
203
+
{
204
+
users {
205
+
username
206
+
password
207
+
}
208
+
}
209
+
----
210
+
211
+
This will require a valid JWT to have been provided with the request, and the matching users will be filtered down according to the JWT subject. The same will apply for attempting to update the `password` field, the update will only apply to the user matching the JWT.
212
+
126
213
127
214
== Authorization without authentication
128
215
@@ -147,3 +234,34 @@ type Post @authorization(filter: [
In each ruleset (`filter` and `validate`), rules are joined with an `OR`. The two rulesets are joined with an `AND`.
241
+
242
+
An example pseudo-logic would be `(filterRule1 OR filterRule2) AND (validateRule1 OR validateRule2)`.
243
+
244
+
If ever there are two rules which you would like to be combined with an `AND`, these should be combined into a single rule. Take for instance the following example:
Say in this example we wanted it to be that a user needs to be an admin _and_ the `locked` property must be `false` in order to update a `User` node. We would need to combine these predicates into a single rule:
0 commit comments