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
1.`authenticate_default`: This is a boolean value which is `true` by default. This value
203
+
defines what is the default behavior for authentication in your schema fields. `true` means
204
+
every root level field requires authentication unless specified otherwise using the
205
+
`authenticate: false` option on the field. `false` means your root level fields won't require
206
+
authentication unless specified otherwise using the `authenticate: true` option on the field.
207
+
1.`unauthenticated_proc`: This param is optional. Here you can provide a proc that receives
208
+
one argument (field name) and is called whenever a field that requires authentication
209
+
is called without an authenticated resource. By default a `GraphQL::ExecutionError` will be
210
+
raised if authentication fails. This will provide a GQL like error message on the response.
211
+
212
+
### Available Mount Options
213
+
Both the `mount_graphql_devise_for` method and the `GraphqlDevise::ResourceLoader` class
214
+
take the same options. So, wether you decide to mount this gem in a separate route
215
+
from your main application's schema or you use our `GraphqlDevise::SchemaPlugin` to load
216
+
this gem's auth operation into your schema, these are the options you can provide as a hash.
123
217
124
-
Here are the options for the mount method:
218
+
```ruby
219
+
# Using the mount method in your config/routes.rb file
220
+
mount_graphql_devise_for('User', {})
221
+
222
+
# Providing options to a GraphqlDevise::ResourceLoader
223
+
GraphqlDevise::ResourceLoader.new('User', {})
224
+
```
125
225
126
-
1.`at`: Route where the GraphQL schema will be mounted on the Rails server. In this example your API will have these two routes: `POST /api/v1/graphql_auth` and `GET /api/v1/graphql_auth`.
127
-
If this option is not specified, the schema will be mounted at `/graphql_auth`.
226
+
1.`at`: Route where the GraphQL schema will be mounted on the Rails server.
227
+
In [this example](#mounting-auth-schema-on-a-separate-route) your API will have
228
+
these two routes: `POST /api/v1/graphql_auth` and `GET /api/v1/graphql_auth`.
229
+
If this option is not specified, the schema will be mounted at `/graphql_auth`. **This option only works if you are using the mount method.**
128
230
1.`operations`: Specifying this is optional. Here you can override default
129
231
behavior by specifying your own mutations and queries for every GraphQL operation.
130
232
Check available operations in this file [mutations](https://github.com/graphql-devise/graphql_devise/blob/b5985036e01ea064e43e457b4f0c8516f172471c/lib/graphql_devise/rails/routes.rb#L19)
@@ -163,7 +265,7 @@ or [base resolver](https://github.com/graphql-devise/graphql_devise/blob/master/
163
265
respectively, to take advantage of some of the methods provided by devise
164
266
just like with `devise_scope`
165
267
166
-
####Available Operations
268
+
### Available Operations
167
269
The following is a list of the symbols you can provide to the `operations`, `skip` and `only` options of the mount method:
168
270
```ruby
169
271
:login
@@ -175,7 +277,6 @@ The following is a list of the symbols you can provide to the `operations`, `ski
175
277
:check_password_token
176
278
```
177
279
178
-
179
280
### Configuring Model
180
281
Just like with Devise and DTA, you need to include a module in your authenticatable model,
181
282
so with our example, your user model will have to look like this:
@@ -216,6 +317,9 @@ Keep in mind that if your app uses multiple locales, you should set the `I18n.lo
216
317
217
318
### Authenticating Controller Actions
218
319
Just like with Devise or DTA, you will need to authenticate users in your controllers.
320
+
For this you have two alternatives.
321
+
322
+
#### Authenticate Before Reaching Your GQL Schema
219
323
For this you need to call `authenticate_<model>!` in a before_action hook of your controller.
220
324
In our example our model is `User`, so it would look like this:
221
325
```ruby
@@ -234,6 +338,62 @@ end
234
338
235
339
The install generator can do this for you because it executes DTA installer.
236
340
See [Installation](#Installation) for details.
341
+
If authentication fails for the request for whatever reason, execution of the request is halted
342
+
and an error is returned in a REST format as the request never reaches your GQL schema.
343
+
344
+
#### Authenticate in Your GQL Schema
345
+
For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
346
+
[here](#mounting-operations-into-your-own-schema) and also set the authenticated resource
This gem supports schemas using the interpreter and it is recommended as it introduces several
477
+
improvements which focus mainly on performance.
478
+
311
479
### Using Alongside Standard Devise
312
480
The DeviseTokenAuth gem allows experimental use of the standard Devise gem to be configured at the same time, for more
313
481
information you can check [this answer here](https://github.com/lynndylanhurley/devise_token_auth/blob/2a32f18ccce15638a74e72f6cfde5cf15a808d3f/docs/faq.md#can-i-use-this-gem-alongside-standard-devise).
@@ -318,7 +486,6 @@ standard Devise templates.
318
486
## Future Work
319
487
We will continue to improve the gem and add better docs.
320
488
321
-
1. Add mount option that will create a separate schema for the mounted resource.
322
489
1. Make sure this gem can correctly work alongside DTA and the original Devise gem.
323
490
1. Improve DOCS.
324
491
1. Add support for unlockable and other Devise modules.
0 commit comments