Skip to content

Commit 5e4ee1d

Browse files
committed
docs: preauthorize_raise_exception and preauthorize_mutation_raise_exception
1 parent ebe90aa commit 5e4ee1d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/graphql.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ def homes
102102
end
103103
```
104104

105+
You can specify the default _raising_ behaviour for `preauthorize:` by setting a configuration option:
106+
107+
```ruby
108+
# By default, it fallbacks to .authorize_raise_exception
109+
ActionPolicy::GraphQL.preauthorize_raise_exception = false
110+
```
111+
105112
**NOTE:** we pass the field's name as the `record` to the policy rule. We assume that pre-authorization rules do not depend on
106113
the record itself and pass the field's name for debugging purposes only.
107114

@@ -159,6 +166,17 @@ end
159166

160167
Check out this issue on how you can implement a `verify_authorized` callback for your mutations: [#28](https://github.com/palkan/action_policy-graphql/issues/28).
161168

169+
### Using `preauthorize: *` with mutations
170+
171+
Since mutation is also a GraphQL field, we can also use our custom `authorize: *` and `preauthorize: *` options. Using `authorize: *` doesn't make any sense because it's called after the field has been resolved (i.e., mutation has been executed).
172+
173+
It is possible to override the default _raising_ behaviour for mutation only via the following configuration option:
174+
175+
```ruby
176+
# By default, it fallbacks to .preauthorize_raise_exception
177+
ActionPolicy::GraphQL.preauthorize_mutation_raise_exception = true
178+
```
179+
162180
## Handling exceptions
163181

164182
The query would fail with `ActionPolicy::Unauthorized` exception when using `authorize: true` (in raising mode) or calling `authorize!` explicitly.

0 commit comments

Comments
 (0)