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
190
+
defines what is the default behavior for authentication in your schema fields. `true` means
191
+
every root level field requires authentication unless specified otherwise using the
192
+
`authenticate: false` option on the field. `false` means your root level fields won't require
193
+
authentication unless specified otherwise using the `authenticate: true` option on the field.
194
+
1.`unauthenticated_proc`: This param is optional. Here you can provide a proc that receives
195
+
one argument (field name) and is called whenever a field that requires authentication
196
+
is called without an authenticated resource.
197
+
198
+
### Available Mount Options
199
+
Both the `mount_graphql_devise_for` method and the `GraphqlDevise::ResourceLoader` class
200
+
take the same options. So, wether you decide to mount this gem in a separate route
201
+
from your main application's schema or you use our `GraphqlDevise::SchemaPlugin` to load
202
+
this gem's auth operation into your schema, these are the options you can provide as a hash.
123
203
124
-
Here are the options for the mount method:
204
+
```ruby
205
+
# Using the mount method in your config/routes.rb file
206
+
mount_graphql_devise_for('User', {})
125
207
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`.
208
+
# Providing options to a GraphqlDevise::ResourceLoader
209
+
GraphqlDevise::ResourceLoader.new('User', {})
210
+
```
211
+
212
+
1.`at`: Route where the GraphQL schema will be mounted on the Rails server.
213
+
In [this example](#mounting-auth-schema-on-a-separate-route) your API will have
214
+
these two routes: `POST /api/v1/graphql_auth` and `GET /api/v1/graphql_auth`.
215
+
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
216
1.`operations`: Specifying this is optional. Here you can override default
129
217
behavior by specifying your own mutations and queries for every GraphQL operation.
130
218
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 +251,7 @@ or [base resolver](https://github.com/graphql-devise/graphql_devise/blob/master/
163
251
respectively, to take advantage of some of the methods provided by devise
164
252
just like with `devise_scope`
165
253
166
-
####Available Operations
254
+
### Available Operations
167
255
The following is a list of the symbols you can provide to the `operations`, `skip` and `only` options of the mount method:
168
256
```ruby
169
257
:login
@@ -175,7 +263,6 @@ The following is a list of the symbols you can provide to the `operations`, `ski
175
263
:check_password_token
176
264
```
177
265
178
-
179
266
### Configuring Model
180
267
Just like with Devise and DTA, you need to include a module in your authenticatable model,
181
268
so with our example, your user model will have to look like this:
@@ -216,6 +303,9 @@ Keep in mind that if your app uses multiple locales, you should set the `I18n.lo
216
303
217
304
### Authenticating Controller Actions
218
305
Just like with Devise or DTA, you will need to authenticate users in your controllers.
306
+
For this you have two alternatives.
307
+
308
+
#### Authenticate Before Reaching Your GQL Schema
219
309
For this you need to call `authenticate_<model>!` in a before_action hook of your controller.
220
310
In our example our model is `User`, so it would look like this:
221
311
```ruby
@@ -234,6 +324,62 @@ end
234
324
235
325
The install generator can do this for you because it executes DTA installer.
236
326
See [Installation](#Installation) for details.
327
+
If authentication fails for the request for whatever reason, execution of the request is halted
328
+
and an error is returned in a REST format as the request never reaches your GQL schema.
329
+
330
+
#### Authenticate in Your GQL Schema
331
+
For this you will need to add the `GraphqlDevise::SchemaPlugin` to your schema as described
332
+
[here](#mounting-operations-into-your-own-schema) and also set the authenticated resource
0 commit comments