This is page 9 of 10. Use http://codebase.md/m-gonzalo/cosa-sai?lines=true&page={x} to view the full context.
# Directory Structure
```
├── .gitignore
├── bun.lock
├── Dockerfile
├── package.json
├── prompts
│ └── default.txt
├── README.md
├── smithery.yaml
├── src
│ ├── db.ts
│ ├── gemini.ts
│ ├── index.ts
│ ├── logger.ts
│ └── types.ts
├── test
│ ├── docs
│ │ ├── ash-docs
│ │ │ ├── ash_admin.md
│ │ │ ├── ash_appsignal.md
│ │ │ ├── ash_archival.md
│ │ │ ├── ash_authentication_phoenix.md
│ │ │ ├── ash_authentication.md
│ │ │ ├── ash_cloak.md
│ │ │ ├── ash_csv.md
│ │ │ ├── ash_cubdb.md
│ │ │ ├── ash_double_entry.md
│ │ │ ├── ash_graphql.md
│ │ │ ├── ash_json_api.md
│ │ │ ├── ash_money.md
│ │ │ ├── ash_oban.md
│ │ │ ├── ash_phoenix.md
│ │ │ ├── ash_postgres.md
│ │ │ ├── ash_rbac.md
│ │ │ ├── ash_sqlite.md
│ │ │ ├── ash_state_machine.md
│ │ │ └── ash.md
│ │ ├── bun-elysia-docs
│ │ │ ├── bun.sh.md
│ │ │ └── elysiajs.com.md
│ │ ├── javascript-docs
│ │ │ └── sample.md
│ │ └── phoenix-docs
│ │ └── phx-docs.md
│ └── prompts
│ ├── ash-framework.txt
│ ├── bun-elysia.txt
│ ├── javascript.txt
│ └── phoenix.txt
└── tsconfig.json
```
# Files
--------------------------------------------------------------------------------
/test/docs/ash-docs/ash_graphql.md:
--------------------------------------------------------------------------------
```markdown
1 | [](https://github.com/ash-project/ash_graphql)
2 |
3 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4 |
5 | v1.5.0
6 |
7 | - GUIDES
8 | - Modules
9 | - Mix Tasks
10 |
11 | <!--THE END-->
12 |
13 | <!--THE END-->
14 |
15 | <!--THE END-->
16 |
17 | Search documentation of ash\_graphql
18 |
19 | Settings
20 |
21 | # [View Source](https://github.com/ash-project/ash_graphql "View Source") API Reference ash\_graphql v1.5.0
22 |
23 | ## [](api-reference.html#modules)Modules
24 |
25 | [AshGraphql](AshGraphql.html)
26 |
27 | AshGraphql is a GraphQL extension for the Ash framework.
28 |
29 | [AshGraphql.ContextHelpers](AshGraphql.ContextHelpers.html)
30 |
31 | Helper to extract context from its various locations
32 |
33 | [AshGraphql.DefaultErrorHandler](AshGraphql.DefaultErrorHandler.html)
34 |
35 | Replaces any text in message or short\_message with variables
36 |
37 | [AshGraphql.Domain](AshGraphql.Domain.html)
38 |
39 | The entrypoint for adding GraphQL behavior to an Ash domain
40 |
41 | [AshGraphql.Domain.Info](AshGraphql.Domain.Info.html)
42 |
43 | Introspection helpers for AshGraphql.Domain
44 |
45 | [AshGraphql.Error](AshGraphql.Error.html)
46 |
47 | [AshGraphql.Errors](AshGraphql.Errors.html)
48 |
49 | Utilities for working with errors in custom resolvers.
50 |
51 | [AshGraphql.Igniter](AshGraphql.Igniter.html)
52 |
53 | Codemods and utilities for working with AshGraphql & Igniter
54 |
55 | [AshGraphql.Plug](AshGraphql.Plug.html)
56 |
57 | Automatically set up the GraphQL `actor` and `tenant`.
58 |
59 | [AshGraphql.Resource](AshGraphql.Resource.html)
60 |
61 | This Ash resource extension adds configuration for exposing a resource in a graphql.
62 |
63 | [AshGraphql.Resource.Action](AshGraphql.Resource.Action.html)
64 |
65 | Represents a configured generic action
66 |
67 | [AshGraphql.Resource.Helpers](AshGraphql.Resource.Helpers.html)
68 |
69 | Imported helpers for the graphql DSL section
70 |
71 | [AshGraphql.Resource.Info](AshGraphql.Resource.Info.html)
72 |
73 | Introspection helpers for AshGraphql.Resource
74 |
75 | [AshGraphql.Resource.ManagedRelationship](AshGraphql.Resource.ManagedRelationship.html)
76 |
77 | Represents a managed relationship configuration on a mutation
78 |
79 | [AshGraphql.Resource.Mutation](AshGraphql.Resource.Mutation.html)
80 |
81 | Represents a configured mutation on a resource
82 |
83 | [AshGraphql.Resource.Query](AshGraphql.Resource.Query.html)
84 |
85 | Represents a configured query on a resource
86 |
87 | [AshGraphql.Resource.Subscription](AshGraphql.Resource.Subscription.html)
88 |
89 | Represents a configured query on a resource
90 |
91 | [AshGraphql.Resource.Transformers.Subscription](AshGraphql.Resource.Transformers.Subscription.html)
92 |
93 | Adds the notifier for Subscriptions to the Resource
94 |
95 | [AshGraphql.Subscription](AshGraphql.Subscription.html)
96 |
97 | Helpers for working with absinthe subscriptions
98 |
99 | [AshGraphql.Subscription.Actor](AshGraphql.Subscription.Actor.html)
100 |
101 | Allows the user to substitue an actor for another more generic actor, this can be used to deduplicate subscription execution
102 |
103 | [AshGraphql.Subscription.Batcher](AshGraphql.Subscription.Batcher.html)
104 |
105 | If started as a GenServer, this module will batch notifications and send them in bulk. Otherwise, it will send them immediately.
106 |
107 | [AshGraphql.Subscription.Config](AshGraphql.Subscription.Config.html)
108 |
109 | Creates a config function used for the absinthe subscription definition
110 |
111 | [AshGraphql.Subscription.Endpoint](AshGraphql.Subscription.Endpoint.html)
112 |
113 | [AshGraphql.Subscription.Notifier](AshGraphql.Subscription.Notifier.html)
114 |
115 | AshNotifier that triggers absinthe if subscriptions are listening
116 |
117 | [AshGraphql.Subscription.Runner](AshGraphql.Subscription.Runner.html)
118 |
119 | Custom implementation if the run\_docset function for the PubSub module used for Subscriptions
120 |
121 | [AshGraphql.Type](AshGraphql.Type.html)
122 |
123 | Callbacks used to enrich types with GraphQL-specific metadata.
124 |
125 | [AshGraphql.Types.JSON](AshGraphql.Types.JSON.html)
126 |
127 | The Json scalar type allows arbitrary JSON values to be passed in and out.
128 |
129 | [AshGraphql.Types.JSONString](AshGraphql.Types.JSONString.html)
130 |
131 | The Json scalar type allows arbitrary JSON values to be passed in and out.
132 |
133 | ## [](api-reference.html#mix-tasks)Mix Tasks
134 |
135 | [mix ash\_graphql.install](Mix.Tasks.AshGraphql.Install.html)
136 |
137 | Installs AshGraphql. Should be run with `mix igniter.install ash_graphql`
138 |
139 | [Next Page → Home](readme.html)
140 |
141 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
142 |
143 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
144 | [](https://github.com/ash-project/ash_graphql)
145 |
146 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
147 |
148 | v1.5.0
149 |
150 | - GUIDES
151 | - Modules
152 | - Mix Tasks
153 |
154 | <!--THE END-->
155 |
156 | <!--THE END-->
157 |
158 | <!--THE END-->
159 |
160 | Search documentation of ash\_graphql
161 |
162 | Settings
163 |
164 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/context_helpers.ex#L1 "View Source") AshGraphql.ContextHelpers (ash\_graphql v1.5.0)
165 |
166 | Helper to extract context from its various locations
167 |
168 | # [](AshGraphql.ContextHelpers.html#summary)Summary
169 |
170 | ## [Functions](AshGraphql.ContextHelpers.html#functions)
171 |
172 | [get\_context(context)](AshGraphql.ContextHelpers.html#get_context/1)
173 |
174 | # [](AshGraphql.ContextHelpers.html#functions)Functions
175 |
176 | [](AshGraphql.ContextHelpers.html#get_context/1)
177 |
178 | # get\_context(context)
179 |
180 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/context_helpers.ex#L4)
181 |
182 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
183 |
184 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
185 | [](https://github.com/ash-project/ash_graphql)
186 |
187 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
188 |
189 | v1.5.0
190 |
191 | - GUIDES
192 | - Modules
193 | - Mix Tasks
194 |
195 | <!--THE END-->
196 |
197 | <!--THE END-->
198 |
199 | <!--THE END-->
200 |
201 | Search documentation of ash\_graphql
202 |
203 | Settings
204 |
205 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/default_error_handler.ex#L1 "View Source") AshGraphql.DefaultErrorHandler (ash\_graphql v1.5.0)
206 |
207 | Replaces any text in message or short\_message with variables
208 |
209 | # [](AshGraphql.DefaultErrorHandler.html#summary)Summary
210 |
211 | ## [Functions](AshGraphql.DefaultErrorHandler.html#functions)
212 |
213 | [handle\_error(error, arg2)](AshGraphql.DefaultErrorHandler.html#handle_error/2)
214 |
215 | [stringified\_value(value)](AshGraphql.DefaultErrorHandler.html#stringified_value/1)
216 |
217 | # [](AshGraphql.DefaultErrorHandler.html#functions)Functions
218 |
219 | [](AshGraphql.DefaultErrorHandler.html#handle_error/2)
220 |
221 | # handle\_error(error, arg2)
222 |
223 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/default_error_handler.ex#L4)
224 |
225 | [](AshGraphql.DefaultErrorHandler.html#stringified_value/1)
226 |
227 | # stringified\_value(value)
228 |
229 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/default_error_handler.ex#L34)
230 |
231 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
232 |
233 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
234 | [](https://github.com/ash-project/ash_graphql)
235 |
236 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
237 |
238 | v1.5.0
239 |
240 | - GUIDES
241 | - Modules
242 | - Mix Tasks
243 |
244 | <!--THE END-->
245 |
246 | <!--THE END-->
247 |
248 | <!--THE END-->
249 |
250 | Search documentation of ash\_graphql
251 |
252 | Settings
253 |
254 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L1 "View Source") AshGraphql.Domain (ash\_graphql v1.5.0)
255 |
256 | The entrypoint for adding GraphQL behavior to an Ash domain
257 |
258 | # [](AshGraphql.Domain.html#summary)Summary
259 |
260 | ## [Functions](AshGraphql.Domain.html#functions)
261 |
262 | [authorize?(domain)](AshGraphql.Domain.html#authorize?/1) deprecated
263 |
264 | See [`AshGraphql.Domain.Info.authorize?/1`](AshGraphql.Domain.Info.html#authorize?/1).
265 |
266 | [global\_type\_definitions(schema, env)](AshGraphql.Domain.html#global_type_definitions/2)
267 |
268 | [graphql(body)](AshGraphql.Domain.html#graphql/1)
269 |
270 | [install(igniter, module, arg, path, argv)](AshGraphql.Domain.html#install/5)
271 |
272 | [root\_level\_errors?(domain)](AshGraphql.Domain.html#root_level_errors?/1) deprecated
273 |
274 | See [`AshGraphql.Domain.Info.root_level_errors?/1`](AshGraphql.Domain.Info.html#root_level_errors?/1).
275 |
276 | [show\_raised\_errors?(domain)](AshGraphql.Domain.html#show_raised_errors?/1) deprecated
277 |
278 | See [`AshGraphql.Domain.Info.show_raised_errors?/1`](AshGraphql.Domain.Info.html#show_raised_errors?/1).
279 |
280 | [subscriptions(domain, all\_domains, resources, action\_middleware, schema)](AshGraphql.Domain.html#subscriptions/5)
281 |
282 | # [](AshGraphql.Domain.html#functions)Functions
283 |
284 | [](AshGraphql.Domain.html#authorize?/1)
285 |
286 | # authorize?(domain)
287 |
288 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L210)
289 |
290 | This function is deprecated. See \`AshGraphql.Domain.Info.authorize?/1\`.
291 |
292 | See [`AshGraphql.Domain.Info.authorize?/1`](AshGraphql.Domain.Info.html#authorize?/1).
293 |
294 | [](AshGraphql.Domain.html#global_type_definitions/2)
295 |
296 | # global\_type\_definitions(schema, env)
297 |
298 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L373)
299 |
300 | [](AshGraphql.Domain.html#graphql/1)
301 |
302 | # graphql(body)
303 |
304 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L147)(macro)
305 |
306 | [](AshGraphql.Domain.html#install/5)
307 |
308 | # install(igniter, module, arg, path, argv)
309 |
310 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L156)
311 |
312 | [](AshGraphql.Domain.html#root_level_errors?/1)
313 |
314 | # root\_level\_errors?(domain)
315 |
316 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L213)
317 |
318 | This function is deprecated. See \`AshGraphql.Domain.Info.root\_level\_errors?/1\`.
319 |
320 | See [`AshGraphql.Domain.Info.root_level_errors?/1`](AshGraphql.Domain.Info.html#root_level_errors?/1).
321 |
322 | [](AshGraphql.Domain.html#show_raised_errors?/1)
323 |
324 | # show\_raised\_errors?(domain)
325 |
326 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L216)
327 |
328 | This function is deprecated. See \`AshGraphql.Domain.Info.show\_raised\_errors?/1\`.
329 |
330 | See [`AshGraphql.Domain.Info.show_raised_errors?/1`](AshGraphql.Domain.Info.html#show_raised_errors?/1).
331 |
332 | [](AshGraphql.Domain.html#subscriptions/5)
333 |
334 | # subscriptions(domain, all\_domains, resources, action\_middleware, schema)
335 |
336 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/domain.ex#L251)
337 |
338 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
339 |
340 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
341 | [](https://github.com/ash-project/ash_graphql)
342 |
343 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
344 |
345 | v1.5.0
346 |
347 | - GUIDES
348 | - Modules
349 | - Mix Tasks
350 |
351 | <!--THE END-->
352 |
353 | <!--THE END-->
354 |
355 | <!--THE END-->
356 |
357 | Search documentation of ash\_graphql
358 |
359 | Settings
360 |
361 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L1 "View Source") AshGraphql.Domain.Info (ash\_graphql v1.5.0)
362 |
363 | Introspection helpers for AshGraphql.Domain
364 |
365 | # [](AshGraphql.Domain.Info.html#summary)Summary
366 |
367 | ## [Functions](AshGraphql.Domain.Info.html#functions)
368 |
369 | [authorize?(domain)](AshGraphql.Domain.Info.html#authorize?/1)
370 |
371 | Whether or not to run authorization on this domain
372 |
373 | [error\_handler(domain)](AshGraphql.Domain.Info.html#error_handler/1)
374 |
375 | An error handler for errors produced by the domain
376 |
377 | [mutations(resource)](AshGraphql.Domain.Info.html#mutations/1)
378 |
379 | The mutations exposed by the domain
380 |
381 | [queries(resource)](AshGraphql.Domain.Info.html#queries/1)
382 |
383 | The queries exposed by the domain
384 |
385 | [root\_level\_errors?(domain)](AshGraphql.Domain.Info.html#root_level_errors?/1)
386 |
387 | Whether or not to surface errors to the root of the response
388 |
389 | [show\_raised\_errors?(domain)](AshGraphql.Domain.Info.html#show_raised_errors?/1)
390 |
391 | Whether or not to render raised errors in the GraphQL response
392 |
393 | [subscriptions(resource)](AshGraphql.Domain.Info.html#subscriptions/1)
394 |
395 | [tracer(domain)](AshGraphql.Domain.Info.html#tracer/1)
396 |
397 | The tracer to use for the given schema
398 |
399 | # [](AshGraphql.Domain.Info.html#functions)Functions
400 |
401 | [](AshGraphql.Domain.Info.html#authorize?/1)
402 |
403 | # authorize?(domain)
404 |
405 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L7)
406 |
407 | Whether or not to run authorization on this domain
408 |
409 | [](AshGraphql.Domain.Info.html#error_handler/1)
410 |
411 | # error\_handler(domain)
412 |
413 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L25)
414 |
415 | An error handler for errors produced by the domain
416 |
417 | [](AshGraphql.Domain.Info.html#mutations/1)
418 |
419 | # mutations(resource)
420 |
421 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L41)
422 |
423 | The mutations exposed by the domain
424 |
425 | [](AshGraphql.Domain.Info.html#queries/1)
426 |
427 | # queries(resource)
428 |
429 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L36)
430 |
431 | The queries exposed by the domain
432 |
433 | [](AshGraphql.Domain.Info.html#root_level_errors?/1)
434 |
435 | # root\_level\_errors?(domain)
436 |
437 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L20)
438 |
439 | Whether or not to surface errors to the root of the response
440 |
441 | [](AshGraphql.Domain.Info.html#show_raised_errors?/1)
442 |
443 | # show\_raised\_errors?(domain)
444 |
445 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L50)
446 |
447 | Whether or not to render raised errors in the GraphQL response
448 |
449 | [](AshGraphql.Domain.Info.html#subscriptions/1)
450 |
451 | # subscriptions(resource)
452 |
453 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L45)
454 |
455 | [](AshGraphql.Domain.Info.html#tracer/1)
456 |
457 | # tracer(domain)
458 |
459 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/domain/info.ex#L12)
460 |
461 | The tracer to use for the given schema
462 |
463 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
464 |
465 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
466 | [](https://github.com/ash-project/ash_graphql)
467 |
468 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
469 |
470 | v1.5.0
471 |
472 | - GUIDES
473 | - Modules
474 | - Mix Tasks
475 |
476 | <!--THE END-->
477 |
478 | <!--THE END-->
479 |
480 | <!--THE END-->
481 |
482 | Search documentation of ash\_graphql
483 |
484 | Settings
485 |
486 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/error.ex#L1 "View Source") AshGraphql.Error protocol (ash\_graphql v1.5.0)
487 |
488 | # [](AshGraphql.Error.html#summary)Summary
489 |
490 | ## [Types](AshGraphql.Error.html#types)
491 |
492 | [t()](AshGraphql.Error.html#t:t/0)
493 |
494 | All the types that implement this protocol.
495 |
496 | ## [Functions](AshGraphql.Error.html#functions)
497 |
498 | [to\_error(exception)](AshGraphql.Error.html#to_error/1)
499 |
500 | # [](AshGraphql.Error.html#types)Types
501 |
502 | [](AshGraphql.Error.html#t:t/0)
503 |
504 | # t()
505 |
506 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/error.ex#L1)
507 |
508 | ```
509 | @type t() :: term()
510 | ```
511 |
512 | All the types that implement this protocol.
513 |
514 | # [](AshGraphql.Error.html#functions)Functions
515 |
516 | [](AshGraphql.Error.html#to_error/1)
517 |
518 | # to\_error(exception)
519 |
520 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/error.ex#L2)
521 |
522 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
523 |
524 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
525 | [](https://github.com/ash-project/ash_graphql)
526 |
527 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
528 |
529 | v1.5.0
530 |
531 | - GUIDES
532 | - Modules
533 | - Mix Tasks
534 |
535 | <!--THE END-->
536 |
537 | <!--THE END-->
538 |
539 | <!--THE END-->
540 |
541 | Search documentation of ash\_graphql
542 |
543 | Settings
544 |
545 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/graphql/errors.ex#L1 "View Source") AshGraphql.Errors (ash\_graphql v1.5.0)
546 |
547 | Utilities for working with errors in custom resolvers.
548 |
549 | # [](AshGraphql.Errors.html#summary)Summary
550 |
551 | ## [Functions](AshGraphql.Errors.html#functions)
552 |
553 | [to\_errors(errors, context, domain, resource, action)](AshGraphql.Errors.html#to_errors/5)
554 |
555 | Transform an error or list of errors into the response for graphql.
556 |
557 | # [](AshGraphql.Errors.html#functions)Functions
558 |
559 | [](AshGraphql.Errors.html#to_errors/5)
560 |
561 | # to\_errors(errors, context, domain, resource, action)
562 |
563 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/graphql/errors.ex#L10)
564 |
565 | Transform an error or list of errors into the response for graphql.
566 |
567 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
568 |
569 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
570 | [](https://github.com/ash-project/ash_graphql)
571 |
572 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
573 |
574 | v1.5.0
575 |
576 | - GUIDES
577 | - Modules
578 | - Mix Tasks
579 |
580 | <!--THE END-->
581 |
582 | <!--THE END-->
583 |
584 | <!--THE END-->
585 |
586 | Search documentation of ash\_graphql
587 |
588 | Settings
589 |
590 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/ash_graphql.ex#L1 "View Source") AshGraphql (ash\_graphql v1.5.0)
591 |
592 | AshGraphql is a GraphQL extension for the Ash framework.
593 |
594 | For more information, see the [getting started guide](getting-started-with-graphql.html)
595 |
596 | # [](AshGraphql.html#summary)Summary
597 |
598 | ## [Functions](AshGraphql.html#functions)
599 |
600 | [handle\_errors(result, resource, resolution, opts \\\\ \[\])](AshGraphql.html#handle_errors/4)
601 |
602 | Applies AshGraphql's error handling logic if the value is an `{:error, error}` tuple, otherwise returns the value
603 |
604 | [load\_fields(data, resource, resolution, opts \\\\ \[\])](AshGraphql.html#load_fields/4)
605 |
606 | Use this to load any requested fields for a result when it is returned from a custom resolver or mutation.
607 |
608 | [load\_fields\_on\_query(query, resolution, opts \\\\ \[\])](AshGraphql.html#load_fields_on_query/3)
609 |
610 | The same as [`load_fields/4`](AshGraphql.html#load_fields/4), but modifies the provided query to load the required fields.
611 |
612 | [subscription(list)](AshGraphql.html#subscription/1)
613 |
614 | # [](AshGraphql.html#functions)Functions
615 |
616 | [](AshGraphql.html#handle_errors/4)
617 |
618 | # handle\_errors(result, resource, resolution, opts \\\\ \[])
619 |
620 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/ash_graphql.ex#L722)
621 |
622 | ```
623 | @spec handle_errors(
624 | result :: term(),
625 | resource :: Ash.Resource.t(),
626 | resolution :: Absinthe.Resolution.t(),
627 | opts :: Keyword.t()
628 | ) :: term()
629 | ```
630 |
631 | Applies AshGraphql's error handling logic if the value is an `{:error, error}` tuple, otherwise returns the value
632 |
633 | Useful for automatically handling errors in custom queries
634 |
635 | ## [](AshGraphql.html#handle_errors/4-options)Options
636 |
637 | - `domain`: The domain to use when loading the fields. Determined from the resource by default.
638 |
639 | [](AshGraphql.html#load_fields/4)
640 |
641 | # load\_fields(data, resource, resolution, opts \\\\ \[])
642 |
643 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/ash_graphql.ex#L651)
644 |
645 | ```
646 | @spec load_fields(
647 | input,
648 | Ash.Resource.t(),
649 | Absinthe.Resolution.t(),
650 | opts :: Keyword.t()
651 | ) ::
652 | {:ok, input} | {:error, term()}
653 | when input: Ash.Resource.record() | [Ash.Resource.record()] | Ash.Page.page()
654 | ```
655 |
656 | Use this to load any requested fields for a result when it is returned from a custom resolver or mutation.
657 |
658 | ## [](AshGraphql.html#load_fields/4-determining-required-fields)Determining required fields
659 |
660 | If you have a custom query/mutation that returns the record at a "path" in the response, then specify the path. In the example below, `path` would be `["record"]`. This is how we know what fields to load.
661 |
662 | ```
663 | query something() {
664 | result {
665 | record { # <- this is the instance
666 | id
667 | name
668 | }
669 | }
670 | }
671 | ```
672 |
673 | ## [](AshGraphql.html#load_fields/4-options)Options
674 |
675 | - `path`: The path to the record(s) in the response
676 | - `domain`: The domain to use when loading the fields. Determined from the resource by default.
677 | - `authorize?`: Whether to authorize access to fields. Defaults to the domain's setting (which defaults to `true`).
678 | - `actor`: The actor to use when authorizing access to fields. Defaults to the actor in the resolution context.
679 | - `tenant`: The tenant to use when authorizing access to fields. Defaults to the tenant in the resolution context.
680 |
681 | [](AshGraphql.html#load_fields_on_query/3)
682 |
683 | # load\_fields\_on\_query(query, resolution, opts \\\\ \[])
684 |
685 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/ash_graphql.ex#L666)
686 |
687 | ```
688 | @spec load_fields_on_query(
689 | query :: Ash.Query.t() | Ash.Resource.t(),
690 | Absinthe.Resolution.t(),
691 | Keyword.t()
692 | ) :: Ash.Query.t()
693 | ```
694 |
695 | The same as [`load_fields/4`](AshGraphql.html#load_fields/4), but modifies the provided query to load the required fields.
696 |
697 | This allows doing the loading in a single query rather than two separate queries.
698 |
699 | [](AshGraphql.html#subscription/1)
700 |
701 | # subscription(list)
702 |
703 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/ash_graphql.ex#L35)(macro)
704 |
705 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
706 |
707 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
708 | [](https://github.com/ash-project/ash_graphql)
709 |
710 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
711 |
712 | v1.5.0
713 |
714 | - GUIDES
715 | - Modules
716 | - Mix Tasks
717 |
718 | <!--THE END-->
719 |
720 | <!--THE END-->
721 |
722 | <!--THE END-->
723 |
724 | Search documentation of ash\_graphql
725 |
726 | Settings
727 |
728 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/igniter.ex#L2 "View Source") AshGraphql.Igniter (ash\_graphql v1.5.0)
729 |
730 | Codemods and utilities for working with AshGraphql & Igniter
731 |
732 | # [](AshGraphql.Igniter.html#summary)Summary
733 |
734 | ## [Functions](AshGraphql.Igniter.html#functions)
735 |
736 | [ash\_graphql\_schemas(igniter)](AshGraphql.Igniter.html#ash_graphql_schemas/1)
737 |
738 | Returns all modules that `use AshGraphql`
739 |
740 | [find\_schema(igniter, domain)](AshGraphql.Igniter.html#find_schema/2)
741 |
742 | Returns the AshGraphql schema containing the domain in question, or a list of all AshGraphql schemas
743 |
744 | [setup\_absinthe\_schema(igniter, schema\_name \\\\ nil)](AshGraphql.Igniter.html#setup_absinthe_schema/2)
745 |
746 | Sets up an absinthe schema for AshGraphql
747 |
748 | [setup\_phoenix(igniter, schema\_name \\\\ nil)](AshGraphql.Igniter.html#setup_phoenix/2)
749 |
750 | Sets up the phoenix module for AshGraphql
751 |
752 | # [](AshGraphql.Igniter.html#functions)Functions
753 |
754 | [](AshGraphql.Igniter.html#ash_graphql_schemas/1)
755 |
756 | # ash\_graphql\_schemas(igniter)
757 |
758 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/igniter.ex#L187)
759 |
760 | Returns all modules that `use AshGraphql`
761 |
762 | [](AshGraphql.Igniter.html#find_schema/2)
763 |
764 | # find\_schema(igniter, domain)
765 |
766 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/igniter.ex#L6)
767 |
768 | Returns the AshGraphql schema containing the domain in question, or a list of all AshGraphql schemas
769 |
770 | [](AshGraphql.Igniter.html#setup_absinthe_schema/2)
771 |
772 | # setup\_absinthe\_schema(igniter, schema\_name \\\\ nil)
773 |
774 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/igniter.ex#L37)
775 |
776 | Sets up an absinthe schema for AshGraphql
777 |
778 | [](AshGraphql.Igniter.html#setup_phoenix/2)
779 |
780 | # setup\_phoenix(igniter, schema\_name \\\\ nil)
781 |
782 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/igniter.ex#L150)
783 |
784 | Sets up the phoenix module for AshGraphql
785 |
786 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
787 |
788 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
789 | [](https://github.com/ash-project/ash_graphql)
790 |
791 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
792 |
793 | v1.5.0
794 |
795 | - GUIDES
796 | - Modules
797 | - Mix Tasks
798 |
799 | <!--THE END-->
800 |
801 | <!--THE END-->
802 |
803 | <!--THE END-->
804 |
805 | Search documentation of ash\_graphql
806 |
807 | Settings
808 |
809 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/plug.ex#L1 "View Source") AshGraphql.Plug (ash\_graphql v1.5.0)
810 |
811 | Automatically set up the GraphQL `actor` and `tenant`.
812 |
813 | Adding this plug to your pipeline will automatically set the `actor` and `tenant` if they were previously put there by [`Ash.PlugHelpers.set_actor/2`](../ash/3.4.50/Ash.PlugHelpers.html#set_actor/2) or [`Ash.PlugHelpers.set_tenant/2`](../ash/3.4.50/Ash.PlugHelpers.html#set_tenant/2).
814 |
815 | # [](AshGraphql.Plug.html#summary)Summary
816 |
817 | ## [Functions](AshGraphql.Plug.html#functions)
818 |
819 | [call(conn, opts)](AshGraphql.Plug.html#call/2)
820 |
821 | Callback implementation for [`Plug.call/2`](../plug/1.16.1/Plug.html#c:call/2).
822 |
823 | [init(opts)](AshGraphql.Plug.html#init/1)
824 |
825 | Callback implementation for [`Plug.init/1`](../plug/1.16.1/Plug.html#c:init/1).
826 |
827 | # [](AshGraphql.Plug.html#functions)Functions
828 |
829 | [](AshGraphql.Plug.html#call/2)
830 |
831 | # call(conn, opts)
832 |
833 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/plug.ex#L16)
834 |
835 | Callback implementation for [`Plug.call/2`](../plug/1.16.1/Plug.html#c:call/2).
836 |
837 | [](AshGraphql.Plug.html#init/1)
838 |
839 | # init(opts)
840 |
841 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/plug.ex#L14)
842 |
843 | Callback implementation for [`Plug.init/1`](../plug/1.16.1/Plug.html#c:init/1).
844 |
845 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
846 |
847 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
848 | [](https://github.com/ash-project/ash_graphql)
849 |
850 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
851 |
852 | v1.5.0
853 |
854 | - GUIDES
855 | - Modules
856 | - Mix Tasks
857 |
858 | <!--THE END-->
859 |
860 | <!--THE END-->
861 |
862 | <!--THE END-->
863 |
864 | Search documentation of ash\_graphql
865 |
866 | Settings
867 |
868 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L92 "View Source") AshGraphql.Resource.Action (ash\_graphql v1.5.0)
869 |
870 | Represents a configured generic action
871 |
872 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
873 |
874 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
875 | [](https://github.com/ash-project/ash_graphql)
876 |
877 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
878 |
879 | v1.5.0
880 |
881 | - GUIDES
882 | - Modules
883 | - Mix Tasks
884 |
885 | <!--THE END-->
886 |
887 | <!--THE END-->
888 |
889 | <!--THE END-->
890 |
891 | Search documentation of ash\_graphql
892 |
893 | Settings
894 |
895 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/helpers.ex#L1 "View Source") AshGraphql.Resource.Helpers (ash\_graphql v1.5.0)
896 |
897 | Imported helpers for the graphql DSL section
898 |
899 | # [](AshGraphql.Resource.Helpers.html#summary)Summary
900 |
901 | ## [Functions](AshGraphql.Resource.Helpers.html#functions)
902 |
903 | [list\_of(value)](AshGraphql.Resource.Helpers.html#list_of/1)
904 |
905 | A list of a given type, idiomatic for those used to `absinthe` notation.
906 |
907 | [non\_null(value)](AshGraphql.Resource.Helpers.html#non_null/1)
908 |
909 | A non nullable type, idiomatic for those used to `absinthe` notation.
910 |
911 | # [](AshGraphql.Resource.Helpers.html#functions)Functions
912 |
913 | [](AshGraphql.Resource.Helpers.html#list_of/1)
914 |
915 | # list\_of(value)
916 |
917 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/helpers.ex#L8)
918 |
919 | ```
920 | @spec list_of(v) :: {:array, v} when v: term()
921 | ```
922 |
923 | A list of a given type, idiomatic for those used to `absinthe` notation.
924 |
925 | [](AshGraphql.Resource.Helpers.html#non_null/1)
926 |
927 | # non\_null(value)
928 |
929 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/helpers.ex#L16)
930 |
931 | ```
932 | @spec non_null(v) :: {:non_null, v} when v: term()
933 | ```
934 |
935 | A non nullable type, idiomatic for those used to `absinthe` notation.
936 |
937 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
938 |
939 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
940 | [](https://github.com/ash-project/ash_graphql)
941 |
942 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
943 |
944 | v1.5.0
945 |
946 | - GUIDES
947 | - Modules
948 | - Mix Tasks
949 |
950 | <!--THE END-->
951 |
952 | <!--THE END-->
953 |
954 | <!--THE END-->
955 |
956 | Search documentation of ash\_graphql
957 |
958 | Settings
959 |
960 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L1 "View Source") AshGraphql.Resource (ash\_graphql v1.5.0)
961 |
962 | This Ash resource extension adds configuration for exposing a resource in a graphql.
963 |
964 | # [](AshGraphql.Resource.html#summary)Summary
965 |
966 | ## [Functions](AshGraphql.Resource.html#functions)
967 |
968 | [codegen(argv)](AshGraphql.Resource.html#codegen/1)
969 |
970 | [decode\_id(resource, id, relay\_ids?)](AshGraphql.Resource.html#decode_id/3)
971 |
972 | [decode\_primary\_key(resource, value)](AshGraphql.Resource.html#decode_primary_key/2)
973 |
974 | [decode\_relay\_id(id)](AshGraphql.Resource.html#decode_relay_id/1)
975 |
976 | [define\_type?(type, constraints)](AshGraphql.Resource.html#define_type?/2)
977 |
978 | [embedded?(resource\_or\_type)](AshGraphql.Resource.html#embedded?/1)
979 |
980 | [encode\_id(record, relay\_ids?)](AshGraphql.Resource.html#encode_id/2)
981 |
982 | [encode\_primary\_key(record)](AshGraphql.Resource.html#encode_primary_key/1)
983 |
984 | [encode\_relay\_id(record)](AshGraphql.Resource.html#encode_relay_id/1)
985 |
986 | [enum\_definitions(resource, schema, env)](AshGraphql.Resource.html#enum_definitions/3)
987 |
988 | [generate\_object?(resource)](AshGraphql.Resource.html#generate_object?/1) deprecated
989 |
990 | See [`AshGraphql.Resource.Info.generate_object?/1`](AshGraphql.Resource.Info.html#generate_object?/1).
991 |
992 | [graphql(body)](AshGraphql.Resource.html#graphql/1)
993 |
994 | [install(igniter, module, arg, path, argv)](AshGraphql.Resource.html#install/5)
995 |
996 | [managed\_relationship\_definitions(used, schema)](AshGraphql.Resource.html#managed_relationship_definitions/2)
997 |
998 | [managed\_relationships(resource)](AshGraphql.Resource.html#managed_relationships/1) deprecated
999 |
1000 | See [`AshGraphql.Resource.Info.managed_relationships/1`](AshGraphql.Resource.Info.html#managed_relationships/1).
1001 |
1002 | [map\_definitions(resource, all\_domains, schema, env)](AshGraphql.Resource.html#map_definitions/4)
1003 |
1004 | [mutations()](AshGraphql.Resource.html#mutations/0)
1005 |
1006 | [mutations(resource, domain \\\\ \[\])](AshGraphql.Resource.html#mutations/2) deprecated
1007 |
1008 | See [`AshGraphql.Resource.Info.mutations/2`](AshGraphql.Resource.Info.html#mutations/2).
1009 |
1010 | [no\_graphql\_types(resource, schema)](AshGraphql.Resource.html#no_graphql_types/2)
1011 |
1012 | [node\_type?(type)](AshGraphql.Resource.html#node_type?/1)
1013 |
1014 | [primary\_key\_delimiter(resource)](AshGraphql.Resource.html#primary_key_delimiter/1) deprecated
1015 |
1016 | See [`AshGraphql.Resource.Info.primary_key_delimiter/1`](AshGraphql.Resource.Info.html#primary_key_delimiter/1).
1017 |
1018 | [primary\_key\_get\_query(resource, all\_domains)](AshGraphql.Resource.html#primary_key_get_query/2)
1019 |
1020 | [queries()](AshGraphql.Resource.html#queries/0)
1021 |
1022 | [queries(resource, domain \\\\ \[\])](AshGraphql.Resource.html#queries/2) deprecated
1023 |
1024 | See [`AshGraphql.Resource.Info.queries/2`](AshGraphql.Resource.Info.html#queries/2).
1025 |
1026 | [query\_type\_definitions(resource, domain, all\_domains, schema, relay\_ids?)](AshGraphql.Resource.html#query_type_definitions/5)
1027 |
1028 | [ref(env)](AshGraphql.Resource.html#ref/1)
1029 |
1030 | [subscriptions()](AshGraphql.Resource.html#subscriptions/0)
1031 |
1032 | [subscriptions(resource, domain \\\\ \[\])](AshGraphql.Resource.html#subscriptions/2) deprecated
1033 |
1034 | See [`AshGraphql.Resource.Info.subscriptions/2`](AshGraphql.Resource.Info.html#subscriptions/2).
1035 |
1036 | [type(resource)](AshGraphql.Resource.html#type/1) deprecated
1037 |
1038 | See [`AshGraphql.Resource.Info.type/1`](AshGraphql.Resource.Info.html#type/1).
1039 |
1040 | [type\_definition(resource, domain, all\_domains, schema, relay\_ids?)](AshGraphql.Resource.html#type_definition/5)
1041 |
1042 | # [](AshGraphql.Resource.html#functions)Functions
1043 |
1044 | [](AshGraphql.Resource.html#codegen/1)
1045 |
1046 | # codegen(argv)
1047 |
1048 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L526)
1049 |
1050 | [](AshGraphql.Resource.html#decode_id/3)
1051 |
1052 | # decode\_id(resource, id, relay\_ids?)
1053 |
1054 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L599)
1055 |
1056 | [](AshGraphql.Resource.html#decode_primary_key/2)
1057 |
1058 | # decode\_primary\_key(resource, value)
1059 |
1060 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L615)
1061 |
1062 | [](AshGraphql.Resource.html#decode_relay_id/1)
1063 |
1064 | # decode\_relay\_id(id)
1065 |
1066 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L632)
1067 |
1068 | [](AshGraphql.Resource.html#define_type?/2)
1069 |
1070 | # define\_type?(type, constraints)
1071 |
1072 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3683)
1073 |
1074 | ```
1075 | @spec define_type?(Ash.Type.t(), Ash.Type.constraints()) :: boolean()
1076 | ```
1077 |
1078 | [](AshGraphql.Resource.html#embedded?/1)
1079 |
1080 | # embedded?(resource\_or\_type)
1081 |
1082 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L4751)
1083 |
1084 | [](AshGraphql.Resource.html#encode_id/2)
1085 |
1086 | # encode\_id(record, relay\_ids?)
1087 |
1088 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L566)
1089 |
1090 | [](AshGraphql.Resource.html#encode_primary_key/1)
1091 |
1092 | # encode\_primary\_key(record)
1093 |
1094 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L574)
1095 |
1096 | [](AshGraphql.Resource.html#encode_relay_id/1)
1097 |
1098 | # encode\_relay\_id(record)
1099 |
1100 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L591)
1101 |
1102 | [](AshGraphql.Resource.html#enum_definitions/3)
1103 |
1104 | # enum\_definitions(resource, schema, env)
1105 |
1106 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3513)
1107 |
1108 | [](AshGraphql.Resource.html#generate_object?/1)
1109 |
1110 | # generate\_object?(resource)
1111 |
1112 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L520)
1113 |
1114 | This function is deprecated. See \`AshGraphql.Resource.Info.generate\_object?/1\`.
1115 |
1116 | See [`AshGraphql.Resource.Info.generate_object?/1`](AshGraphql.Resource.Info.html#generate_object?/1).
1117 |
1118 | [](AshGraphql.Resource.html#graphql/1)
1119 |
1120 | # graphql(body)
1121 |
1122 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L499)(macro)
1123 |
1124 | [](AshGraphql.Resource.html#install/5)
1125 |
1126 | # install(igniter, module, arg, path, argv)
1127 |
1128 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L538)
1129 |
1130 | [](AshGraphql.Resource.html#managed_relationship_definitions/2)
1131 |
1132 | # managed\_relationship\_definitions(used, schema)
1133 |
1134 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L2144)
1135 |
1136 | [](AshGraphql.Resource.html#managed_relationships/1)
1137 |
1138 | # managed\_relationships(resource)
1139 |
1140 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L511)
1141 |
1142 | This function is deprecated. See \`AshGraphql.Resource.Info.managed\_relationships/1\`.
1143 |
1144 | See [`AshGraphql.Resource.Info.managed_relationships/1`](AshGraphql.Resource.Info.html#managed_relationships/1).
1145 |
1146 | [](AshGraphql.Resource.html#map_definitions/4)
1147 |
1148 | # map\_definitions(resource, all\_domains, schema, env)
1149 |
1150 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3255)
1151 |
1152 | [](AshGraphql.Resource.html#mutations/0)
1153 |
1154 | # mutations()
1155 |
1156 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L287)
1157 |
1158 | [](AshGraphql.Resource.html#mutations/2)
1159 |
1160 | # mutations(resource, domain \\\\ \[])
1161 |
1162 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L505)
1163 |
1164 | This function is deprecated. See \`AshGraphql.Resource.Info.mutations/1\`.
1165 |
1166 | See [`AshGraphql.Resource.Info.mutations/2`](AshGraphql.Resource.Info.html#mutations/2).
1167 |
1168 | [](AshGraphql.Resource.html#no_graphql_types/2)
1169 |
1170 | # no\_graphql\_types(resource, schema)
1171 |
1172 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L2140)
1173 |
1174 | [](AshGraphql.Resource.html#node_type?/1)
1175 |
1176 | # node\_type?(type)
1177 |
1178 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3917)
1179 |
1180 | [](AshGraphql.Resource.html#primary_key_delimiter/1)
1181 |
1182 | # primary\_key\_delimiter(resource)
1183 |
1184 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L517)
1185 |
1186 | This function is deprecated. See \`AshGraphql.Resource.Info.primary\_key\_delimiter/1\`.
1187 |
1188 | See [`AshGraphql.Resource.Info.primary_key_delimiter/1`](AshGraphql.Resource.Info.html#primary_key_delimiter/1).
1189 |
1190 | [](AshGraphql.Resource.html#primary_key_get_query/2)
1191 |
1192 | # primary\_key\_get\_query(resource, all\_domains)
1193 |
1194 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L4744)
1195 |
1196 | [](AshGraphql.Resource.html#queries/0)
1197 |
1198 | # queries()
1199 |
1200 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L185)
1201 |
1202 | [](AshGraphql.Resource.html#queries/2)
1203 |
1204 | # queries(resource, domain \\\\ \[])
1205 |
1206 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L502)
1207 |
1208 | This function is deprecated. See \`AshGraphql.Resource.Info.queries/1\`.
1209 |
1210 | See [`AshGraphql.Resource.Info.queries/2`](AshGraphql.Resource.Info.html#queries/2).
1211 |
1212 | [](AshGraphql.Resource.html#query_type_definitions/5)
1213 |
1214 | # query\_type\_definitions(resource, domain, all\_domains, schema, relay\_ids?)
1215 |
1216 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3921)
1217 |
1218 | [](AshGraphql.Resource.html#ref/1)
1219 |
1220 | # ref(env)
1221 |
1222 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L522)
1223 |
1224 | [](AshGraphql.Resource.html#subscriptions/0)
1225 |
1226 | # subscriptions()
1227 |
1228 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L331)
1229 |
1230 | [](AshGraphql.Resource.html#subscriptions/2)
1231 |
1232 | # subscriptions(resource, domain \\\\ \[])
1233 |
1234 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L508)
1235 |
1236 | This function is deprecated. See \`AshGraphql.Resource.Info.mutations/1\`.
1237 |
1238 | See [`AshGraphql.Resource.Info.subscriptions/2`](AshGraphql.Resource.Info.html#subscriptions/2).
1239 |
1240 | [](AshGraphql.Resource.html#type/1)
1241 |
1242 | # type(resource)
1243 |
1244 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L514)
1245 |
1246 | This function is deprecated. See \`AshGraphql.Resource.Info.type/1\`.
1247 |
1248 | See [`AshGraphql.Resource.Info.type/1`](AshGraphql.Resource.Info.html#type/1).
1249 |
1250 | [](AshGraphql.Resource.html#type_definition/5)
1251 |
1252 | # type\_definition(resource, domain, all\_domains, schema, relay\_ids?)
1253 |
1254 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/resource.ex#L3951)
1255 |
1256 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1257 |
1258 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1259 | [](https://github.com/ash-project/ash_graphql)
1260 |
1261 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1262 |
1263 | v1.5.0
1264 |
1265 | - GUIDES
1266 | - Modules
1267 | - Mix Tasks
1268 |
1269 | <!--THE END-->
1270 |
1271 | <!--THE END-->
1272 |
1273 | <!--THE END-->
1274 |
1275 | Search documentation of ash\_graphql
1276 |
1277 | Settings
1278 |
1279 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L1 "View Source") AshGraphql.Resource.Info (ash\_graphql v1.5.0)
1280 |
1281 | Introspection helpers for AshGraphql.Resource
1282 |
1283 | # [](AshGraphql.Resource.Info.html#summary)Summary
1284 |
1285 | ## [Functions](AshGraphql.Resource.Info.html#functions)
1286 |
1287 | [argument\_input\_types(resource)](AshGraphql.Resource.Info.html#argument_input_types/1)
1288 |
1289 | Graphql argument type overrides for the resource
1290 |
1291 | [argument\_names(resource)](AshGraphql.Resource.Info.html#argument_names/1)
1292 |
1293 | Graphql argument name overrides for the resource
1294 |
1295 | [attribute\_input\_types(resource)](AshGraphql.Resource.Info.html#attribute_input_types/1)
1296 |
1297 | Graphql attribute input type overrides for the resource
1298 |
1299 | [attribute\_types(resource)](AshGraphql.Resource.Info.html#attribute_types/1)
1300 |
1301 | Graphql type overrides for the resource
1302 |
1303 | [derive\_filter?(resource)](AshGraphql.Resource.Info.html#derive_filter?/1)
1304 |
1305 | Wether or not to derive a filter input for the resource automatically
1306 |
1307 | [derive\_sort?(resource)](AshGraphql.Resource.Info.html#derive_sort?/1)
1308 |
1309 | Wether or not to derive a sort input for the resource automatically
1310 |
1311 | [encode\_primary\_key?(resource)](AshGraphql.Resource.Info.html#encode_primary_key?/1)
1312 |
1313 | Wether or not to encode the primary key as a single `id` field when reading and getting
1314 |
1315 | [error\_handler(resource)](AshGraphql.Resource.Info.html#error_handler/1)
1316 |
1317 | An error handler for errors produced by the resource
1318 |
1319 | [field\_names(resource)](AshGraphql.Resource.Info.html#field_names/1)
1320 |
1321 | Graphql field name (attribute/relationship/calculation/arguments) overrides for the resource
1322 |
1323 | [filterable\_field?(resource, field\_name)](AshGraphql.Resource.Info.html#filterable_field?/2)
1324 |
1325 | May the specified field be filtered on?
1326 |
1327 | [filterable\_fields(resource)](AshGraphql.Resource.Info.html#filterable_fields/1)
1328 |
1329 | Fields that may be filtered on
1330 |
1331 | [generate\_object?(resource)](AshGraphql.Resource.Info.html#generate_object?/1)
1332 |
1333 | Wether or not an object should be generated, or if one with the type name for this resource should be used.
1334 |
1335 | [hide\_fields(resource)](AshGraphql.Resource.Info.html#hide_fields/1)
1336 |
1337 | Fields to hide from the graphql domain
1338 |
1339 | [keyset\_field(resource)](AshGraphql.Resource.Info.html#keyset_field/1)
1340 |
1341 | The field name to place the keyset of a result in
1342 |
1343 | [managed\_relationship(resource, action, argument)](AshGraphql.Resource.Info.html#managed_relationship/3)
1344 |
1345 | The managed\_relationshi configuration for a given action/argument
1346 |
1347 | [managed\_relationships(resource)](AshGraphql.Resource.Info.html#managed_relationships/1)
1348 |
1349 | The managed\_relationship configurations
1350 |
1351 | [managed\_relationships\_auto?(resource)](AshGraphql.Resource.Info.html#managed_relationships_auto?/1)
1352 |
1353 | [mutations(resource, domain\_or\_domains \\\\ \[\])](AshGraphql.Resource.Info.html#mutations/2)
1354 |
1355 | The mutations exposed for the resource
1356 |
1357 | [nullable\_fields(resource)](AshGraphql.Resource.Info.html#nullable_fields/1)
1358 |
1359 | Graphql nullability overrides for the resource
1360 |
1361 | [paginate\_relationship\_with(resource)](AshGraphql.Resource.Info.html#paginate_relationship_with/1)
1362 |
1363 | Pagination configuration for list relationships
1364 |
1365 | [primary\_key\_delimiter(resource)](AshGraphql.Resource.Info.html#primary_key_delimiter/1)
1366 |
1367 | The delimiter for a resource with a composite primary key
1368 |
1369 | [queries(resource, domain\_or\_domains \\\\ \[\])](AshGraphql.Resource.Info.html#queries/2)
1370 |
1371 | The queries exposed for the resource
1372 |
1373 | [relationships(resource)](AshGraphql.Resource.Info.html#relationships/1)
1374 |
1375 | Which relationships should be included in the generated type
1376 |
1377 | [show\_field?(resource, field)](AshGraphql.Resource.Info.html#show_field?/2)
1378 |
1379 | Wether or not a given field will be shown
1380 |
1381 | [show\_fields(resource)](AshGraphql.Resource.Info.html#show_fields/1)
1382 |
1383 | Fields to show in the graphql domain
1384 |
1385 | [subscription\_pubsub(resource)](AshGraphql.Resource.Info.html#subscription_pubsub/1)
1386 |
1387 | The pubsub module used for subscriptions
1388 |
1389 | [subscriptions(resource, domain\_or\_domains \\\\ \[\])](AshGraphql.Resource.Info.html#subscriptions/2)
1390 |
1391 | The subscriptions exposed for the resource
1392 |
1393 | [type(resource)](AshGraphql.Resource.Info.html#type/1)
1394 |
1395 | The graphql type of the resource
1396 |
1397 | # [](AshGraphql.Resource.Info.html#functions)Functions
1398 |
1399 | [](AshGraphql.Resource.Info.html#argument_input_types/1)
1400 |
1401 | # argument\_input\_types(resource)
1402 |
1403 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L194)
1404 |
1405 | Graphql argument type overrides for the resource
1406 |
1407 | [](AshGraphql.Resource.Info.html#argument_names/1)
1408 |
1409 | # argument\_names(resource)
1410 |
1411 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L184)
1412 |
1413 | Graphql argument name overrides for the resource
1414 |
1415 | [](AshGraphql.Resource.Info.html#attribute_input_types/1)
1416 |
1417 | # attribute\_input\_types(resource)
1418 |
1419 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L189)
1420 |
1421 | Graphql attribute input type overrides for the resource
1422 |
1423 | [](AshGraphql.Resource.Info.html#attribute_types/1)
1424 |
1425 | # attribute\_types(resource)
1426 |
1427 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L135)
1428 |
1429 | Graphql type overrides for the resource
1430 |
1431 | [](AshGraphql.Resource.Info.html#derive_filter?/1)
1432 |
1433 | # derive\_filter?(resource)
1434 |
1435 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L125)
1436 |
1437 | Wether or not to derive a filter input for the resource automatically
1438 |
1439 | [](AshGraphql.Resource.Info.html#derive_sort?/1)
1440 |
1441 | # derive\_sort?(resource)
1442 |
1443 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L130)
1444 |
1445 | Wether or not to derive a sort input for the resource automatically
1446 |
1447 | [](AshGraphql.Resource.Info.html#encode_primary_key?/1)
1448 |
1449 | # encode\_primary\_key?(resource)
1450 |
1451 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L60)
1452 |
1453 | Wether or not to encode the primary key as a single `id` field when reading and getting
1454 |
1455 | [](AshGraphql.Resource.Info.html#error_handler/1)
1456 |
1457 | # error\_handler(resource)
1458 |
1459 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L221)
1460 |
1461 | An error handler for errors produced by the resource
1462 |
1463 | [](AshGraphql.Resource.Info.html#field_names/1)
1464 |
1465 | # field\_names(resource)
1466 |
1467 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L150)
1468 |
1469 | Graphql field name (attribute/relationship/calculation/arguments) overrides for the resource
1470 |
1471 | [](AshGraphql.Resource.Info.html#filterable_field?/2)
1472 |
1473 | # filterable\_field?(resource, field\_name)
1474 |
1475 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L214)
1476 |
1477 | May the specified field be filtered on?
1478 |
1479 | [](AshGraphql.Resource.Info.html#filterable_fields/1)
1480 |
1481 | # filterable\_fields(resource)
1482 |
1483 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L209)
1484 |
1485 | Fields that may be filtered on
1486 |
1487 | [](AshGraphql.Resource.Info.html#generate_object?/1)
1488 |
1489 | # generate\_object?(resource)
1490 |
1491 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L204)
1492 |
1493 | Wether or not an object should be generated, or if one with the type name for this resource should be used.
1494 |
1495 | [](AshGraphql.Resource.Info.html#hide_fields/1)
1496 |
1497 | # hide\_fields(resource)
1498 |
1499 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L155)
1500 |
1501 | Fields to hide from the graphql domain
1502 |
1503 | [](AshGraphql.Resource.Info.html#keyset_field/1)
1504 |
1505 | # keyset\_field(resource)
1506 |
1507 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L145)
1508 |
1509 | The field name to place the keyset of a result in
1510 |
1511 | [](AshGraphql.Resource.Info.html#managed_relationship/3)
1512 |
1513 | # managed\_relationship(resource, action, argument)
1514 |
1515 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L74)
1516 |
1517 | The managed\_relationshi configuration for a given action/argument
1518 |
1519 | [](AshGraphql.Resource.Info.html#managed_relationships/1)
1520 |
1521 | # managed\_relationships(resource)
1522 |
1523 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L65)
1524 |
1525 | The managed\_relationship configurations
1526 |
1527 | [](AshGraphql.Resource.Info.html#managed_relationships_auto?/1)
1528 |
1529 | # managed\_relationships\_auto?(resource)
1530 |
1531 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L69)
1532 |
1533 | [](AshGraphql.Resource.Info.html#mutations/2)
1534 |
1535 | # mutations(resource, domain\_or\_domains \\\\ \[])
1536 |
1537 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L23)
1538 |
1539 | The mutations exposed for the resource
1540 |
1541 | [](AshGraphql.Resource.Info.html#nullable_fields/1)
1542 |
1543 | # nullable\_fields(resource)
1544 |
1545 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L140)
1546 |
1547 | Graphql nullability overrides for the resource
1548 |
1549 | [](AshGraphql.Resource.Info.html#paginate_relationship_with/1)
1550 |
1551 | # paginate\_relationship\_with(resource)
1552 |
1553 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L179)
1554 |
1555 | Pagination configuration for list relationships
1556 |
1557 | [](AshGraphql.Resource.Info.html#primary_key_delimiter/1)
1558 |
1559 | # primary\_key\_delimiter(resource)
1560 |
1561 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L199)
1562 |
1563 | The delimiter for a resource with a composite primary key
1564 |
1565 | [](AshGraphql.Resource.Info.html#queries/2)
1566 |
1567 | # queries(resource, domain\_or\_domains \\\\ \[])
1568 |
1569 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L7)
1570 |
1571 | The queries exposed for the resource
1572 |
1573 | [](AshGraphql.Resource.Info.html#relationships/1)
1574 |
1575 | # relationships(resource)
1576 |
1577 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L173)
1578 |
1579 | Which relationships should be included in the generated type
1580 |
1581 | [](AshGraphql.Resource.Info.html#show_field?/2)
1582 |
1583 | # show\_field?(resource, field)
1584 |
1585 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L165)
1586 |
1587 | Wether or not a given field will be shown
1588 |
1589 | [](AshGraphql.Resource.Info.html#show_fields/1)
1590 |
1591 | # show\_fields(resource)
1592 |
1593 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L160)
1594 |
1595 | Fields to show in the graphql domain
1596 |
1597 | [](AshGraphql.Resource.Info.html#subscription_pubsub/1)
1598 |
1599 | # subscription\_pubsub(resource)
1600 |
1601 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L55)
1602 |
1603 | The pubsub module used for subscriptions
1604 |
1605 | [](AshGraphql.Resource.Info.html#subscriptions/2)
1606 |
1607 | # subscriptions(resource, domain\_or\_domains \\\\ \[])
1608 |
1609 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L39)
1610 |
1611 | The subscriptions exposed for the resource
1612 |
1613 | [](AshGraphql.Resource.Info.html#type/1)
1614 |
1615 | # type(resource)
1616 |
1617 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/info.ex#L120)
1618 |
1619 | The graphql type of the resource
1620 |
1621 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1622 |
1623 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1624 | [](https://github.com/ash-project/ash_graphql)
1625 |
1626 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1627 |
1628 | v1.5.0
1629 |
1630 | - GUIDES
1631 | - Modules
1632 | - Mix Tasks
1633 |
1634 | <!--THE END-->
1635 |
1636 | <!--THE END-->
1637 |
1638 | <!--THE END-->
1639 |
1640 | Search documentation of ash\_graphql
1641 |
1642 | Settings
1643 |
1644 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/managed_relationship.ex#L1 "View Source") AshGraphql.Resource.ManagedRelationship (ash\_graphql v1.5.0)
1645 |
1646 | Represents a managed relationship configuration on a mutation
1647 |
1648 | # [](AshGraphql.Resource.ManagedRelationship.html#summary)Summary
1649 |
1650 | ## [Functions](AshGraphql.Resource.ManagedRelationship.html#functions)
1651 |
1652 | [schema()](AshGraphql.Resource.ManagedRelationship.html#schema/0)
1653 |
1654 | # [](AshGraphql.Resource.ManagedRelationship.html#functions)Functions
1655 |
1656 | [](AshGraphql.Resource.ManagedRelationship.html#schema/0)
1657 |
1658 | # schema()
1659 |
1660 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/managed_relationship.ex#L57)
1661 |
1662 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1663 |
1664 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1665 | [](https://github.com/ash-project/ash_graphql)
1666 |
1667 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1668 |
1669 | v1.5.0
1670 |
1671 | - GUIDES
1672 | - Modules
1673 | - Mix Tasks
1674 |
1675 | <!--THE END-->
1676 |
1677 | <!--THE END-->
1678 |
1679 | <!--THE END-->
1680 |
1681 | Search documentation of ash\_graphql
1682 |
1683 | Settings
1684 |
1685 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/mutation.ex#L1 "View Source") AshGraphql.Resource.Mutation (ash\_graphql v1.5.0)
1686 |
1687 | Represents a configured mutation on a resource
1688 |
1689 | # [](AshGraphql.Resource.Mutation.html#summary)Summary
1690 |
1691 | ## [Functions](AshGraphql.Resource.Mutation.html#functions)
1692 |
1693 | [create\_schema()](AshGraphql.Resource.Mutation.html#create_schema/0)
1694 |
1695 | [destroy\_schema()](AshGraphql.Resource.Mutation.html#destroy_schema/0)
1696 |
1697 | [update\_schema()](AshGraphql.Resource.Mutation.html#update_schema/0)
1698 |
1699 | # [](AshGraphql.Resource.Mutation.html#functions)Functions
1700 |
1701 | [](AshGraphql.Resource.Mutation.html#create_schema/0)
1702 |
1703 | # create\_schema()
1704 |
1705 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/mutation.ex#L144)
1706 |
1707 | [](AshGraphql.Resource.Mutation.html#destroy_schema/0)
1708 |
1709 | # destroy\_schema()
1710 |
1711 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/mutation.ex#L146)
1712 |
1713 | [](AshGraphql.Resource.Mutation.html#update_schema/0)
1714 |
1715 | # update\_schema()
1716 |
1717 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/mutation.ex#L145)
1718 |
1719 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1720 |
1721 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1722 | [](https://github.com/ash-project/ash_graphql)
1723 |
1724 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1725 |
1726 | v1.5.0
1727 |
1728 | - GUIDES
1729 | - Modules
1730 | - Mix Tasks
1731 |
1732 | <!--THE END-->
1733 |
1734 | <!--THE END-->
1735 |
1736 | <!--THE END-->
1737 |
1738 | Search documentation of ash\_graphql
1739 |
1740 | Settings
1741 |
1742 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/query.ex#L1 "View Source") AshGraphql.Resource.Query (ash\_graphql v1.5.0)
1743 |
1744 | Represents a configured query on a resource
1745 |
1746 | # [](AshGraphql.Resource.Query.html#summary)Summary
1747 |
1748 | ## [Functions](AshGraphql.Resource.Query.html#functions)
1749 |
1750 | [get\_schema()](AshGraphql.Resource.Query.html#get_schema/0)
1751 |
1752 | [list\_schema()](AshGraphql.Resource.Query.html#list_schema/0)
1753 |
1754 | [read\_one\_schema()](AshGraphql.Resource.Query.html#read_one_schema/0)
1755 |
1756 | # [](AshGraphql.Resource.Query.html#functions)Functions
1757 |
1758 | [](AshGraphql.Resource.Query.html#get_schema/0)
1759 |
1760 | # get\_schema()
1761 |
1762 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/query.ex#L128)
1763 |
1764 | [](AshGraphql.Resource.Query.html#list_schema/0)
1765 |
1766 | # list\_schema()
1767 |
1768 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/query.ex#L130)
1769 |
1770 | [](AshGraphql.Resource.Query.html#read_one_schema/0)
1771 |
1772 | # read\_one\_schema()
1773 |
1774 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/query.ex#L129)
1775 |
1776 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1777 |
1778 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1779 | [](https://github.com/ash-project/ash_graphql)
1780 |
1781 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1782 |
1783 | v1.5.0
1784 |
1785 | - GUIDES
1786 | - Modules
1787 | - Mix Tasks
1788 |
1789 | <!--THE END-->
1790 |
1791 | <!--THE END-->
1792 |
1793 | <!--THE END-->
1794 |
1795 | Search documentation of ash\_graphql
1796 |
1797 | Settings
1798 |
1799 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/subscription.ex#L1 "View Source") AshGraphql.Resource.Subscription (ash\_graphql v1.5.0)
1800 |
1801 | Represents a configured query on a resource
1802 |
1803 | # [](AshGraphql.Resource.Subscription.html#summary)Summary
1804 |
1805 | ## [Functions](AshGraphql.Resource.Subscription.html#functions)
1806 |
1807 | [schema()](AshGraphql.Resource.Subscription.html#schema/0)
1808 |
1809 | # [](AshGraphql.Resource.Subscription.html#functions)Functions
1810 |
1811 | [](AshGraphql.Resource.Subscription.html#schema/0)
1812 |
1813 | # schema()
1814 |
1815 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/subscription.ex#L44)
1816 |
1817 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1818 |
1819 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1820 | [](https://github.com/ash-project/ash_graphql)
1821 |
1822 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1823 |
1824 | v1.5.0
1825 |
1826 | - GUIDES
1827 | - Modules
1828 | - Mix Tasks
1829 |
1830 | <!--THE END-->
1831 |
1832 | <!--THE END-->
1833 |
1834 | <!--THE END-->
1835 |
1836 | Search documentation of ash\_graphql
1837 |
1838 | Settings
1839 |
1840 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/transformers/subscription.ex#L1 "View Source") AshGraphql.Resource.Transformers.Subscription (ash\_graphql v1.5.0)
1841 |
1842 | Adds the notifier for Subscriptions to the Resource
1843 |
1844 | # [](AshGraphql.Resource.Transformers.Subscription.html#summary)Summary
1845 |
1846 | ## [Functions](AshGraphql.Resource.Transformers.Subscription.html#functions)
1847 |
1848 | [after?(\_)](AshGraphql.Resource.Transformers.Subscription.html#after?/1)
1849 |
1850 | Callback implementation for [`Spark.Dsl.Transformer.after?/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:after?/1).
1851 |
1852 | [after\_compile?()](AshGraphql.Resource.Transformers.Subscription.html#after_compile?/0)
1853 |
1854 | Callback implementation for [`Spark.Dsl.Transformer.after_compile?/0`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:after_compile?/0).
1855 |
1856 | [before?(\_)](AshGraphql.Resource.Transformers.Subscription.html#before?/1)
1857 |
1858 | Callback implementation for [`Spark.Dsl.Transformer.before?/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:before?/1).
1859 |
1860 | [transform(dsl)](AshGraphql.Resource.Transformers.Subscription.html#transform/1)
1861 |
1862 | Callback implementation for [`Spark.Dsl.Transformer.transform/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:transform/1).
1863 |
1864 | # [](AshGraphql.Resource.Transformers.Subscription.html#functions)Functions
1865 |
1866 | [](AshGraphql.Resource.Transformers.Subscription.html#after?/1)
1867 |
1868 | # after?(\_)
1869 |
1870 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/transformers/subscription.ex#L6)
1871 |
1872 | Callback implementation for [`Spark.Dsl.Transformer.after?/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:after?/1).
1873 |
1874 | [](AshGraphql.Resource.Transformers.Subscription.html#after_compile?/0)
1875 |
1876 | # after\_compile?()
1877 |
1878 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/transformers/subscription.ex#L6)
1879 |
1880 | Callback implementation for [`Spark.Dsl.Transformer.after_compile?/0`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:after_compile?/0).
1881 |
1882 | [](AshGraphql.Resource.Transformers.Subscription.html#before?/1)
1883 |
1884 | # before?(\_)
1885 |
1886 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/transformers/subscription.ex#L6)
1887 |
1888 | Callback implementation for [`Spark.Dsl.Transformer.before?/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:before?/1).
1889 |
1890 | [](AshGraphql.Resource.Transformers.Subscription.html#transform/1)
1891 |
1892 | # transform(dsl)
1893 |
1894 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/resource/transformers/subscription.ex#L10)
1895 |
1896 | Callback implementation for [`Spark.Dsl.Transformer.transform/1`](../spark/2.2.36/Spark.Dsl.Transformer.html#c:transform/1).
1897 |
1898 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1899 |
1900 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1901 | [](https://github.com/ash-project/ash_graphql)
1902 |
1903 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1904 |
1905 | v1.5.0
1906 |
1907 | - GUIDES
1908 | - Modules
1909 | - Mix Tasks
1910 |
1911 | <!--THE END-->
1912 |
1913 | <!--THE END-->
1914 |
1915 | <!--THE END-->
1916 |
1917 | Search documentation of ash\_graphql
1918 |
1919 | Settings
1920 |
1921 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/actor.ex#L1 "View Source") AshGraphql.Subscription.Actor behaviour (ash\_graphql v1.5.0)
1922 |
1923 | Allows the user to substitue an actor for another more generic actor, this can be used to deduplicate subscription execution
1924 |
1925 | # [](AshGraphql.Subscription.Actor.html#summary)Summary
1926 |
1927 | ## [Callbacks](AshGraphql.Subscription.Actor.html#callbacks)
1928 |
1929 | [actor(actor, opts)](AshGraphql.Subscription.Actor.html#c:actor/2)
1930 |
1931 | # [](AshGraphql.Subscription.Actor.html#callbacks)Callbacks
1932 |
1933 | [](AshGraphql.Subscription.Actor.html#c:actor/2)
1934 |
1935 | # actor(actor, opts)
1936 |
1937 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/actor.ex#L9)
1938 |
1939 | ```
1940 | @callback actor(actor :: any(), opts :: Keyword.t()) :: actor :: any()
1941 | ```
1942 |
1943 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
1944 |
1945 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
1946 | [](https://github.com/ash-project/ash_graphql)
1947 |
1948 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
1949 |
1950 | v1.5.0
1951 |
1952 | - GUIDES
1953 | - Modules
1954 | - Mix Tasks
1955 |
1956 | <!--THE END-->
1957 |
1958 | <!--THE END-->
1959 |
1960 | <!--THE END-->
1961 |
1962 | Search documentation of ash\_graphql
1963 |
1964 | Settings
1965 |
1966 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L1 "View Source") AshGraphql.Subscription.Batcher (ash\_graphql v1.5.0)
1967 |
1968 | If started as a GenServer, this module will batch notifications and send them in bulk. Otherwise, it will send them immediately.
1969 |
1970 | # [](AshGraphql.Subscription.Batcher.html#summary)Summary
1971 |
1972 | ## [Functions](AshGraphql.Subscription.Batcher.html#functions)
1973 |
1974 | [child\_spec(init\_arg)](AshGraphql.Subscription.Batcher.html#child_spec/1)
1975 |
1976 | Returns a specification to start this module under a supervisor.
1977 |
1978 | [drain()](AshGraphql.Subscription.Batcher.html#drain/0)
1979 |
1980 | [handle\_continue(arg, state)](AshGraphql.Subscription.Batcher.html#handle_continue/2)
1981 |
1982 | Callback implementation for [`GenServer.handle_continue/2`](../elixir/GenServer.html#c:handle_continue/2).
1983 |
1984 | [init(config)](AshGraphql.Subscription.Batcher.html#init/1)
1985 |
1986 | Config options
1987 |
1988 | [publish(topic, notification, pubsub, key\_strategy, doc)](AshGraphql.Subscription.Batcher.html#publish/5)
1989 |
1990 | [start\_link(opts \\\\ \[\])](AshGraphql.Subscription.Batcher.html#start_link/1)
1991 |
1992 | # [](AshGraphql.Subscription.Batcher.html#functions)Functions
1993 |
1994 | [](AshGraphql.Subscription.Batcher.html#child_spec/1)
1995 |
1996 | # child\_spec(init\_arg)
1997 |
1998 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L6)
1999 |
2000 | Returns a specification to start this module under a supervisor.
2001 |
2002 | See [`Supervisor`](../elixir/Supervisor.html).
2003 |
2004 | [](AshGraphql.Subscription.Batcher.html#drain/0)
2005 |
2006 | # drain()
2007 |
2008 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L44)
2009 |
2010 | [](AshGraphql.Subscription.Batcher.html#handle_continue/2)
2011 |
2012 | # handle\_continue(arg, state)
2013 |
2014 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L103)
2015 |
2016 | Callback implementation for [`GenServer.handle_continue/2`](../elixir/GenServer.html#c:handle_continue/2).
2017 |
2018 | [](AshGraphql.Subscription.Batcher.html#init/1)
2019 |
2020 | # init(config)
2021 |
2022 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L77)
2023 |
2024 | Config options
2025 |
2026 | `async_limit` (default 100): if there are more than `async_limit` notifications, we will start to backpressure
2027 |
2028 | `send_immediately_threshold` (default 50): if there are less then `send_immediately_threshold` notifications, we will send them immediately
2029 |
2030 | `subscription_batch_interval` (default 1000): the interval in milliseconds the batcher waits for new notifications before sending them
2031 |
2032 | [](AshGraphql.Subscription.Batcher.html#publish/5)
2033 |
2034 | # publish(topic, notification, pubsub, key\_strategy, doc)
2035 |
2036 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L48)
2037 |
2038 | [](AshGraphql.Subscription.Batcher.html#start_link/1)
2039 |
2040 | # start\_link(opts \\\\ \[])
2041 |
2042 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/batcher.ex#L40)
2043 |
2044 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2045 |
2046 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2047 | [](https://github.com/ash-project/ash_graphql)
2048 |
2049 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2050 |
2051 | v1.5.0
2052 |
2053 | - GUIDES
2054 | - Modules
2055 | - Mix Tasks
2056 |
2057 | <!--THE END-->
2058 |
2059 | <!--THE END-->
2060 |
2061 | <!--THE END-->
2062 |
2063 | Search documentation of ash\_graphql
2064 |
2065 | Settings
2066 |
2067 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/config.ex#L1 "View Source") AshGraphql.Subscription.Config (ash\_graphql v1.5.0)
2068 |
2069 | Creates a config function used for the absinthe subscription definition
2070 |
2071 | See [https://github.com/absinthe-graphql/absinthe/blob/3d0823bd71c2ebb94357a5588c723e053de8c66a/lib/absinthe/schema/notation.ex#L58](https://github.com/absinthe-graphql/absinthe/blob/3d0823bd71c2ebb94357a5588c723e053de8c66a/lib/absinthe/schema/notation.ex#L58)
2072 |
2073 | # [](AshGraphql.Subscription.Config.html#summary)Summary
2074 |
2075 | ## [Functions](AshGraphql.Subscription.Config.html#functions)
2076 |
2077 | [create\_config(subscription, domain, resource)](AshGraphql.Subscription.Config.html#create_config/3)
2078 |
2079 | # [](AshGraphql.Subscription.Config.html#functions)Functions
2080 |
2081 | [](AshGraphql.Subscription.Config.html#create_config/3)
2082 |
2083 | # create\_config(subscription, domain, resource)
2084 |
2085 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/config.ex#L10)
2086 |
2087 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2088 |
2089 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2090 | [](https://github.com/ash-project/ash_graphql)
2091 |
2092 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2093 |
2094 | v1.5.0
2095 |
2096 | - GUIDES
2097 | - Modules
2098 | - Mix Tasks
2099 |
2100 | <!--THE END-->
2101 |
2102 | <!--THE END-->
2103 |
2104 | <!--THE END-->
2105 |
2106 | Search documentation of ash\_graphql
2107 |
2108 | Settings
2109 |
2110 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/endpoint.ex#L1 "View Source") AshGraphql.Subscription.Endpoint (ash\_graphql v1.5.0)
2111 |
2112 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2113 |
2114 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2115 | [](https://github.com/ash-project/ash_graphql)
2116 |
2117 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2118 |
2119 | v1.5.0
2120 |
2121 | - GUIDES
2122 | - Modules
2123 | - Mix Tasks
2124 |
2125 | <!--THE END-->
2126 |
2127 | <!--THE END-->
2128 |
2129 | <!--THE END-->
2130 |
2131 | Search documentation of ash\_graphql
2132 |
2133 | Settings
2134 |
2135 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscriptions.ex#L1 "View Source") AshGraphql.Subscription (ash\_graphql v1.5.0)
2136 |
2137 | Helpers for working with absinthe subscriptions
2138 |
2139 | # [](AshGraphql.Subscription.html#summary)Summary
2140 |
2141 | ## [Functions](AshGraphql.Subscription.html#functions)
2142 |
2143 | [query\_for\_subscription(query, domain, resolution, type\_override \\\\ nil, nested \\\\ \[\])](AshGraphql.Subscription.html#query_for_subscription/5)
2144 |
2145 | Produce a query that will load the correct data for a subscription.
2146 |
2147 | # [](AshGraphql.Subscription.html#functions)Functions
2148 |
2149 | [](AshGraphql.Subscription.html#query_for_subscription/5)
2150 |
2151 | # query\_for\_subscription(query, domain, resolution, type\_override \\\\ nil, nested \\\\ \[])
2152 |
2153 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscriptions.ex#L11)
2154 |
2155 | Produce a query that will load the correct data for a subscription.
2156 |
2157 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2158 |
2159 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2160 | [](https://github.com/ash-project/ash_graphql)
2161 |
2162 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2163 |
2164 | v1.5.0
2165 |
2166 | - GUIDES
2167 | - Modules
2168 | - Mix Tasks
2169 |
2170 | <!--THE END-->
2171 |
2172 | <!--THE END-->
2173 |
2174 | <!--THE END-->
2175 |
2176 | Search documentation of ash\_graphql
2177 |
2178 | Settings
2179 |
2180 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/notifier.ex#L1 "View Source") AshGraphql.Subscription.Notifier (ash\_graphql v1.5.0)
2181 |
2182 | AshNotifier that triggers absinthe if subscriptions are listening
2183 |
2184 | # [](AshGraphql.Subscription.Notifier.html#summary)Summary
2185 |
2186 | ## [Functions](AshGraphql.Subscription.Notifier.html#functions)
2187 |
2188 | [requires\_original\_data?(\_, \_)](AshGraphql.Subscription.Notifier.html#requires_original_data?/2)
2189 |
2190 | Callback implementation for [`Ash.Notifier.requires_original_data?/2`](../ash/3.4.50/Ash.Notifier.html#c:requires_original_data?/2).
2191 |
2192 | # [](AshGraphql.Subscription.Notifier.html#functions)Functions
2193 |
2194 | [](AshGraphql.Subscription.Notifier.html#requires_original_data?/2)
2195 |
2196 | # requires\_original\_data?(\_, \_)
2197 |
2198 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/notifier.ex#L5)
2199 |
2200 | Callback implementation for [`Ash.Notifier.requires_original_data?/2`](../ash/3.4.50/Ash.Notifier.html#c:requires_original_data?/2).
2201 |
2202 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2203 |
2204 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2205 | [](https://github.com/ash-project/ash_graphql)
2206 |
2207 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2208 |
2209 | v1.5.0
2210 |
2211 | - GUIDES
2212 | - Modules
2213 | - Mix Tasks
2214 |
2215 | <!--THE END-->
2216 |
2217 | <!--THE END-->
2218 |
2219 | <!--THE END-->
2220 |
2221 | Search documentation of ash\_graphql
2222 |
2223 | Settings
2224 |
2225 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/runner.ex#L1 "View Source") AshGraphql.Subscription.Runner (ash\_graphql v1.5.0)
2226 |
2227 | Custom implementation if the run\_docset function for the PubSub module used for Subscriptions
2228 |
2229 | Mostly a copy of [https://github.com/absinthe-graphql/absinthe/blob/3d0823bd71c2ebb94357a5588c723e053de8c66a/lib/absinthe/subscription/local.ex#L40](https://github.com/absinthe-graphql/absinthe/blob/3d0823bd71c2ebb94357a5588c723e053de8c66a/lib/absinthe/subscription/local.ex#L40) but this lets us decide if we want to send the data to the client or not in certain error cases
2230 |
2231 | # [](AshGraphql.Subscription.Runner.html#summary)Summary
2232 |
2233 | ## [Functions](AshGraphql.Subscription.Runner.html#functions)
2234 |
2235 | [run\_docset(pubsub, docs\_and\_topics, notification)](AshGraphql.Subscription.Runner.html#run_docset/3)
2236 |
2237 | # [](AshGraphql.Subscription.Runner.html#functions)Functions
2238 |
2239 | [](AshGraphql.Subscription.Runner.html#run_docset/3)
2240 |
2241 | # run\_docset(pubsub, docs\_and\_topics, notification)
2242 |
2243 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/subscription/runner.ex#L10)
2244 |
2245 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2246 |
2247 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2248 | [](https://github.com/ash-project/ash_graphql)
2249 |
2250 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2251 |
2252 | v1.5.0
2253 |
2254 | - GUIDES
2255 | - Modules
2256 | - Mix Tasks
2257 |
2258 | <!--THE END-->
2259 |
2260 | <!--THE END-->
2261 |
2262 | <!--THE END-->
2263 |
2264 | Search documentation of ash\_graphql
2265 |
2266 | Settings
2267 |
2268 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L1 "View Source") AshGraphql.Type behaviour (ash\_graphql v1.5.0)
2269 |
2270 | Callbacks used to enrich types with GraphQL-specific metadata.
2271 |
2272 | # [](AshGraphql.Type.html#summary)Summary
2273 |
2274 | ## [Callbacks](AshGraphql.Type.html#callbacks)
2275 |
2276 | [graphql\_define\_type?(constraints)](AshGraphql.Type.html#c:graphql_define_type?/1)
2277 |
2278 | Used for maps/enums/unions that *would* define a type automatically, to disable them.
2279 |
2280 | [graphql\_describe\_enum\_value(atom)](AshGraphql.Type.html#c:graphql_describe_enum_value/1)
2281 |
2282 | Used for [`Ash.Type.Enum`](../ash/3.4.50/Ash.Type.Enum.html) to provide a description for individual values. For example
2283 |
2284 | [graphql\_input\_type(constraints)](AshGraphql.Type.html#c:graphql_input_type/1)
2285 |
2286 | Sets the name of the graphql input type for a given Ash type. For example: `:weekday`.
2287 |
2288 | [graphql\_rename\_value(constraints)](AshGraphql.Type.html#c:graphql_rename_value/1)
2289 |
2290 | Used for [`Ash.Type.Enum`](../ash/3.4.50/Ash.Type.Enum.html) to rename individual values. For example
2291 |
2292 | [graphql\_type(constraints)](AshGraphql.Type.html#c:graphql_type/1)
2293 |
2294 | Sets the name of the graphql type for a given Ash type. For example: `:weekday`.
2295 |
2296 | [graphql\_unnested\_unions(constraints)](AshGraphql.Type.html#c:graphql_unnested_unions/1)
2297 |
2298 | Used for map/embedded types embedded in unions, to avoid nesting them in a key by their name.
2299 |
2300 | # [](AshGraphql.Type.html#callbacks)Callbacks
2301 |
2302 | [](AshGraphql.Type.html#c:graphql_define_type?/1)
2303 |
2304 | # graphql\_define\_type?(constraints)
2305 |
2306 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L68)(optional)
2307 |
2308 | ```
2309 | @callback graphql_define_type?(Ash.Type.constraints()) :: false
2310 | ```
2311 |
2312 | Used for maps/enums/unions that *would* define a type automatically, to disable them.
2313 |
2314 | [](AshGraphql.Type.html#c:graphql_describe_enum_value/1)
2315 |
2316 | # graphql\_describe\_enum\_value(atom)
2317 |
2318 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L82)(optional)
2319 |
2320 | ```
2321 | @callback graphql_describe_enum_value(atom()) :: String.t() | nil
2322 | ```
2323 |
2324 | Used for [`Ash.Type.Enum`](../ash/3.4.50/Ash.Type.Enum.html) to provide a description for individual values. For example:
2325 |
2326 | ```
2327 | defmodule MyEnum do
2328 | use Ash.Type.Enum, values: [:foo, :bar, :baz]
2329 |
2330 | def graphql_describe_enum_value(:baz), do: "A baz"
2331 | def graphql_describe_enum_value(_), do: nil
2332 | end
2333 | ```
2334 |
2335 | [](AshGraphql.Type.html#c:graphql_input_type/1)
2336 |
2337 | # graphql\_input\_type(constraints)
2338 |
2339 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L42)(optional)
2340 |
2341 | ```
2342 | @callback graphql_input_type(Ash.Type.constraints()) :: atom()
2343 | ```
2344 |
2345 | Sets the name of the graphql input type for a given Ash type. For example: `:weekday`.
2346 |
2347 | This will do different things depending on the type you're adding it to.
2348 |
2349 | ## [](AshGraphql.Type.html#c:graphql_input_type/1-regular-types)Regular Types
2350 |
2351 | This expresses that you will define a custom type for representing this input in your graphql
2352 |
2353 | ## [](AshGraphql.Type.html#c:graphql_input_type/1-newtypes)NewTypes
2354 |
2355 | If it is a subtype of a union, or map/keyword with `fields` the type will be *created* with that name. So you can use this to decide what it will be named. Otherwise, it behaves as stated above for regular types.
2356 |
2357 | [](AshGraphql.Type.html#c:graphql_rename_value/1)
2358 |
2359 | # graphql\_rename\_value(constraints)
2360 |
2361 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L56)(optional)
2362 |
2363 | ```
2364 | @callback graphql_rename_value(Ash.Type.constraints()) :: String.t() | atom()
2365 | ```
2366 |
2367 | Used for [`Ash.Type.Enum`](../ash/3.4.50/Ash.Type.Enum.html) to rename individual values. For example:
2368 |
2369 | ```
2370 | defmodule MyEnum do
2371 | use Ash.Type.Enum, values: [:foo, :bar, :baz]
2372 |
2373 | def graphql_rename_value(:baz), do: :buz
2374 | def graphql_rename_value(other), do: other
2375 | end
2376 | ```
2377 |
2378 | [](AshGraphql.Type.html#c:graphql_type/1)
2379 |
2380 | # graphql\_type(constraints)
2381 |
2382 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L26)(optional)
2383 |
2384 | ```
2385 | @callback graphql_type(Ash.Type.constraints()) :: atom()
2386 | ```
2387 |
2388 | Sets the name of the graphql type for a given Ash type. For example: `:weekday`.
2389 |
2390 | This will do different things depending on the type you're adding it to.
2391 |
2392 | ## [](AshGraphql.Type.html#c:graphql_type/1-regular-types)Regular Types
2393 |
2394 | This expresses that you will define a custom type for representing this in your graphql
2395 |
2396 | ## [](AshGraphql.Type.html#c:graphql_type/1-newtypes)NewTypes
2397 |
2398 | If it is a subtype of a union, or map/keyword with `fields` the type will be *created* with that name. So you can use this to decide what it will be named. Otherwise, it behaves as stated above for regular types.
2399 |
2400 | [](AshGraphql.Type.html#c:graphql_unnested_unions/1)
2401 |
2402 | # graphql\_unnested\_unions(constraints)
2403 |
2404 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/type.ex#L63)(optional)
2405 |
2406 | ```
2407 | @callback graphql_unnested_unions(Ash.Type.constraints()) :: [atom()]
2408 | ```
2409 |
2410 | Used for map/embedded types embedded in unions, to avoid nesting them in a key by their name.
2411 |
2412 | See [the unions guide](use-unions-with-graphql.html) for more.
2413 |
2414 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2415 |
2416 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2417 | [](https://github.com/ash-project/ash_graphql)
2418 |
2419 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2420 |
2421 | v1.5.0
2422 |
2423 | - GUIDES
2424 | - Modules
2425 | - Mix Tasks
2426 |
2427 | <!--THE END-->
2428 |
2429 | <!--THE END-->
2430 |
2431 | <!--THE END-->
2432 |
2433 | Search documentation of ash\_graphql
2434 |
2435 | Settings
2436 |
2437 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json.ex#L1 "View Source") AshGraphql.Types.JSON (ash\_graphql v1.5.0)
2438 |
2439 | The Json scalar type allows arbitrary JSON values to be passed in and out.
2440 |
2441 | # [](AshGraphql.Types.JSON.html#summary)Summary
2442 |
2443 | ## [Functions](AshGraphql.Types.JSON.html#functions)
2444 |
2445 | [decode(arg1)](AshGraphql.Types.JSON.html#decode/1)
2446 |
2447 | [encode(value)](AshGraphql.Types.JSON.html#encode/1)
2448 |
2449 | # [](AshGraphql.Types.JSON.html#functions)Functions
2450 |
2451 | [](AshGraphql.Types.JSON.html#decode/1)
2452 |
2453 | # decode(arg1)
2454 |
2455 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json.ex#L18)
2456 |
2457 | [](AshGraphql.Types.JSON.html#encode/1)
2458 |
2459 | # encode(value)
2460 |
2461 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json.ex#L33)
2462 |
2463 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2464 |
2465 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2466 | [](https://github.com/ash-project/ash_graphql)
2467 |
2468 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2469 |
2470 | v1.5.0
2471 |
2472 | - GUIDES
2473 | - Modules
2474 | - Mix Tasks
2475 |
2476 | <!--THE END-->
2477 |
2478 | <!--THE END-->
2479 |
2480 | <!--THE END-->
2481 |
2482 | Search documentation of ash\_graphql
2483 |
2484 | Settings
2485 |
2486 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json_string.ex#L1 "View Source") AshGraphql.Types.JSONString (ash\_graphql v1.5.0)
2487 |
2488 | The Json scalar type allows arbitrary JSON values to be passed in and out.
2489 |
2490 | # [](AshGraphql.Types.JSONString.html#summary)Summary
2491 |
2492 | ## [Functions](AshGraphql.Types.JSONString.html#functions)
2493 |
2494 | [decode(arg1)](AshGraphql.Types.JSONString.html#decode/1)
2495 |
2496 | [encode(value)](AshGraphql.Types.JSONString.html#encode/1)
2497 |
2498 | # [](AshGraphql.Types.JSONString.html#functions)Functions
2499 |
2500 | [](AshGraphql.Types.JSONString.html#decode/1)
2501 |
2502 | # decode(arg1)
2503 |
2504 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json_string.ex#L18)
2505 |
2506 | [](AshGraphql.Types.JSONString.html#encode/1)
2507 |
2508 | # encode(value)
2509 |
2510 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/types/json_string.ex#L33)
2511 |
2512 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2513 |
2514 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2515 | [](https://github.com/ash-project/ash_graphql)
2516 |
2517 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2518 |
2519 | v1.5.0
2520 |
2521 | - GUIDES
2522 | - Modules
2523 | - Mix Tasks
2524 |
2525 | <!--THE END-->
2526 |
2527 | <!--THE END-->
2528 |
2529 | <!--THE END-->
2530 |
2531 | Search documentation of ash\_graphql
2532 |
2533 | Settings
2534 |
2535 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/authorize-with-graphql.md#L1 "View Source") Authorize with GraphQL
2536 |
2537 | AshGraphql uses three special keys in the `absinthe` context:
2538 |
2539 | - `:actor` - the current actor, to be used for authorization/preparations/changes
2540 | - `:tenant` - a tenant when using [multitenancy](../ash/multitenancy.html).
2541 | - `:ash_context` - a map of arbitrary context to be passed into the changeset/query. Accessible via `changeset.context` and `query.context`
2542 |
2543 | By default, `authorize?` in the domain is set to true. To disable authorization for a given domain in graphql, use:
2544 |
2545 | ```
2546 | graphql do
2547 | authorize? false
2548 | end
2549 | ```
2550 |
2551 | If you are doing authorization, you'll need to provide an `actor`.
2552 |
2553 | ### [](authorize-with-graphql.html#using-ashauthentication)Using AshAuthentication
2554 |
2555 | If you have not yet installed AshAuthentication, you can install it with igniter:
2556 |
2557 | ```
2558 | # installs ash_authentication & ash_authentication_phoenix
2559 | mix igniter.install ash_authentication_phoenix
2560 | ```
2561 |
2562 | If you've already set up [`AshGraphql`](AshGraphql.html) before adding `AshAuthentication`, you will just need to make sure that your `:graphql` scope in your router looks like this:
2563 |
2564 | ```
2565 | pipeline :graphql do
2566 | plug :load_from_bearer
2567 | plug :set_actor, :user
2568 | plug AshGraphql.Plug
2569 | end
2570 | ```
2571 |
2572 | ### [](authorize-with-graphql.html#using-something-else)Using Something Else
2573 |
2574 | To set the `actor` for authorization, you'll need to add an `actor` key to the absinthe context. Typically, you would have a plug that fetches the current user and uses [`Ash.PlugHelpers.set_actor/2`](../ash/3.4.50/Ash.PlugHelpers.html#set_actor/2) to set the actor in the `conn` (likewise with [`Ash.PlugHelpers.set_tenant/2`](../ash/3.4.50/Ash.PlugHelpers.html#set_tenant/2)).
2575 |
2576 | Just add [`AshGraphql.Plug`](AshGraphql.Plug.html) somewhere *after* that in the pipeline and the your GraphQL APIs will have the correct authorization.
2577 |
2578 | ```
2579 | defmodule MyAppWeb.Router do
2580 | pipeline :api do
2581 | # ...
2582 | plug :get_actor_from_token
2583 | plug AshGraphql.Plug
2584 | end
2585 |
2586 | scope "/" do
2587 | forward "/gql", Absinthe.Plug, schema: YourSchema
2588 |
2589 | forward "/playground",
2590 | Absinthe.Plug.GraphiQL,
2591 | schema: YourSchema,
2592 | interface: :playground
2593 | end
2594 |
2595 | def get_actor_from_token(conn, _opts) do
2596 | with ["" <> token] <- get_req_header(conn, "authorization"),
2597 | {:ok, user, _claims} <- MyApp.Guardian.resource_from_token(token) do
2598 | conn
2599 | |> set_actor(user)
2600 | else
2601 | _ -> conn
2602 | end
2603 | end
2604 | end
2605 | ```
2606 |
2607 | ## [](authorize-with-graphql.html#policy-breakdowns)Policy Breakdowns
2608 |
2609 | By default, unauthorized requests simply return `forbidden` in the message. If you prefer to show policy breakdowns in your GraphQL errors, you can set the config option:
2610 |
2611 | ```
2612 | config :ash_graphql, :policies, show_policy_breakdowns?: true
2613 | ```
2614 |
2615 | ```
2616 | {
2617 | "data": {
2618 | "attendanceRecords": null
2619 | },
2620 | "errors": [
2621 | {
2622 | "code": "forbidden",
2623 | "fields": [],
2624 | "locations": [
2625 | {
2626 | "column": 3,
2627 | "line": 2
2628 | }
2629 | ],
2630 | "message": "MyApp.Authentication.User.read\n\n\n\n\nPolicy Breakdown\n Policy | ⛔:\n forbid unless: actor is active | ✓ | ⬇ \n authorize if: actor is Executive | ✘ | ⬇",
2631 | "path": ["attendanceRecords"],
2632 | "short_message": "forbidden",
2633 | "vars": {}
2634 | }
2635 | ]
2636 | }
2637 | ```
2638 |
2639 | Be careful, as this can be an attack vector in some systems (i.e "here is exactly what you need to make true to do what you want to do").
2640 |
2641 | ## [](authorize-with-graphql.html#field-policies)Field Policies
2642 |
2643 | Field policies in AshGraphql work by producing a `null` value for any forbidden field, as well as an error in the errors list.
2644 |
2645 | ### [](authorize-with-graphql.html#nullability)nullability
2646 |
2647 | Any fields with field policies on them should be nullable. If they are not nullable, the *parent* object will also be `null` (and considered in an error state), because `null` is not a valid type for that field.
2648 |
2649 | To make fields as nullable even if it is not nullable by its definition, use the `nullable_fields` option.
2650 |
2651 | ```
2652 | graphql do
2653 | type :post
2654 |
2655 | nullable_fields [:foo, :bar, :baz]
2656 | end
2657 | ```
2658 |
2659 | [← Previous Page Getting Started With GraphQL](getting-started-with-graphql.html)
2660 |
2661 | [Next Page → Handling Errors](handle-errors.html)
2662 |
2663 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/authorize-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2664 |
2665 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2666 | [](https://github.com/ash-project/ash_graphql)
2667 |
2668 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2669 |
2670 | v1.5.0
2671 |
2672 | - GUIDES
2673 | - Modules
2674 | - Mix Tasks
2675 |
2676 | <!--THE END-->
2677 |
2678 | <!--THE END-->
2679 |
2680 | <!--THE END-->
2681 |
2682 | Search documentation of ash\_graphql
2683 |
2684 | Settings
2685 |
2686 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/custom-queries-and-mutations.md#L1 "View Source") Custom Queries & Mutations
2687 |
2688 | You can define your own queries and mutations in your schema, using Absinthe's tooling. See their docs for more.
2689 |
2690 | ### [](custom-queries-and-mutations.html#you-probably-don-t-need-this)You probably don't need this!
2691 |
2692 | You can define generic actions in your resources which can return any type that you want, and those generic actions will automatically get all of the goodness of AshGraphql, with automatic data loading and type derivation, etc. See the [generic actions guide](generic-actions.html) for more.
2693 |
2694 | ## [](custom-queries-and-mutations.html#using-ashgraphql-s-types)Using AshGraphql's types
2695 |
2696 | If you want to return resource types defined by AshGraphql, however, you will need to use [`AshGraphql.load_fields_on_query/2`](AshGraphql.html#load_fields_on_query/2) to ensure that any requested fields are loaded.
2697 |
2698 | For example:
2699 |
2700 | ```
2701 | require Ash.Query
2702 |
2703 | query do
2704 | field :custom_get_post, :post do
2705 | arg(:id, non_null(:id))
2706 |
2707 | resolve(fn %{id: post_id}, resolution ->
2708 | MyApp.Blog.Post
2709 | |> Ash.Query.filter(id == ^post_id)
2710 | |> AshGraphql.load_fields_on_query(resolution)
2711 | |> Ash.read_one(not_found_error?: true)
2712 | |> AshGraphql.handle_errors(MyApp.Blog.Post, resolution)
2713 | end)
2714 | end
2715 | end
2716 | ```
2717 |
2718 | Alternatively, if you have records already that you need to load data on, use [`AshGraphql.load_fields/3`](AshGraphql.html#load_fields/3):
2719 |
2720 | ```
2721 | query do
2722 | field :custom_get_post, :post do
2723 | arg(:id, non_null(:id))
2724 |
2725 | resolve(fn %{id: post_id}, resolution ->
2726 | with {:ok, post} when not is_nil(post) <- Ash.get(MyApp.Blog.Post, post_id) do
2727 | AshGraphql.load_fields(post, MyApp.Blog.Post, resolution)
2728 | end
2729 | |> AshGraphql.handle_errors(MyApp.Blog.Post, resolution)
2730 | end)
2731 | end
2732 | end
2733 | ```
2734 |
2735 | [← Previous Page Relay](relay.html)
2736 |
2737 | [Next Page → Upgrading to 1.0](upgrade.html)
2738 |
2739 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/custom-queries-and-mutations.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
2740 |
2741 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
2742 | [](https://github.com/ash-project/ash_graphql)
2743 |
2744 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
2745 |
2746 | v1.5.0
2747 |
2748 | - GUIDES
2749 | - Modules
2750 | - Mix Tasks
2751 |
2752 | <!--THE END-->
2753 |
2754 | <!--THE END-->
2755 |
2756 | <!--THE END-->
2757 |
2758 | Search documentation of ash\_graphql
2759 |
2760 | Settings
2761 |
2762 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/dsls/DSL-AshGraphql.Domain.md#L1 "View Source") DSL: AshGraphql.Domain
2763 |
2764 | The entrypoint for adding GraphQL behavior to an Ash domain
2765 |
2766 | ## [](dsl-ashgraphql-domain.html#graphql)graphql
2767 |
2768 | Domain level configuration for GraphQL
2769 |
2770 | ### [](dsl-ashgraphql-domain.html#nested-dsls)Nested DSLs
2771 |
2772 | - [queries](dsl-ashgraphql-domain.html#graphql-queries)
2773 |
2774 | - get
2775 | - read\_one
2776 | - list
2777 | - action
2778 | - [mutations](dsl-ashgraphql-domain.html#graphql-mutations)
2779 |
2780 | - create
2781 | - update
2782 | - destroy
2783 | - action
2784 | - [subscriptions](dsl-ashgraphql-domain.html#graphql-subscriptions)
2785 |
2786 | - subscribe
2787 |
2788 | ### [](dsl-ashgraphql-domain.html#examples)Examples
2789 |
2790 | ```
2791 | graphql do
2792 | authorize? false # To skip authorization for this domain
2793 | end
2794 | ```
2795 |
2796 | ### [](dsl-ashgraphql-domain.html#options)Options
2797 |
2798 | NameTypeDefaultDocs[`authorize?`](dsl-ashgraphql-domain.html#graphql-authorize?)`boolean``true`Whether or not to perform authorization for this domain[`tracer`](dsl-ashgraphql-domain.html#graphql-tracer)`atom`A tracer to use to trace execution in the graphql. Will use `config :ash, :tracer` if it is set.[`root_level_errors?`](dsl-ashgraphql-domain.html#graphql-root_level_errors?)`boolean``false`By default, mutation errors are shown in their result object's errors key, but this setting places those errors in the top level errors list[`error_handler`](dsl-ashgraphql-domain.html#graphql-error_handler)`mfa``{AshGraphql.DefaultErrorHandler, :handle_error, []}`Set an MFA to intercept/handle any errors that are generated.[`show_raised_errors?`](dsl-ashgraphql-domain.html#graphql-show_raised_errors?)`boolean``false`For security purposes, if an error is *raised* then Ash simply shows a generic error. If you want to show those errors, set this to true.
2799 |
2800 | ## [](dsl-ashgraphql-domain.html#graphql-queries)graphql.queries
2801 |
2802 | Queries to expose for the resource.
2803 |
2804 | ### [](dsl-ashgraphql-domain.html#nested-dsls-1)Nested DSLs
2805 |
2806 | - [get](dsl-ashgraphql-domain.html#graphql-queries-get)
2807 | - [read\_one](dsl-ashgraphql-domain.html#graphql-queries-read_one)
2808 | - [list](dsl-ashgraphql-domain.html#graphql-queries-list)
2809 | - [action](dsl-ashgraphql-domain.html#graphql-queries-action)
2810 |
2811 | ### [](dsl-ashgraphql-domain.html#examples-1)Examples
2812 |
2813 | ```
2814 | queries do
2815 | get Post, :get_post, :read
2816 | read_one User, :current_user, :current_user
2817 | list Post, :list_posts, :read
2818 | end
2819 | ```
2820 |
2821 | ## [](dsl-ashgraphql-domain.html#graphql-queries-get)graphql.queries.get
2822 |
2823 | ```
2824 | get resource, name, action
2825 | ```
2826 |
2827 | A query to fetch a record by primary key
2828 |
2829 | ### [](dsl-ashgraphql-domain.html#examples-2)Examples
2830 |
2831 | ```
2832 | get :get_post, :read
2833 | ```
2834 |
2835 | ### [](dsl-ashgraphql-domain.html#arguments)Arguments
2836 |
2837 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-queries-get-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-queries-get-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-domain.html#graphql-queries-get-action)`atom`The action to use for the query.
2838 |
2839 | ### [](dsl-ashgraphql-domain.html#options-1)Options
2840 |
2841 | NameTypeDefaultDocs[`identity`](dsl-ashgraphql-domain.html#graphql-queries-get-identity)`atom`The identity to use for looking up the record. Pass `false` to not use an identity.[`allow_nil?`](dsl-ashgraphql-domain.html#graphql-queries-get-allow_nil?)`boolean``true`Whether or not the action can return nil.[`modify_resolution`](dsl-ashgraphql-domain.html#graphql-queries-get-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`type_name`](dsl-ashgraphql-domain.html#graphql-queries-get-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-domain.html#graphql-queries-get-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-domain.html#graphql-queries-get-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-domain.html#graphql-queries-get-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-domain.html#graphql-queries-get-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-domain.html#graphql-queries-get-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-queries-get-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-queries-get-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
2842 |
2843 | ### [](dsl-ashgraphql-domain.html#introspection)Introspection
2844 |
2845 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
2846 |
2847 | ## [](dsl-ashgraphql-domain.html#graphql-queries-read_one)graphql.queries.read\_one
2848 |
2849 | ```
2850 | read_one resource, name, action
2851 | ```
2852 |
2853 | A query to fetch a record
2854 |
2855 | ### [](dsl-ashgraphql-domain.html#examples-3)Examples
2856 |
2857 | ```
2858 | read_one :current_user, :current_user
2859 | ```
2860 |
2861 | ### [](dsl-ashgraphql-domain.html#arguments-1)Arguments
2862 |
2863 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-queries-read_one-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-queries-read_one-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-domain.html#graphql-queries-read_one-action)`atom`The action to use for the query.
2864 |
2865 | ### [](dsl-ashgraphql-domain.html#options-2)Options
2866 |
2867 | NameTypeDefaultDocs[`allow_nil?`](dsl-ashgraphql-domain.html#graphql-queries-read_one-allow_nil?)`boolean``true`Whether or not the action can return nil.[`type_name`](dsl-ashgraphql-domain.html#graphql-queries-read_one-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-domain.html#graphql-queries-read_one-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-domain.html#graphql-queries-read_one-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-domain.html#graphql-queries-read_one-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-domain.html#graphql-queries-read_one-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-domain.html#graphql-queries-read_one-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-queries-read_one-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-queries-read_one-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
2868 |
2869 | ### [](dsl-ashgraphql-domain.html#introspection-1)Introspection
2870 |
2871 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
2872 |
2873 | ## [](dsl-ashgraphql-domain.html#graphql-queries-list)graphql.queries.list
2874 |
2875 | ```
2876 | list resource, name, action
2877 | ```
2878 |
2879 | A query to fetch a list of records
2880 |
2881 | ### [](dsl-ashgraphql-domain.html#examples-4)Examples
2882 |
2883 | ```
2884 | list :list_posts, :read
2885 | ```
2886 |
2887 | ```
2888 | list :list_posts_paginated, :read, relay?: true
2889 | ```
2890 |
2891 | ### [](dsl-ashgraphql-domain.html#arguments-2)Arguments
2892 |
2893 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-queries-list-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-queries-list-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-domain.html#graphql-queries-list-action)`atom`The action to use for the query.
2894 |
2895 | ### [](dsl-ashgraphql-domain.html#options-3)Options
2896 |
2897 | NameTypeDefaultDocs[`relay?`](dsl-ashgraphql-domain.html#graphql-queries-list-relay?)`boolean``false`If true, the graphql queries/resolvers for this resource will be built to honor the relay specification. See [the relay guide](https://hexdocs.pm/documentation/topics/relay.html) for more.[`paginate_with`](dsl-ashgraphql-domain.html#graphql-queries-list-paginate_with)`:keyset | :offset | nil``:keyset`Determine the pagination strategy to use, if multiple are available. If `nil`, no pagination is applied, otherwise the given strategy is used.[`type_name`](dsl-ashgraphql-domain.html#graphql-queries-list-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-domain.html#graphql-queries-list-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-domain.html#graphql-queries-list-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-domain.html#graphql-queries-list-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-domain.html#graphql-queries-list-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-domain.html#graphql-queries-list-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-queries-list-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-queries-list-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
2898 |
2899 | ### [](dsl-ashgraphql-domain.html#introspection-2)Introspection
2900 |
2901 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
2902 |
2903 | ## [](dsl-ashgraphql-domain.html#graphql-queries-action)graphql.queries.action
2904 |
2905 | ```
2906 | action resource, name, action
2907 | ```
2908 |
2909 | Runs a generic action
2910 |
2911 | ### [](dsl-ashgraphql-domain.html#examples-5)Examples
2912 |
2913 | ```
2914 | action :check_status, :check_status
2915 | ```
2916 |
2917 | ### [](dsl-ashgraphql-domain.html#arguments-3)Arguments
2918 |
2919 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-queries-action-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-queries-action-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-domain.html#graphql-queries-action-action)`atom`The action to use for the query.
2920 |
2921 | ### [](dsl-ashgraphql-domain.html#options-4)Options
2922 |
2923 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-domain.html#graphql-queries-action-description)`String.t`The description that gets shown in the Graphql schema. If not provided, the action description will be used.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-queries-action-hide_inputs)`list(atom)``[]`Inputs to hide in the mutation/query[`error_location`](dsl-ashgraphql-domain.html#graphql-queries-action-error_location)`:in_result | :top_level``:top_level`If the result should have an `errors` and a `result` key (like create/update/destroy mutations), or if errors should be shown in the top level errors key[`modify_resolution`](dsl-ashgraphql-domain.html#graphql-queries-action-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-queries-action-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
2924 |
2925 | ### [](dsl-ashgraphql-domain.html#introspection-3)Introspection
2926 |
2927 | Target: [`AshGraphql.Resource.Action`](AshGraphql.Resource.Action.html)
2928 |
2929 | ## [](dsl-ashgraphql-domain.html#graphql-mutations)graphql.mutations
2930 |
2931 | Mutations (create/update/destroy actions) to expose for the resource.
2932 |
2933 | ### [](dsl-ashgraphql-domain.html#nested-dsls-2)Nested DSLs
2934 |
2935 | - [create](dsl-ashgraphql-domain.html#graphql-mutations-create)
2936 | - [update](dsl-ashgraphql-domain.html#graphql-mutations-update)
2937 | - [destroy](dsl-ashgraphql-domain.html#graphql-mutations-destroy)
2938 | - [action](dsl-ashgraphql-domain.html#graphql-mutations-action)
2939 |
2940 | ### [](dsl-ashgraphql-domain.html#examples-6)Examples
2941 |
2942 | ```
2943 | mutations do
2944 | create Post, :create_post, :create
2945 | update Post, :update_post, :update
2946 | destroy Post, :destroy_post, :destroy
2947 | end
2948 | ```
2949 |
2950 | ## [](dsl-ashgraphql-domain.html#graphql-mutations-create)graphql.mutations.create
2951 |
2952 | ```
2953 | create resource, name, action
2954 | ```
2955 |
2956 | A mutation to create a record
2957 |
2958 | ### [](dsl-ashgraphql-domain.html#examples-7)Examples
2959 |
2960 | ```
2961 | create :create_post, :create
2962 | ```
2963 |
2964 | ### [](dsl-ashgraphql-domain.html#arguments-4)Arguments
2965 |
2966 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-mutations-create-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-mutations-create-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-domain.html#graphql-mutations-create-action)`atom`The action to use for the mutation.
2967 |
2968 | ### [](dsl-ashgraphql-domain.html#options-5)Options
2969 |
2970 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-domain.html#graphql-mutations-create-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`upsert?`](dsl-ashgraphql-domain.html#graphql-mutations-create-upsert?)`boolean``false`Whether or not to use the `upsert?: true` option when calling `YourDomain.create/2`.[`upsert_identity`](dsl-ashgraphql-domain.html#graphql-mutations-create-upsert_identity)`atom``false`Which identity to use for the upsert[`modify_resolution`](dsl-ashgraphql-domain.html#graphql-mutations-create-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-mutations-create-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-mutations-create-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
2971 |
2972 | ### [](dsl-ashgraphql-domain.html#introspection-4)Introspection
2973 |
2974 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
2975 |
2976 | ## [](dsl-ashgraphql-domain.html#graphql-mutations-update)graphql.mutations.update
2977 |
2978 | ```
2979 | update resource, name, action
2980 | ```
2981 |
2982 | A mutation to update a record
2983 |
2984 | ### [](dsl-ashgraphql-domain.html#examples-8)Examples
2985 |
2986 | ```
2987 | update :update_post, :update
2988 | ```
2989 |
2990 | ### [](dsl-ashgraphql-domain.html#arguments-5)Arguments
2991 |
2992 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-mutations-update-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-mutations-update-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-domain.html#graphql-mutations-update-action)`atom`The action to use for the mutation.
2993 |
2994 | ### [](dsl-ashgraphql-domain.html#options-6)Options
2995 |
2996 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-domain.html#graphql-mutations-update-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`identity`](dsl-ashgraphql-domain.html#graphql-mutations-update-identity)`atom`The identity to use to fetch the record to be updated. Use `false` if no identity is required.[`read_action`](dsl-ashgraphql-domain.html#graphql-mutations-update-read_action)`atom`The read action to use to fetch the record to be updated. Defaults to the primary read action.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-mutations-update-hide_inputs)`list(atom)`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-mutations-update-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
2997 |
2998 | ### [](dsl-ashgraphql-domain.html#introspection-5)Introspection
2999 |
3000 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
3001 |
3002 | ## [](dsl-ashgraphql-domain.html#graphql-mutations-destroy)graphql.mutations.destroy
3003 |
3004 | ```
3005 | destroy resource, name, action
3006 | ```
3007 |
3008 | A mutation to destroy a record
3009 |
3010 | ### [](dsl-ashgraphql-domain.html#examples-9)Examples
3011 |
3012 | ```
3013 | destroy :destroy_post, :destroy
3014 | ```
3015 |
3016 | ### [](dsl-ashgraphql-domain.html#arguments-6)Arguments
3017 |
3018 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-action)`atom`The action to use for the mutation.
3019 |
3020 | ### [](dsl-ashgraphql-domain.html#options-7)Options
3021 |
3022 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`read_action`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-read_action)`atom`The read action to use to fetch the record to be destroyed. Defaults to the primary read action.[`identity`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-identity)`atom`The identity to use to fetch the record to be destroyed. Use `false` if no identity is required.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-hide_inputs)`list(atom)`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-mutations-destroy-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3023 |
3024 | ### [](dsl-ashgraphql-domain.html#introspection-6)Introspection
3025 |
3026 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
3027 |
3028 | ## [](dsl-ashgraphql-domain.html#graphql-mutations-action)graphql.mutations.action
3029 |
3030 | ```
3031 | action resource, name, action
3032 | ```
3033 |
3034 | Runs a generic action
3035 |
3036 | ### [](dsl-ashgraphql-domain.html#examples-10)Examples
3037 |
3038 | ```
3039 | action :check_status, :check_status
3040 | ```
3041 |
3042 | ### [](dsl-ashgraphql-domain.html#arguments-7)Arguments
3043 |
3044 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-mutations-action-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-mutations-action-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-domain.html#graphql-mutations-action-action)`atom`The action to use for the query.
3045 |
3046 | ### [](dsl-ashgraphql-domain.html#options-8)Options
3047 |
3048 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-domain.html#graphql-mutations-action-description)`String.t`The description that gets shown in the Graphql schema. If not provided, the action description will be used.[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-mutations-action-hide_inputs)`list(atom)``[]`Inputs to hide in the mutation/query[`error_location`](dsl-ashgraphql-domain.html#graphql-mutations-action-error_location)`:in_result | :top_level``:top_level`If the result should have an `errors` and a `result` key (like create/update/destroy mutations), or if errors should be shown in the top level errors key[`modify_resolution`](dsl-ashgraphql-domain.html#graphql-mutations-action-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-domain.html#graphql-mutations-action-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3049 |
3050 | ### [](dsl-ashgraphql-domain.html#introspection-7)Introspection
3051 |
3052 | Target: [`AshGraphql.Resource.Action`](AshGraphql.Resource.Action.html)
3053 |
3054 | ## [](dsl-ashgraphql-domain.html#graphql-subscriptions)graphql.subscriptions
3055 |
3056 | Subscriptions to expose for the resource.
3057 |
3058 | ### [](dsl-ashgraphql-domain.html#nested-dsls-3)Nested DSLs
3059 |
3060 | - [subscribe](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe)
3061 |
3062 | ### [](dsl-ashgraphql-domain.html#examples-11)Examples
3063 |
3064 | ```
3065 | subscription do
3066 | subscribe Post, :post_created do
3067 | action_types(:create)
3068 | end
3069 | end
3070 | ```
3071 |
3072 | ## [](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe)graphql.subscriptions.subscribe
3073 |
3074 | ```
3075 | subscribe resource, name
3076 | ```
3077 |
3078 | A subscription to listen for changes on the resource
3079 |
3080 | ### [](dsl-ashgraphql-domain.html#examples-12)Examples
3081 |
3082 | ```
3083 | subscribe :post_created do
3084 | action_types(:create)
3085 | end
3086 | ```
3087 |
3088 | ### [](dsl-ashgraphql-domain.html#arguments-8)Arguments
3089 |
3090 | NameTypeDefaultDocs[`resource`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-resource)`module`The resource that the action is defined on[`name`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-name)`atom`The name to use for the subscription.
3091 |
3092 | ### [](dsl-ashgraphql-domain.html#options-9)Options
3093 |
3094 | NameTypeDefaultDocs[`actor`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-actor)`(any -> any) | module`The actor to use for authorization.[`actions`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-actions)`list(atom) | atom`The create/update/destroy actions the subsciption should listen to.[`action_types`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-action_types)`list(atom) | atom`The type of actions the subsciption should listen to.[`read_action`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-read_action)`atom`The read action to use for reading data[`hide_inputs`](dsl-ashgraphql-domain.html#graphql-subscriptions-subscribe-hide_inputs)`list(atom)``[]`A list of inputs to hide from the subscription, usable if the read action has arguments.
3095 |
3096 | ### [](dsl-ashgraphql-domain.html#introspection-8)Introspection
3097 |
3098 | Target: [`AshGraphql.Resource.Subscription`](AshGraphql.Resource.Subscription.html)
3099 |
3100 | [← Previous Page Upgrading to 1.0](upgrade.html)
3101 |
3102 | [Next Page → DSL: AshGraphql.Resource](dsl-ashgraphql-resource.html)
3103 |
3104 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/dsls/DSL-AshGraphql.Domain.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
3105 |
3106 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
3107 | [](https://github.com/ash-project/ash_graphql)
3108 |
3109 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
3110 |
3111 | v1.5.0
3112 |
3113 | - GUIDES
3114 | - Modules
3115 | - Mix Tasks
3116 |
3117 | <!--THE END-->
3118 |
3119 | <!--THE END-->
3120 |
3121 | <!--THE END-->
3122 |
3123 | Search documentation of ash\_graphql
3124 |
3125 | Settings
3126 |
3127 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/dsls/DSL-AshGraphql.Resource.md#L1 "View Source") DSL: AshGraphql.Resource
3128 |
3129 | This Ash resource extension adds configuration for exposing a resource in a graphql.
3130 |
3131 | ## [](dsl-ashgraphql-resource.html#graphql)graphql
3132 |
3133 | Configuration for a given resource in graphql
3134 |
3135 | ### [](dsl-ashgraphql-resource.html#nested-dsls)Nested DSLs
3136 |
3137 | - [queries](dsl-ashgraphql-resource.html#graphql-queries)
3138 |
3139 | - get
3140 | - read\_one
3141 | - list
3142 | - action
3143 | - [mutations](dsl-ashgraphql-resource.html#graphql-mutations)
3144 |
3145 | - create
3146 | - update
3147 | - destroy
3148 | - action
3149 | - [subscriptions](dsl-ashgraphql-resource.html#graphql-subscriptions)
3150 |
3151 | - subscribe
3152 | - [managed\_relationships](dsl-ashgraphql-resource.html#graphql-managed_relationships)
3153 |
3154 | - managed\_relationship
3155 |
3156 | ### [](dsl-ashgraphql-resource.html#examples)Examples
3157 |
3158 | ```
3159 | graphql do
3160 | type :post
3161 |
3162 | queries do
3163 | get :get_post, :read
3164 | list :list_posts, :read
3165 | end
3166 |
3167 | mutations do
3168 | create :create_post, :create
3169 | update :update_post, :update
3170 | destroy :destroy_post, :destroy
3171 | end
3172 | end
3173 | ```
3174 |
3175 | ### [](dsl-ashgraphql-resource.html#options)Options
3176 |
3177 | NameTypeDefaultDocs[`type`](dsl-ashgraphql-resource.html#graphql-type)`atom`The type to use for this entity in the graphql schema. If the resource doesn't have a type, it also needs to have `generate_object? false` and can only expose generic action queries.[`derive_filter?`](dsl-ashgraphql-resource.html#graphql-derive_filter?)`boolean``true`Set to false to disable the automatic generation of a filter input for read actions.[`derive_sort?`](dsl-ashgraphql-resource.html#graphql-derive_sort?)`boolean``true`Set to false to disable the automatic generation of a sort input for read actions.[`encode_primary_key?`](dsl-ashgraphql-resource.html#graphql-encode_primary_key?)`boolean``true`For resources with composite primary keys, or primary keys not called `:id`, this will cause the id to be encoded as a single `id` attribute, both in the representation of the resource and in get requests[`relationships`](dsl-ashgraphql-resource.html#graphql-relationships)`list(atom)`A list of relationships to include on the created type. Defaults to all public relationships where the destination defines a graphql type.[`paginate_relationship_with`](dsl-ashgraphql-resource.html#graphql-paginate_relationship_with)`keyword``[]`A keyword list indicating which kind of pagination should be used for each `has_many` and `many_to_many` relationships, e.g. `related_things: :keyset, other_related_things: :offset`. Valid pagination values are `nil`, `:offset`, `:keyset` and `:relay`.[`field_names`](dsl-ashgraphql-resource.html#graphql-field_names)`keyword`A keyword list of name overrides for attributes.[`hide_fields`](dsl-ashgraphql-resource.html#graphql-hide_fields)`list(atom)`A list of attributes to hide from the domain[`show_fields`](dsl-ashgraphql-resource.html#graphql-show_fields)`list(atom)`A list of attributes to show in the domain. If not specified includes all (excluding `hide_fiels`).[`argument_names`](dsl-ashgraphql-resource.html#graphql-argument_names)`keyword`A nested keyword list of action names, to argument name remappings. i.e `create: [arg_name: :new_name]`[`keyset_field`](dsl-ashgraphql-resource.html#graphql-keyset_field)`atom`If set, the keyset will be displayed on all read actions in this field. It will be `nil` unless at least one of the read actions on a resource uses keyset pagination or it is the result of a mutation[`attribute_types`](dsl-ashgraphql-resource.html#graphql-attribute_types)`keyword`A keyword list of type overrides for attributes. The type overrides should refer to types available in the graphql (absinthe) schema. `list_of/1` and `non_null/1` helpers can be used.[`attribute_input_types`](dsl-ashgraphql-resource.html#graphql-attribute_input_types)`keyword`A keyword list of input type overrides for attributes. The type overrides should refer to types available in the graphql (absinthe) schema. `list_of/1` and `non_null/1` helpers can be used.[`argument_input_types`](dsl-ashgraphql-resource.html#graphql-argument_input_types)`keyword`A keyword list of actions and their input type overrides for arguments. The type overrides should refer to types available in the graphql (absinthe) schema. `list_of/1` and `non_null/1` helpers can be used.[`primary_key_delimiter`](dsl-ashgraphql-resource.html#graphql-primary_key_delimiter)`String.t``"~"`If a composite primary key exists, this can be set to determine delimiter used in the `id` field value.[`depth_limit`](dsl-ashgraphql-resource.html#graphql-depth_limit)`integer`A simple way to prevent massive queries.[`generate_object?`](dsl-ashgraphql-resource.html#graphql-generate_object?)`boolean``true`Whether or not to create the GraphQL object, this allows you to manually create the GraphQL object.[`filterable_fields`](dsl-ashgraphql-resource.html#graphql-filterable_fields)`list(atom)`A list of fields that are allowed to be filtered on. Defaults to all filterable fields for which a GraphQL type can be created.[`nullable_fields`](dsl-ashgraphql-resource.html#graphql-nullable_fields)`atom | list(atom)`Mark fields as nullable even if they are required. This is useful when using field policies. See the authorization guide for more.[`error_handler`](dsl-ashgraphql-resource.html#graphql-error_handler)`mfa``{AshGraphql.DefaultErrorHandler, :handle_error, []}`Set an MFA to intercept/handle any errors that are generated.
3178 |
3179 | ## [](dsl-ashgraphql-resource.html#graphql-queries)graphql.queries
3180 |
3181 | Queries (read actions) to expose for the resource.
3182 |
3183 | ### [](dsl-ashgraphql-resource.html#nested-dsls-1)Nested DSLs
3184 |
3185 | - [get](dsl-ashgraphql-resource.html#graphql-queries-get)
3186 | - [read\_one](dsl-ashgraphql-resource.html#graphql-queries-read_one)
3187 | - [list](dsl-ashgraphql-resource.html#graphql-queries-list)
3188 | - [action](dsl-ashgraphql-resource.html#graphql-queries-action)
3189 |
3190 | ### [](dsl-ashgraphql-resource.html#examples-1)Examples
3191 |
3192 | ```
3193 | queries do
3194 | get :get_post, :read
3195 | read_one :current_user, :current_user
3196 | list :list_posts, :read
3197 | end
3198 | ```
3199 |
3200 | ## [](dsl-ashgraphql-resource.html#graphql-queries-get)graphql.queries.get
3201 |
3202 | ```
3203 | get name, action
3204 | ```
3205 |
3206 | A query to fetch a record by primary key
3207 |
3208 | ### [](dsl-ashgraphql-resource.html#examples-2)Examples
3209 |
3210 | ```
3211 | get :get_post, :read
3212 | ```
3213 |
3214 | ### [](dsl-ashgraphql-resource.html#arguments)Arguments
3215 |
3216 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-queries-get-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-resource.html#graphql-queries-get-action)`atom`The action to use for the query.
3217 |
3218 | ### [](dsl-ashgraphql-resource.html#options-1)Options
3219 |
3220 | NameTypeDefaultDocs[`identity`](dsl-ashgraphql-resource.html#graphql-queries-get-identity)`atom`The identity to use for looking up the record. Pass `false` to not use an identity.[`allow_nil?`](dsl-ashgraphql-resource.html#graphql-queries-get-allow_nil?)`boolean``true`Whether or not the action can return nil.[`modify_resolution`](dsl-ashgraphql-resource.html#graphql-queries-get-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`type_name`](dsl-ashgraphql-resource.html#graphql-queries-get-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-resource.html#graphql-queries-get-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-resource.html#graphql-queries-get-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-resource.html#graphql-queries-get-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-resource.html#graphql-queries-get-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-resource.html#graphql-queries-get-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-queries-get-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-queries-get-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
3221 |
3222 | ### [](dsl-ashgraphql-resource.html#introspection)Introspection
3223 |
3224 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
3225 |
3226 | ## [](dsl-ashgraphql-resource.html#graphql-queries-read_one)graphql.queries.read\_one
3227 |
3228 | ```
3229 | read_one name, action
3230 | ```
3231 |
3232 | A query to fetch a record
3233 |
3234 | ### [](dsl-ashgraphql-resource.html#examples-3)Examples
3235 |
3236 | ```
3237 | read_one :current_user, :current_user
3238 | ```
3239 |
3240 | ### [](dsl-ashgraphql-resource.html#arguments-1)Arguments
3241 |
3242 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-queries-read_one-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-resource.html#graphql-queries-read_one-action)`atom`The action to use for the query.
3243 |
3244 | ### [](dsl-ashgraphql-resource.html#options-2)Options
3245 |
3246 | NameTypeDefaultDocs[`allow_nil?`](dsl-ashgraphql-resource.html#graphql-queries-read_one-allow_nil?)`boolean``true`Whether or not the action can return nil.[`type_name`](dsl-ashgraphql-resource.html#graphql-queries-read_one-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-resource.html#graphql-queries-read_one-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-resource.html#graphql-queries-read_one-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-resource.html#graphql-queries-read_one-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-resource.html#graphql-queries-read_one-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-resource.html#graphql-queries-read_one-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-queries-read_one-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-queries-read_one-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
3247 |
3248 | ### [](dsl-ashgraphql-resource.html#introspection-1)Introspection
3249 |
3250 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
3251 |
3252 | ## [](dsl-ashgraphql-resource.html#graphql-queries-list)graphql.queries.list
3253 |
3254 | ```
3255 | list name, action
3256 | ```
3257 |
3258 | A query to fetch a list of records
3259 |
3260 | ### [](dsl-ashgraphql-resource.html#examples-4)Examples
3261 |
3262 | ```
3263 | list :list_posts, :read
3264 | ```
3265 |
3266 | ```
3267 | list :list_posts_paginated, :read, relay?: true
3268 | ```
3269 |
3270 | ### [](dsl-ashgraphql-resource.html#arguments-2)Arguments
3271 |
3272 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-queries-list-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-resource.html#graphql-queries-list-action)`atom`The action to use for the query.
3273 |
3274 | ### [](dsl-ashgraphql-resource.html#options-3)Options
3275 |
3276 | NameTypeDefaultDocs[`relay?`](dsl-ashgraphql-resource.html#graphql-queries-list-relay?)`boolean``false`If true, the graphql queries/resolvers for this resource will be built to honor the relay specification. See [the relay guide](https://hexdocs.pm/documentation/topics/relay.html) for more.[`paginate_with`](dsl-ashgraphql-resource.html#graphql-queries-list-paginate_with)`:keyset | :offset | nil``:keyset`Determine the pagination strategy to use, if multiple are available. If `nil`, no pagination is applied, otherwise the given strategy is used.[`type_name`](dsl-ashgraphql-resource.html#graphql-queries-list-type_name)`atom`Override the type name returned by this query. Must be set if the read action has `metadata` that is not hidden via the `show_metadata` key.[`description`](dsl-ashgraphql-resource.html#graphql-queries-list-description)`String.t`The query description that gets shown in the Graphql schema. If not provided, the action description will be used.[`metadata_names`](dsl-ashgraphql-resource.html#graphql-queries-list-metadata_names)`keyword``[]`Name overrides for metadata fields on the read action.[`metadata_types`](dsl-ashgraphql-resource.html#graphql-queries-list-metadata_types)`keyword``[]`Type overrides for metadata fields on the read action.[`show_metadata`](dsl-ashgraphql-resource.html#graphql-queries-list-show_metadata)`list(atom)`The metadata attributes to show. Defaults to all.[`as_mutation?`](dsl-ashgraphql-resource.html#graphql-queries-list-as_mutation?)`boolean``false`Places the query in the `mutations` key instead. Not typically necessary, but is often paired with `as_mutation?`. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-queries-list-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-queries-list-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.
3277 |
3278 | ### [](dsl-ashgraphql-resource.html#introspection-2)Introspection
3279 |
3280 | Target: [`AshGraphql.Resource.Query`](AshGraphql.Resource.Query.html)
3281 |
3282 | ## [](dsl-ashgraphql-resource.html#graphql-queries-action)graphql.queries.action
3283 |
3284 | ```
3285 | action name, action
3286 | ```
3287 |
3288 | Runs a generic action
3289 |
3290 | ### [](dsl-ashgraphql-resource.html#examples-5)Examples
3291 |
3292 | ```
3293 | action :check_status, :check_status
3294 | ```
3295 |
3296 | ### [](dsl-ashgraphql-resource.html#arguments-3)Arguments
3297 |
3298 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-queries-action-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-resource.html#graphql-queries-action-action)`atom`The action to use for the query.
3299 |
3300 | ### [](dsl-ashgraphql-resource.html#options-4)Options
3301 |
3302 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-resource.html#graphql-queries-action-description)`String.t`The description that gets shown in the Graphql schema. If not provided, the action description will be used.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-queries-action-hide_inputs)`list(atom)``[]`Inputs to hide in the mutation/query[`error_location`](dsl-ashgraphql-resource.html#graphql-queries-action-error_location)`:in_result | :top_level``:top_level`If the result should have an `errors` and a `result` key (like create/update/destroy mutations), or if errors should be shown in the top level errors key[`modify_resolution`](dsl-ashgraphql-resource.html#graphql-queries-action-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-queries-action-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3303 |
3304 | ### [](dsl-ashgraphql-resource.html#introspection-3)Introspection
3305 |
3306 | Target: [`AshGraphql.Resource.Action`](AshGraphql.Resource.Action.html)
3307 |
3308 | ## [](dsl-ashgraphql-resource.html#graphql-mutations)graphql.mutations
3309 |
3310 | Mutations (create/update/destroy actions) to expose for the resource.
3311 |
3312 | ### [](dsl-ashgraphql-resource.html#nested-dsls-2)Nested DSLs
3313 |
3314 | - [create](dsl-ashgraphql-resource.html#graphql-mutations-create)
3315 | - [update](dsl-ashgraphql-resource.html#graphql-mutations-update)
3316 | - [destroy](dsl-ashgraphql-resource.html#graphql-mutations-destroy)
3317 | - [action](dsl-ashgraphql-resource.html#graphql-mutations-action)
3318 |
3319 | ### [](dsl-ashgraphql-resource.html#examples-6)Examples
3320 |
3321 | ```
3322 | mutations do
3323 | create :create_post, :create
3324 | update :update_post, :update
3325 | destroy :destroy_post, :destroy
3326 | end
3327 | ```
3328 |
3329 | ## [](dsl-ashgraphql-resource.html#graphql-mutations-create)graphql.mutations.create
3330 |
3331 | ```
3332 | create name, action
3333 | ```
3334 |
3335 | A mutation to create a record
3336 |
3337 | ### [](dsl-ashgraphql-resource.html#examples-7)Examples
3338 |
3339 | ```
3340 | create :create_post, :create
3341 | ```
3342 |
3343 | ### [](dsl-ashgraphql-resource.html#arguments-4)Arguments
3344 |
3345 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-mutations-create-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-resource.html#graphql-mutations-create-action)`atom`The action to use for the mutation.
3346 |
3347 | ### [](dsl-ashgraphql-resource.html#options-5)Options
3348 |
3349 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-resource.html#graphql-mutations-create-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`upsert?`](dsl-ashgraphql-resource.html#graphql-mutations-create-upsert?)`boolean``false`Whether or not to use the `upsert?: true` option when calling `YourDomain.create/2`.[`upsert_identity`](dsl-ashgraphql-resource.html#graphql-mutations-create-upsert_identity)`atom``false`Which identity to use for the upsert[`modify_resolution`](dsl-ashgraphql-resource.html#graphql-mutations-create-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-mutations-create-hide_inputs)`list(atom)``[]`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-mutations-create-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3350 |
3351 | ### [](dsl-ashgraphql-resource.html#introspection-4)Introspection
3352 |
3353 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
3354 |
3355 | ## [](dsl-ashgraphql-resource.html#graphql-mutations-update)graphql.mutations.update
3356 |
3357 | ```
3358 | update name, action
3359 | ```
3360 |
3361 | A mutation to update a record
3362 |
3363 | ### [](dsl-ashgraphql-resource.html#examples-8)Examples
3364 |
3365 | ```
3366 | update :update_post, :update
3367 | ```
3368 |
3369 | ### [](dsl-ashgraphql-resource.html#arguments-5)Arguments
3370 |
3371 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-mutations-update-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-resource.html#graphql-mutations-update-action)`atom`The action to use for the mutation.
3372 |
3373 | ### [](dsl-ashgraphql-resource.html#options-6)Options
3374 |
3375 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-resource.html#graphql-mutations-update-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`identity`](dsl-ashgraphql-resource.html#graphql-mutations-update-identity)`atom`The identity to use to fetch the record to be updated. Use `false` if no identity is required.[`read_action`](dsl-ashgraphql-resource.html#graphql-mutations-update-read_action)`atom`The read action to use to fetch the record to be updated. Defaults to the primary read action.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-mutations-update-hide_inputs)`list(atom)`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-mutations-update-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3376 |
3377 | ### [](dsl-ashgraphql-resource.html#introspection-5)Introspection
3378 |
3379 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
3380 |
3381 | ## [](dsl-ashgraphql-resource.html#graphql-mutations-destroy)graphql.mutations.destroy
3382 |
3383 | ```
3384 | destroy name, action
3385 | ```
3386 |
3387 | A mutation to destroy a record
3388 |
3389 | ### [](dsl-ashgraphql-resource.html#examples-9)Examples
3390 |
3391 | ```
3392 | destroy :destroy_post, :destroy
3393 | ```
3394 |
3395 | ### [](dsl-ashgraphql-resource.html#arguments-6)Arguments
3396 |
3397 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-name)`atom``:get`The name to use for the mutation.[`action`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-action)`atom`The action to use for the mutation.
3398 |
3399 | ### [](dsl-ashgraphql-resource.html#options-7)Options
3400 |
3401 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-description)`String.t`The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.[`read_action`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-read_action)`atom`The read action to use to fetch the record to be destroyed. Defaults to the primary read action.[`identity`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-identity)`atom`The identity to use to fetch the record to be destroyed. Use `false` if no identity is required.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-hide_inputs)`list(atom)`A list of inputs to hide from the mutation.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-mutations-destroy-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3402 |
3403 | ### [](dsl-ashgraphql-resource.html#introspection-6)Introspection
3404 |
3405 | Target: [`AshGraphql.Resource.Mutation`](AshGraphql.Resource.Mutation.html)
3406 |
3407 | ## [](dsl-ashgraphql-resource.html#graphql-mutations-action)graphql.mutations.action
3408 |
3409 | ```
3410 | action name, action
3411 | ```
3412 |
3413 | Runs a generic action
3414 |
3415 | ### [](dsl-ashgraphql-resource.html#examples-10)Examples
3416 |
3417 | ```
3418 | action :check_status, :check_status
3419 | ```
3420 |
3421 | ### [](dsl-ashgraphql-resource.html#arguments-7)Arguments
3422 |
3423 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-mutations-action-name)`atom``:get`The name to use for the query.[`action`](dsl-ashgraphql-resource.html#graphql-mutations-action-action)`atom`The action to use for the query.
3424 |
3425 | ### [](dsl-ashgraphql-resource.html#options-8)Options
3426 |
3427 | NameTypeDefaultDocs[`description`](dsl-ashgraphql-resource.html#graphql-mutations-action-description)`String.t`The description that gets shown in the Graphql schema. If not provided, the action description will be used.[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-mutations-action-hide_inputs)`list(atom)``[]`Inputs to hide in the mutation/query[`error_location`](dsl-ashgraphql-resource.html#graphql-mutations-action-error_location)`:in_result | :top_level``:top_level`If the result should have an `errors` and a `result` key (like create/update/destroy mutations), or if errors should be shown in the top level errors key[`modify_resolution`](dsl-ashgraphql-resource.html#graphql-mutations-action-modify_resolution)`mfa`An MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. See the [the guide](https://hexdocs.pm/documentation/topics/modifying-the-resolution.html) for more.[`relay_id_translations`](dsl-ashgraphql-resource.html#graphql-mutations-action-relay_id_translations)`keyword``[]`A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the [Relay guide](relay.html#translating-relay-global-ids-passed-as-arguments) for more.
3428 |
3429 | ### [](dsl-ashgraphql-resource.html#introspection-7)Introspection
3430 |
3431 | Target: [`AshGraphql.Resource.Action`](AshGraphql.Resource.Action.html)
3432 |
3433 | ## [](dsl-ashgraphql-resource.html#graphql-subscriptions)graphql.subscriptions
3434 |
3435 | Subscriptions (notifications) to expose for the resource.
3436 |
3437 | ### [](dsl-ashgraphql-resource.html#nested-dsls-3)Nested DSLs
3438 |
3439 | - [subscribe](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe)
3440 |
3441 | ### [](dsl-ashgraphql-resource.html#examples-11)Examples
3442 |
3443 | ```
3444 | subscriptions do
3445 | subscribe :bucket_created do
3446 | actions :create
3447 | read_action :read
3448 | end
3449 | end
3450 | ```
3451 |
3452 | ### [](dsl-ashgraphql-resource.html#options-9)Options
3453 |
3454 | NameTypeDefaultDocs[`pubsub`](dsl-ashgraphql-resource.html#graphql-subscriptions-pubsub)`module`The pubsub module to use for the subscription
3455 |
3456 | ## [](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe)graphql.subscriptions.subscribe
3457 |
3458 | ```
3459 | subscribe name
3460 | ```
3461 |
3462 | A subscription to listen for changes on the resource
3463 |
3464 | ### [](dsl-ashgraphql-resource.html#examples-12)Examples
3465 |
3466 | ```
3467 | subscribe :post_created do
3468 | action_types(:create)
3469 | end
3470 | ```
3471 |
3472 | ### [](dsl-ashgraphql-resource.html#arguments-8)Arguments
3473 |
3474 | NameTypeDefaultDocs[`name`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-name)`atom`The name to use for the subscription.
3475 |
3476 | ### [](dsl-ashgraphql-resource.html#options-10)Options
3477 |
3478 | NameTypeDefaultDocs[`actor`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-actor)`(any -> any) | module`The actor to use for authorization.[`actions`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-actions)`list(atom) | atom`The create/update/destroy actions the subsciption should listen to.[`action_types`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-action_types)`list(atom) | atom`The type of actions the subsciption should listen to.[`read_action`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-read_action)`atom`The read action to use for reading data[`hide_inputs`](dsl-ashgraphql-resource.html#graphql-subscriptions-subscribe-hide_inputs)`list(atom)``[]`A list of inputs to hide from the subscription, usable if the read action has arguments.
3479 |
3480 | ### [](dsl-ashgraphql-resource.html#introspection-8)Introspection
3481 |
3482 | Target: [`AshGraphql.Resource.Subscription`](AshGraphql.Resource.Subscription.html)
3483 |
3484 | ## [](dsl-ashgraphql-resource.html#graphql-managed_relationships)graphql.managed\_relationships
3485 |
3486 | Generates input objects for `manage_relationship` arguments on resource actions.
3487 |
3488 | ### [](dsl-ashgraphql-resource.html#nested-dsls-4)Nested DSLs
3489 |
3490 | - [managed\_relationship](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship)
3491 |
3492 | ### [](dsl-ashgraphql-resource.html#examples-13)Examples
3493 |
3494 | ```
3495 | managed_relationships do
3496 | manage_relationship :create_post, :comments
3497 | end
3498 | ```
3499 |
3500 | ### [](dsl-ashgraphql-resource.html#options-11)Options
3501 |
3502 | NameTypeDefaultDocs[`auto?`](dsl-ashgraphql-resource.html#graphql-managed_relationships-auto?)`boolean``true`Automatically derive types for all arguments that have a `manage_relationship` call change.
3503 |
3504 | ## [](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship)graphql.managed\_relationships.managed\_relationship
3505 |
3506 | ```
3507 | managed_relationship action, argument
3508 | ```
3509 |
3510 | Instructs ash\_graphql that a given argument with a `manage_relationship` change should have its input objects derived automatically from the potential actions to be called.
3511 |
3512 | For example, given an action like:
3513 |
3514 | ```
3515 | actions do
3516 | create :create do
3517 | argument :comments, {:array, :map}
3518 |
3519 | change manage_relationship(:comments, type: :direct_control) # <- we look for this change with a matching argument name
3520 | end
3521 | end
3522 | ```
3523 |
3524 | You could add the following managed\_relationship
3525 |
3526 | ```
3527 | graphql do
3528 | ...
3529 |
3530 | managed_relationships do
3531 | managed_relationship :create, :comments
3532 | end
3533 | end
3534 | ```
3535 |
3536 | By default, the `{:array, :map}` would simply be a `json[]` type. If the argument name is placed in this list, all of the potential actions that could be called will be combined into a single input object. If there are type conflicts (for example, if the input could create or update a record, and the create and update actions have an argument of the same name but with a different type), a warning is emitted at compile time and the first one is used. If that is insufficient, you will need to do one of the following:
3537 |
3538 | 1.) provide the `:types` option to the `managed_relationship` constructor (see that option for more) 2.) define a custom type, with a custom input object (see the custom types guide), and use that custom type instead of `:map` 3.) change your actions to not have overlapping inputs with different types
3539 |
3540 | Since managed relationships can ultimately call multiple actions, there is the possibility of field type conflicts. Use the `types` option to determine the type of fields and remove the conflict warnings.
3541 |
3542 | For `non_null` use `{:non_null, type}`, and for a list, use `{:array, type}`, for example:
3543 |
3544 | `{:non_null, {:array, {:non_null, :string}}}` for a non null list of non null strings.
3545 |
3546 | To *remove* a key from the input object, simply pass `nil` as the type.
3547 |
3548 | ### [](dsl-ashgraphql-resource.html#arguments-9)Arguments
3549 |
3550 | NameTypeDefaultDocs[`action`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-action)`atom`The action that accepts the argument[`argument`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-argument)`atom`The argument for which an input object should be derived.
3551 |
3552 | ### [](dsl-ashgraphql-resource.html#options-12)Options
3553 |
3554 | NameTypeDefaultDocs[`lookup_with_primary_key?`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-lookup_with_primary_key?)`boolean`If the managed\_relationship has `on_lookup` behavior, this option determines whether or not the primary key is provided in the input object for looking up.[`lookup_identities`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-lookup_identities)`list(atom)`Determines which identities are provided in the input object for looking up, if there is `on_lookup` behavior. Defalts to the `use_identities` option.[`type_name`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-type_name)`atom`The name of the input object that will be derived. Defaults to `<action_type>_<resource>_<argument_name>_input`[`types`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-types)`any`A keyword list of field names to their graphql type identifiers.[`ignore?`](dsl-ashgraphql-resource.html#graphql-managed_relationships-managed_relationship-ignore?)`boolean``false`Use this to ignore a given managed relationship, preventing `auto? true` from deriving a type for it.
3555 |
3556 | ### [](dsl-ashgraphql-resource.html#introspection-9)Introspection
3557 |
3558 | Target: [`AshGraphql.Resource.ManagedRelationship`](AshGraphql.Resource.ManagedRelationship.html)
3559 |
3560 | [← Previous Page DSL: AshGraphql.Domain](dsl-ashgraphql-domain.html)
3561 |
3562 | [Next Page → Change Log](changelog.html)
3563 |
3564 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/dsls/DSL-AshGraphql.Resource.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
3565 |
3566 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
3567 | [](https://github.com/ash-project/ash_graphql)
3568 |
3569 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
3570 |
3571 | v1.5.0
3572 |
3573 | - GUIDES
3574 | - Modules
3575 | - Mix Tasks
3576 |
3577 | <!--THE END-->
3578 |
3579 | <!--THE END-->
3580 |
3581 | <!--THE END-->
3582 |
3583 | Search documentation of ash\_graphql
3584 |
3585 | Settings
3586 |
3587 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/generic-actions.md#L1 "View Source") Generic Actions
3588 |
3589 | Generic actions allow us to build any interface we want in Ash. AshGraphql has full support for generic actions, from type generation to data loading.
3590 |
3591 | This means that you can write actions that return records or lists of records and those will have all of their fields appropriately loadable, or you can have generic actions that return simple scalars, like integers or strings.
3592 |
3593 | ## [](generic-actions.html#examples)Examples
3594 |
3595 | Here we have a simple generic action returning a scalar value.
3596 |
3597 | ```
3598 | graphql do
3599 | queries do
3600 | action :say_hello, :say_hello
3601 | end
3602 | end
3603 |
3604 | actions do
3605 | action :say_hello, :string do
3606 | argument :to, :string, allow_nil?: false
3607 |
3608 | run fn input, _ ->
3609 | {:ok, "Hello, #{input.arguments.to}"}
3610 | end
3611 | end
3612 | end
3613 | ```
3614 |
3615 | And here we have a generic action returning a list of records.
3616 |
3617 | ```
3618 | graphql do
3619 | type :post
3620 |
3621 | queries do
3622 | action :random_ten, :random_ten
3623 | end
3624 | end
3625 |
3626 | actions do
3627 | action :random_ten, {:array, :struct} do
3628 | constraints items: [instance_of: __MODULE__]
3629 |
3630 | run fn input, context ->
3631 | # This is just an example, not an efficient way to get
3632 | # ten random records
3633 | with {:ok, records} <- Ash.read(__MODULE__) do
3634 | {:ok, Enum.take_random(records, 10)}
3635 | end
3636 | end
3637 | end
3638 | end
3639 | ```
3640 |
3641 | [← Previous Page Handling Errors](handle-errors.html)
3642 |
3643 | [Next Page → Using the SDL File](sdl-file.html)
3644 |
3645 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/generic-actions.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
3646 |
3647 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
3648 | [](https://github.com/ash-project/ash_graphql)
3649 |
3650 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
3651 |
3652 | v1.5.0
3653 |
3654 | - GUIDES
3655 | - Modules
3656 | - Mix Tasks
3657 |
3658 | <!--THE END-->
3659 |
3660 | <!--THE END-->
3661 |
3662 | <!--THE END-->
3663 |
3664 | Search documentation of ash\_graphql
3665 |
3666 | Settings
3667 |
3668 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/tutorials/getting-started-with-graphql.md#L1 "View Source") Getting Started With GraphQL
3669 |
3670 | ## [](getting-started-with-graphql.html#get-familiar-with-ash-resources)Get familiar with Ash resources
3671 |
3672 | If you haven't already, read the [Ash Getting Started Guide](../ash/get-started.html). This assumes that you already have resources set up, and only gives you the steps to *add* AshGraphql to your resources/domains.
3673 |
3674 | ## [](getting-started-with-graphql.html#installation)Installation
3675 |
3676 | ### [](getting-started-with-graphql.html#using-igniter-recommended)Using Igniter (recommended)
3677 |
3678 | ```
3679 | mix igniter.install ash_graphql
3680 | ```
3681 |
3682 | ### [](getting-started-with-graphql.html#manual)Manual
3683 |
3684 | #### Bring in the `ash_graphql` dependency
3685 |
3686 | ```
3687 | def deps()
3688 | [
3689 | ...
3690 | {:ash_graphql, "~> 1.5.0"}
3691 | ]
3692 | end
3693 | ```
3694 |
3695 | #### Setting up your schema
3696 |
3697 | If you don't have an absinthe schema, you can create one just for ash. Replace `helpdesk` in the examples with your own application name.
3698 |
3699 | See [the SDL file guide](sdl-file.html) for more information on using the SDL file, or remove the `generate_sdl_file` option to skip generating it on calls to [`mix ash.codegen`](../ash/3.4.50/Mix.Tasks.Ash.Codegen.html).
3700 |
3701 | in `lib/helpdesk/schema.ex`
3702 |
3703 | ```
3704 | defmodule Helpdesk.GraphqlSchema do
3705 | use Absinthe.Schema
3706 |
3707 | # Add your domains here
3708 | use AshGraphql,
3709 | domains: [Your.Domains]
3710 |
3711 | query do
3712 | # Custom absinthe queries can be placed here
3713 | @desc "Remove me once you have a query of your own!"
3714 | field :remove_me, :string do
3715 | resolve fn _, _, _ ->
3716 | {:ok, "Remove me!"}
3717 | end
3718 | end
3719 | end
3720 |
3721 | mutation do
3722 | # Custom absinthe mutations can be placed here
3723 | end
3724 | end
3725 | ```
3726 |
3727 | #### Connect your schema
3728 |
3729 | ##### Using Phoenix
3730 |
3731 | Add the following code to your Phoenix router. It's useful to set up the Absinthe playground for trying things out, but it's optional.
3732 |
3733 | ```
3734 | pipeline :graphql do
3735 | plug AshGraphql.Plug
3736 | end
3737 |
3738 | scope "/gql" do
3739 | pipe_through [:graphql]
3740 |
3741 | forward "/playground",
3742 | Absinthe.Plug.GraphiQL,
3743 | schema: Module.concat(["Helpdesk.GraphqlSchema"]),
3744 | interface: :playground
3745 |
3746 | forward "/",
3747 | Absinthe.Plug,
3748 | schema: Module.concat(["Helpdesk.GraphqlSchema"])
3749 | end
3750 | ```
3751 |
3752 | ### [](getting-started-with-graphql.html#whats-up-with-module-concat-1)Whats up with [`Module.concat/1`](../elixir/Module.html#concat/1)?
3753 |
3754 | This [`Module.concat/1`](../elixir/Module.html#concat/1) prevents a [compile-time dependency](https://dashbit.co/blog/speeding-up-re-compilation-of-elixir-projects) from this router module to the schema module. It is an implementation detail of how `forward/2` works that you end up with a compile-time dependency on the schema, but there is no need for this dependency, and that dependency can have *drastic* impacts on your compile times in certain scenarios.
3755 |
3756 | If you started with `mix new ...` instead of `mix phx.new ...` and you want to still use Phoenix, the fastest path that way is typically to just create a new Phoenix application and copy your resources/config over.
3757 |
3758 | ##### Using Plug
3759 |
3760 | If you are unfamiliar with how plug works, this [guide](https://elixirschool.com/en/lessons/specifics/plug/#dependencies) will be helpful for understanding it. It also guides you through adding plug to your application.
3761 |
3762 | Then you can use a [`Plug.Router`](../plug/1.16.1/Plug.Router.html) and [forward](https://hexdocs.pm/plug/Plug.Router.html#forward/2) to your plugs similar to how it is done for phoenix:
3763 |
3764 | ```
3765 | plug AshGraphql.Plug
3766 |
3767 | forward "/gql",
3768 | to: Absinthe.Plug,
3769 | init_opts: [schema: Module.concat(["Helpdesk.GraphqlSchema"])]
3770 |
3771 | forward "/playground",
3772 | to: Absinthe.Plug.GraphiQL,
3773 | init_opts: [
3774 | schema: Module.concat(["Helpdesk.GraphqlSchema"]),
3775 | interface: :playground
3776 | ]
3777 | ```
3778 |
3779 | For information on why we are using [`Module.concat/1`](../elixir/Module.html#concat/1), see the note above in the Phoenix section.
3780 |
3781 | ## [](getting-started-with-graphql.html#select-domains-to-show-in-your-graphql)Select domains to show in your GraphQL
3782 |
3783 | In the `use AshGraphql` call in your schema, you specify which domains you want to expose in your GraphQL API. Add any domains that will have [`AshGraphql`](AshGraphql.html) queries/mutations to the `domains` list. For example:
3784 |
3785 | ```
3786 | use AshGraphql, domains: [Your.Domain1, Your.Domain2]
3787 | ```
3788 |
3789 | ## [](getting-started-with-graphql.html#adding-queries-and-mutations)Adding Queries and Mutations
3790 |
3791 | Some example queries/mutations are shown below. If no queries/mutations are added, nothing will show up in the GraphQL API, so be sure to set one up if you want to try it out.
3792 |
3793 | ### [](getting-started-with-graphql.html#queries-mutations-on-the-resource)Queries & Mutations on the Resource
3794 |
3795 | Here we show queries and mutations being added to the resource, but you can also define them on the *domain*. See below for an equivalent definition
3796 |
3797 | ```
3798 | defmodule Helpdesk.Support.Ticket do
3799 | use Ash.Resource,
3800 | ...,
3801 | extensions: [
3802 | AshGraphql.Resource
3803 | ]
3804 |
3805 | graphql do
3806 | type :ticket
3807 |
3808 | queries do
3809 | # Examples
3810 |
3811 | # create a field called `get_ticket` that uses the `read` read action to fetch a single ticke
3812 | get :get_ticket, :read
3813 | # create a field called `most_important_ticket` that uses the `most_important` read action to fetch a single record
3814 | read_one :most_important_ticket, :most_important
3815 |
3816 | # create a field called `list_tickets` that uses the `read` read action to fetch a list of tickets
3817 | list :list_tickets, :read
3818 | end
3819 |
3820 | mutations do
3821 | # Examples
3822 |
3823 | create :create_ticket, :create
3824 | update :update_ticket, :update
3825 | destroy :destroy_ticket, :destroy
3826 | end
3827 | end
3828 |
3829 | ...
3830 | end
3831 | ```
3832 |
3833 | ### [](getting-started-with-graphql.html#queries-mutations-on-the-domain)Queries & Mutations on the Domain
3834 |
3835 | ```
3836 | defmodule Helpdesk.Support.Ticket do
3837 | use Ash.Resource,
3838 | ...,
3839 | extensions: [
3840 | AshGraphql.Resource
3841 | ]
3842 |
3843 | # The resource still determines its type, and any other resource/type-based
3844 | # configuration
3845 | graphql do
3846 | type :ticket
3847 | end
3848 |
3849 | ...
3850 | end
3851 |
3852 | defmodule Helpdesk.Support do
3853 | use Ash.Domain,
3854 | extensions: [
3855 | AshGraphql.Domain
3856 | ]
3857 |
3858 | ...
3859 | graphql do
3860 | # equivalent queries and mutations, but the first argument
3861 | # is the resource because the domain can define queries for
3862 | # any of its resources
3863 | queries do
3864 | get Helpdesk.Support.Ticket, :get_ticket, :read
3865 | read_one Helpdesk.Support.Ticket, :most_important_ticket, :most_important
3866 | list Helpdesk.Support.Ticket, :list_tickets, :read
3867 | end
3868 |
3869 | mutations do
3870 | create Helpdesk.Support.Ticket, :create_ticket, :create
3871 | update Helpdesk.Support.Ticket, :update_ticket, :update
3872 | destroy Helpdesk.Support.Ticket, :destroy_ticket, :destroy
3873 | end
3874 | end
3875 | ```
3876 |
3877 | ## [](getting-started-with-graphql.html#what-s-next)What's next?
3878 |
3879 | Topics:
3880 |
3881 | - [GraphQL Generation](graphql-generation.html)
3882 |
3883 | How Tos:
3884 |
3885 | - [Authorize With GraphQL](authorize-with-graphql.html)
3886 | - [Handle Errors](handle-errors.html)
3887 | - [Use Enums with GraphQL](use-enums-with-graphql.html)
3888 | - [Use JSON with GraphQL](use-json-with-graphql.html)
3889 |
3890 | [← Previous Page Home](readme.html)
3891 |
3892 | [Next Page → Authorize with GraphQL](authorize-with-graphql.html)
3893 |
3894 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/tutorials/getting-started-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
3895 |
3896 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
3897 | [](https://github.com/ash-project/ash_graphql)
3898 |
3899 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
3900 |
3901 | v1.5.0
3902 |
3903 | - GUIDES
3904 | - Modules
3905 | - Mix Tasks
3906 |
3907 | <!--THE END-->
3908 |
3909 | <!--THE END-->
3910 |
3911 | <!--THE END-->
3912 |
3913 | Search documentation of ash\_graphql
3914 |
3915 | Settings
3916 |
3917 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/graphql-generation.md#L1 "View Source") GraphQL Query Generation
3918 |
3919 | Following where we left off from [Getting Started with GraphQL](getting-started-with-graphql.html), this guide explores what the GraphQL requests and responses look like for different queries defined with the AshGraphql DSL.
3920 |
3921 | All of the following examples apply to queries & mutations places on the domain as well.
3922 |
3923 | ## [](graphql-generation.html#fetch-data-by-id)Fetch Data by ID
3924 |
3925 | ```
3926 | defmodule Helpdesk.Support.Ticket do
3927 | use Ash.Resource,
3928 | ...,
3929 | extensions: [
3930 | AshGraphql.Resource
3931 | ]
3932 |
3933 | attributes do
3934 | # Add an autogenerated UUID primary key called `:id`.
3935 | uuid_primary_key :id
3936 |
3937 | # Add a string type attribute called `:subject`
3938 | attribute :subject, :string
3939 | end
3940 |
3941 | actions do
3942 | # Add a set of simple actions. You'll customize these later.
3943 | defaults [:read, :update, :destroy]
3944 | end
3945 |
3946 | graphql do
3947 | type :ticket
3948 |
3949 | queries do
3950 | # create a field called `get_ticket` that uses the `read` read action to fetch a single ticket
3951 | get :get_ticket, :read
3952 | end
3953 | end
3954 | end
3955 | ```
3956 |
3957 | For the `get_ticket` query defined above, the corresponding GraphQL would look like this:
3958 |
3959 | ```
3960 | query ($id: ID!) {
3961 | getTicket(id: $id) {
3962 | id
3963 | subject
3964 | }
3965 | }
3966 | ```
3967 |
3968 | And the response would look similar to this:
3969 |
3970 | ```
3971 | {
3972 | "data": {
3973 | "getTicket": {
3974 | "id": "",
3975 | "subject": ""
3976 | }
3977 | }
3978 | }
3979 | ```
3980 |
3981 | Let's look at an example of querying a list of things.
3982 |
3983 | ```
3984 | graphql do
3985 | type :ticket
3986 |
3987 | queries do
3988 | # create a field called `get_ticket` that uses the `read` read action to fetch a single ticket
3989 | get :get_ticket, :read
3990 |
3991 | # create a field called `list_tickets` that uses the `read` read action to fetch a list of tickets
3992 | list :list_tickets, :read
3993 | end
3994 | end
3995 | ```
3996 |
3997 | This time, we've added `list :list_tickets, :read`, to generate a GraphQL query for listing tickets. The request would look something like this:
3998 |
3999 | ```
4000 | query {
4001 | listTickets {
4002 | id
4003 | subject
4004 | }
4005 | }
4006 | ```
4007 |
4008 | And the response would look similar to this:
4009 |
4010 | ```
4011 | {
4012 | "data": {
4013 | "listTickets": [
4014 | {
4015 | "id": "",
4016 | "subject": ""
4017 | }
4018 | ]
4019 | }
4020 | }
4021 | ```
4022 |
4023 | ## [](graphql-generation.html#filter-data-with-arguments)Filter Data With Arguments
4024 |
4025 | Now, let's say we want to add query parameters to `listTickets`. How do we do that? Consider `list :list_tickets, :read` and the `actions` section:
4026 |
4027 | ```
4028 | actions do
4029 | # Add a set of simple actions. You'll customize these later.
4030 | defaults [:read, :update, :destroy]
4031 | end
4032 |
4033 | graphql do
4034 | type :ticket
4035 |
4036 | queries do
4037 | # create a field called `list_tickets` that uses the `read` read action to fetch a list of tickets
4038 | list :list_tickets, :read
4039 | end
4040 | end
4041 | ```
4042 |
4043 | The second argument to `list :list_tickets, :read` is the action that will be called when the query is run. In the current example, the action is `:read`, which is the generic Read action. Let's create a custom action in order to define query parameters for the `listTickets` query.
4044 |
4045 | We'll call this action `:query_tickets`:
4046 |
4047 | ```
4048 | actions do
4049 | defaults [:read, :update, :destroy]
4050 |
4051 | read :query_tickets do
4052 | argument :representative_id, :uuid
4053 |
4054 | filter(
4055 | expr do
4056 | is_nil(^arg(:representative_id)) or representative_id == ^arg(:representative_id)
4057 | end
4058 | )
4059 | end
4060 | end
4061 |
4062 | graphql do
4063 | type :ticket
4064 |
4065 | queries do
4066 | # create a field called `list_tickets` that uses the `:query_tickets` read action to fetch a list of tickets
4067 | list :list_tickets, :query_tickets
4068 | end
4069 | end
4070 | ```
4071 |
4072 | In the `graphql` section, the `list/2` call has been changed, replacing the `:read` action with `:query_tickets`.
4073 |
4074 | The GraphQL request would look something like this:
4075 |
4076 | ```
4077 | query ($representative_id: ID) {
4078 | list_tickets(representative_id: $representative_id) {
4079 | id
4080 | representative_id
4081 | subject
4082 | }
4083 | }
4084 | ```
4085 |
4086 | ## [](graphql-generation.html#mutations-and-enums)Mutations and Enums
4087 |
4088 | Now, let's look at how to create a ticket by using a GraphQL mutation.
4089 |
4090 | Let's say you have a Resource that defines an enum-like attribute:
4091 |
4092 | ```
4093 | defmodule Helpdesk.Support.Ticket do
4094 | use Ash.Resource,
4095 | ...,
4096 | extensions: [
4097 | AshGraphql.Resource
4098 | ]
4099 |
4100 |
4101 | attributes do
4102 | uuid_primary_key :id
4103 | attribute :subject, :string
4104 | attribute :status, :atom, constraints: [one_of: [:open, :closed]]
4105 | end
4106 |
4107 | actions do
4108 | defaults [:create, :read, :update, :destroy]
4109 | end
4110 |
4111 | graphql do
4112 | type :ticket
4113 |
4114 | queries do
4115 | get :get_ticket, :read
4116 | end
4117 |
4118 | mutations do
4119 | create :create_ticket, :create
4120 | end
4121 | end
4122 | end
4123 | ```
4124 |
4125 | Above, the following changes have been added:
4126 |
4127 | 1. In the `attributes` section, the `:status` attribute has been added.
4128 | 2. In the `actions` section, the `:create` action has been added.
4129 | 3. The `:create_ticket` mutation has been defined in the new `graphql.mutations` section.
4130 |
4131 | The `:status` attribute is an enum that is constrained to the values `[:open, :closed]`. When used in conjunction with AshGraphql, a GraphQL enum type called `TicketStatus` will be generated for this attribute. The possible GraphQL values for `TicketStatus` are `OPEN` and `CLOSED`. See [Use Enums with GraphQL](use-enums-with-graphql.html) for more information.
4132 |
4133 | We can now create a ticket with the `createTicket` mutation:
4134 |
4135 | ```
4136 | mutation ($input: CreateTicketInput!) {
4137 | createTicket(input: $input) {
4138 | result {
4139 | id
4140 | subject
4141 | status
4142 | }
4143 | errors {
4144 | code
4145 | fields
4146 | message
4147 | shortMessage
4148 | vars
4149 | }
4150 | }
4151 | }
4152 | ```
4153 |
4154 | **Note**
4155 |
4156 | - The resulting ticket data is wrapped in AshGraphql's `result` object.
4157 | - Validation errors are wrapped in a list of error objects under `errors`, also specified in the query. AshGraphql does this by default instead of exposing errors in GraphQL's standard `errors` array. This behavior can be changed by setting `root_level_errors? true` in the `graphql` section of your Ash domain module:
4158 |
4159 | ```
4160 | defmodule Helpdesk.Support do
4161 | use Ash.Domain, extensions: [AshGraphql.Domain]
4162 |
4163 | graphql do
4164 | root_level_errors? true
4165 | end
4166 | end
4167 | ```
4168 |
4169 | If we were to run this mutation in a test, it would look something like this:
4170 |
4171 | ```
4172 | input = %{
4173 | subject: "My Ticket",
4174 | status: "OPEN"
4175 | }
4176 |
4177 | resp_body =
4178 | post(conn, "/api/graphql", %{
4179 | query: query,
4180 | variables: %{input: input}
4181 | })
4182 | |> json_response(200)
4183 | ```
4184 |
4185 | Notice that the `status` attribute is set to `"OPEN"` and not `"open"`. It is important that the value of the `status` be uppercase. This is required by GraphQL enums. AshGraphql will automatically convert the value to the correct case.
4186 |
4187 | The response will look something like this:
4188 |
4189 | ```
4190 | {
4191 | "data": {
4192 | "createTicket": {
4193 | "result": {
4194 | "id": "b771e433-0979-4d07-a280-4d12373849aa",
4195 | "subject": "My Ticket",
4196 | "status": "OPEN"
4197 | }
4198 | }
4199 | }
4200 | }
4201 | ```
4202 |
4203 | Again, AshGraphql will automatically convert the `status` value from `:open` to `"OPEN"`.
4204 |
4205 | ## [](graphql-generation.html#more-graphql-docs)More GraphQL Docs
4206 |
4207 | If you haven't already, please turn on the documentation tag for AshGraphql. Tags can be controlled at the top of the left navigation menu, under "Including Libraries:".
4208 |
4209 | - [Getting Started With GraphQL](getting-started-with-graphql.html)
4210 | - [`AshGraphql.Domain`](AshGraphql.Domain.html)
4211 |
4212 | [← Previous Page Monitoring](monitoring.html)
4213 |
4214 | [Next Page → Modifying the Resolution](modifying-the-resolution.html)
4215 |
4216 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/graphql-generation.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4217 |
4218 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4219 | [](https://github.com/ash-project/ash_graphql)
4220 |
4221 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4222 |
4223 | v1.5.0
4224 |
4225 | - GUIDES
4226 | - Modules
4227 | - Mix Tasks
4228 |
4229 | <!--THE END-->
4230 |
4231 | <!--THE END-->
4232 |
4233 | <!--THE END-->
4234 |
4235 | Search documentation of ash\_graphql
4236 |
4237 | Settings
4238 |
4239 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/handle-errors.md#L1 "View Source") Handling Errors
4240 |
4241 | There are various options that can be set on the Domain module to determine how errors behave and/or are shown in the GraphQL.
4242 |
4243 | ## [](handle-errors.html#showing-raised-errors)Showing raised errors
4244 |
4245 | For security purposes, if an error is *raised* as opposed to returned somewhere, the error is hidden. Set this to `true` in dev/test environments for an easier time debugging.
4246 |
4247 | ```
4248 | graphql do
4249 | show_raised_errors? true
4250 | end
4251 |
4252 | # or it can be done in config
4253 | # make sure you've set `otp_app` in your domain, i.e use Ash.Domain, otp_app: :my_app
4254 |
4255 | config :my_app, YourDomain, [
4256 | graphql: [
4257 | show_raised_errors?: true
4258 | ]
4259 | ]
4260 | ```
4261 |
4262 | ## [](handle-errors.html#root-level-errors)Root level errors
4263 |
4264 | By default, action errors are simply shown in the `errors` field for mutations. Set this to `true` to return them as root level errors instead.
4265 |
4266 | ```
4267 | graphql do
4268 | root_level_errors? true
4269 | end
4270 | ```
4271 |
4272 | ## [](handle-errors.html#error-handler)Error Handler
4273 |
4274 | Setting an error handler allows you to use things like `gettext` to translate errors and/or modify errors in some way. This error handler will take the error object to be returned, and the context. See the [absinthe docs](../absinthe/context-and-authentication.html#context-and-plugs) for adding to the absinthe context (i.e for setting a locale).
4275 |
4276 | ```
4277 | graphql do
4278 | error_handler {MyApp.GraphqlErrorHandler, :handle_error, []}
4279 | end
4280 | ```
4281 |
4282 | Keep in mind, that you will want to ensure that any custom error handler you add performs the logic to replace variables in error messages.
4283 |
4284 | This is what the default error handler looks like, for example:
4285 |
4286 | ```
4287 | defmodule AshGraphql.DefaultErrorHandler do
4288 | @moduledoc "Replaces any text in message or short_message with variables"
4289 |
4290 | def handle_error(
4291 | %{message: message, short_message: short_message, vars: vars} = error,
4292 | _context
4293 | ) do
4294 | %{
4295 | error
4296 | | message: replace_vars(message, vars),
4297 | short_message: replace_vars(short_message, vars)
4298 | }
4299 | end
4300 |
4301 | def handle_error(other, _), do: other
4302 |
4303 | defp replace_vars(string, vars) do
4304 | vars =
4305 | if is_map(vars) do
4306 | vars
4307 | else
4308 | List.wrap(vars)
4309 | end
4310 |
4311 | Enum.reduce(vars, string, fn {key, value}, acc ->
4312 | if String.contains?(acc, "%{#{key}}") do
4313 | String.replace(acc, "%{#{key}}", to_string(value))
4314 | else
4315 | acc
4316 | end
4317 | end)
4318 | end
4319 | end
4320 | ```
4321 |
4322 | ### [](handle-errors.html#error-handler-in-resources)Error handler in resources
4323 |
4324 | Error handlers can also be specified in a resource. For examples:
4325 |
4326 | ```
4327 | defmodule MyApp.Resource do
4328 | use Ash.Resource,
4329 | domain: [MyApp.Domain],
4330 | extensions: [AshGraphql]
4331 |
4332 | graphql do
4333 | type :ticket
4334 | error_handler {MyApp.Resource.GraphqlErrorHandler, :handle_error, []}
4335 | end
4336 |
4337 | # ...
4338 | end
4339 | ```
4340 |
4341 | If both an error handler for the resource and one for the domain are defined, they both take action: first the resource handler and then the domain handler.
4342 |
4343 | If an action on a resource calls other actions (e.g. with a `manage_relationships`) the errors are handled by the primary resource that called the action.
4344 |
4345 | ### [](handle-errors.html#filtering-by-action)Filtering by action
4346 |
4347 | The error handler carries in the context the name of the primary action that returned the error down the line. With that one can set different behaviors depending on the specific action that triggered the error. For example consider the following resource with `:create`, `:custom_create` and `:update` actions:
4348 |
4349 | ```
4350 | defmodule MyApp.Resource do
4351 | use Ash.Resource,
4352 | domain: [MyApp.Domain],
4353 | extensions: [AshGraphql]
4354 |
4355 | graphql do
4356 | type :ticket
4357 | error_handler {MyApp.Resource.GraphqlErrorHandler, :handle_error, []}
4358 | end
4359 |
4360 | actions do
4361 | deafults [:read, :destroy, :create]
4362 | create :custom_create do
4363 | # ...
4364 | change manage_relationships # ...
4365 | end
4366 |
4367 | update :update do
4368 | # ...
4369 | end
4370 | end
4371 | end
4372 | ```
4373 |
4374 | The error handler `MyApp.Resource.GraphqlErrorHandler` can in this case set different behaviors depending on the specific action that caused the error:
4375 |
4376 | ```
4377 | defmodule MyApp.Resource.GraphqlErrorHandler do
4378 |
4379 | def handle_error(error, context) do
4380 | %{action: action} = context
4381 |
4382 | case action do
4383 | :custom_create -> custom_create_behavior(error)
4384 | :update -> update_behavior(error)
4385 |
4386 | _ -> deafult_behvaior(error)
4387 | end
4388 | end
4389 | end
4390 | ```
4391 |
4392 | ## [](handle-errors.html#custom-errors)Custom Errors
4393 |
4394 | If you created your own Errors as described in the [Ash Docs](../ash/error-handling.html#using-a-custom-exception) you also need to implement the protocol for it to be displayed in the Api.
4395 |
4396 | ```
4397 | defmodule Ash.Error.Action.InvalidArgument do
4398 | @moduledoc "Used when an invalid value is provided for an action argument"
4399 | use Splode.Error, fields: [:field, :message, :value], class: :invalid
4400 |
4401 | def message(error) do
4402 | """
4403 | Invalid value provided#{for_field(error)}#{do_message(error)}
4404 |
4405 | #{inspect(error.value)}
4406 | """
4407 | end
4408 |
4409 | defimpl AshGraphql.Error, for: Ash.Error.Changes.InvalidArgument do
4410 | def to_error(error) do
4411 | %{
4412 | message: error.message,
4413 | short_message: error.message,
4414 | code: "invalid_argument",
4415 | vars: Map.new(error.vars),
4416 | fields: [error.field]
4417 | }
4418 | end
4419 | end
4420 | end
4421 | ```
4422 |
4423 | [← Previous Page Authorize with GraphQL](authorize-with-graphql.html)
4424 |
4425 | [Next Page → Generic Actions](generic-actions.html)
4426 |
4427 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/handle-errors.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4428 |
4429 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4430 | [](https://github.com/ash-project/ash_graphql)
4431 |
4432 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4433 |
4434 | v1.5.0
4435 |
4436 | - GUIDES
4437 | - Modules
4438 | - Mix Tasks
4439 |
4440 | <!--THE END-->
4441 |
4442 | <!--THE END-->
4443 |
4444 | <!--THE END-->
4445 |
4446 | Search documentation of ash\_graphql
4447 |
4448 | Settings
4449 |
4450 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/mix/tasks/ash_graphql.install.ex#L2 "View Source") mix ash\_graphql.install (ash\_graphql v1.5.0)
4451 |
4452 | Installs AshGraphql. Should be run with `mix igniter.install ash_graphql`
4453 |
4454 | # [](Mix.Tasks.AshGraphql.Install.html#summary)Summary
4455 |
4456 | ## [Functions](Mix.Tasks.AshGraphql.Install.html#functions)
4457 |
4458 | [igniter(igniter, argv)](Mix.Tasks.AshGraphql.Install.html#igniter/2)
4459 |
4460 | Callback implementation for [`Igniter.Mix.Task.igniter/2`](../igniter/0.5.3/Igniter.Mix.Task.html#c:igniter/2).
4461 |
4462 | # [](Mix.Tasks.AshGraphql.Install.html#functions)Functions
4463 |
4464 | [](Mix.Tasks.AshGraphql.Install.html#igniter/2)
4465 |
4466 | # igniter(igniter, argv)
4467 |
4468 | [](https://github.com/ash-project/ash_graphql/blob/v1.5.0/lib/mix/tasks/ash_graphql.install.ex#L8)
4469 |
4470 | Callback implementation for [`Igniter.Mix.Task.igniter/2`](../igniter/0.5.3/Igniter.Mix.Task.html#c:igniter/2).
4471 |
4472 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4473 |
4474 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4475 | [](https://github.com/ash-project/ash_graphql)
4476 |
4477 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4478 |
4479 | v1.5.0
4480 |
4481 | - GUIDES
4482 | - Modules
4483 | - Mix Tasks
4484 |
4485 | <!--THE END-->
4486 |
4487 | <!--THE END-->
4488 |
4489 | <!--THE END-->
4490 |
4491 | Search documentation of ash\_graphql
4492 |
4493 | Settings
4494 |
4495 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/modifying-the-resolution.md#L1 "View Source") Modifying the Resolution
4496 |
4497 | Using the `modify_resolution` option, you can alter the [`Absinthe.Resolution`](../absinthe/1.7.8/Absinthe.Resolution.html).
4498 |
4499 | `modify_resolution` is an MFA that will be called with the resolution, the query, and the result of the action as the first three arguments. Must return a new [`Absinthe.Resolution`](../absinthe/1.7.8/Absinthe.Resolution.html).
4500 |
4501 | This can be used to implement things like setting cookies based on resource actions. A method of using resolution context for that is documented [in Absinthe.Plug](../absinthe_plug/Absinthe.Plug.html#module-before-send)
4502 |
4503 | ### [](modifying-the-resolution.html#as_mutation)as\_mutation?
4504 |
4505 | If you are modifying the context in a query, then you should also set `as_mutation?` to true and represent this in your graphql as a mutation. See `as_mutation?` for more.
4506 |
4507 | [← Previous Page GraphQL Query Generation](graphql-generation.html)
4508 |
4509 | [Next Page → Relay](relay.html)
4510 |
4511 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/modifying-the-resolution.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4512 |
4513 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4514 | [](https://github.com/ash-project/ash_graphql)
4515 |
4516 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4517 |
4518 | v1.5.0
4519 |
4520 | - GUIDES
4521 | - Modules
4522 | - Mix Tasks
4523 |
4524 | <!--THE END-->
4525 |
4526 | <!--THE END-->
4527 |
4528 | <!--THE END-->
4529 |
4530 | Search documentation of ash\_graphql
4531 |
4532 | Settings
4533 |
4534 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/monitoring.md#L1 "View Source") Monitoring
4535 |
4536 | Please read [the Ash monitoring guide](../ash/monitoring.html) for more information. Here we simply cover the additional traces & telemetry events that we publish from this extension.
4537 |
4538 | A tracer can be configured in the domain. It will fallback to the global tracer configuration `config :ash, :tracer, Tracer`
4539 |
4540 | ```
4541 | graphql do
4542 | trace MyApp.Tracer
4543 | end
4544 | ```
4545 |
4546 | ## [](monitoring.html#traces)Traces
4547 |
4548 | Each graphql resolver, and batch resolution of the underlying data loader, will produce a span with an appropriate name. We also set a `source: :graphql` metadata if you want to filter them out or annotate them in some way.
4549 |
4550 | ## [](monitoring.html#telemetry)Telemetry
4551 |
4552 | AshGraphql emits the following telemetry events, suffixed with `:start` and `:stop`. Start events have `system_time` measurements, and stop events have `system_time` and `duration` measurements. All times will be in the native time unit.
4553 |
4554 | - `[:ash, <domain_short_name>, :gql_mutation]` - The execution of a mutation. Use `resource_short_name` and `mutation` (or `action`) metadata to break down measurements.
4555 | - `[:ash, <domain_short_name>, :gql_query]` - The execution of a mutation. Use `resource_short_name` and `query` (or `action`) metadata to break down measurements.
4556 | - `[:ash, <domain_short_name>, :gql_relationship]` - The resolution of a relationship. Use `resource_short_name` and `relationship` metadata to break down measurements.
4557 | - `[:ash, <domain_short_name>, :gql_calculation]` - The resolution of a calculation. Use `resource_short_name` and `calculation` metadata to break down measurements.
4558 | - `[:ash, <domain_short_name>, :gql_relationship_batch]` - The resolution of a batch of relationships by the data loader. Use `resource_short_name` and `relationship` metadata to break down measurements.
4559 | - `[:ash, <domain_short_name>, :gql_calculation_batch]` - The resolution of a batch of calculations by the data loader. Use `resource_short_name` and `calculation` metadata to break down measurements.
4560 |
4561 | [← Previous Page Use Maps with GraphQL](use-maps-with-graphql.html)
4562 |
4563 | [Next Page → GraphQL Query Generation](graphql-generation.html)
4564 |
4565 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/monitoring.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4566 |
4567 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4568 | [](https://github.com/ash-project/ash_graphql)
4569 |
4570 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4571 |
4572 | v1.5.0
4573 |
4574 | - GUIDES
4575 | - Modules
4576 | - Mix Tasks
4577 |
4578 | <!--THE END-->
4579 |
4580 | <!--THE END-->
4581 |
4582 | <!--THE END-->
4583 |
4584 | Search documentation of ash\_graphql
4585 |
4586 | Settings
4587 |
4588 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/README.md#L1 "View Source") Home
4589 |
4590 |  
4591 |
4592 |  [](https://opensource.org/licenses/MIT) [](https://hex.pm/packages/ash_graphql) [](../ash_graphql.html)
4593 |
4594 | # AshGraphql
4595 |
4596 | Welcome! This is the extension for building GraphQL APIs with [Ash](../ash.html). The generated GraphQL APIs are powered by [Absinthe](../absinthe.html). Generate a powerful Graphql API in minutes!
4597 |
4598 | ## [](readme.html#tutorials)Tutorials
4599 |
4600 | - [Getting Started with GraphQL](getting-started-with-graphql.html)
4601 |
4602 | ## [](readme.html#topics)Topics
4603 |
4604 | - [Authorize with GraphQL](authorize-with-graphql.html)
4605 | - [Handle Errors](handle-errors.html)
4606 | - [Monitoring](monitoring.html)
4607 | - [Use JSON with GraphQL](use-json-with-graphql.html)
4608 | - [Use Subscriptions with GraphQL](use-subscriptions-with-graphql.html)
4609 | - [GraphQL Generation](graphql-generation.html)
4610 | - [Modifying the Resolution](modifying-the-resolution.html)
4611 | - [Relay](relay.html)
4612 | - [Use Enums with GraphQL](use-enums-with-graphql.html)
4613 | - [Use Maps with GraphQL](use-maps-with-graphql.html)
4614 | - [Use Unions with GraphQL](use-unions-with-graphql.html)
4615 | - [Upgrading to 1.0](upgrade.html)
4616 |
4617 | ## [](readme.html#reference)Reference
4618 |
4619 | - [AshGraphql.Resource DSL](dsl-ashgraphql-resource.html)
4620 | - [AshGraphql.Domain DSL](dsl-ashgraphql-domain.html)
4621 |
4622 | [← Previous Page API Reference](api-reference.html)
4623 |
4624 | [Next Page → Getting Started With GraphQL](getting-started-with-graphql.html)
4625 |
4626 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/README.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4627 |
4628 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4629 | [](https://github.com/ash-project/ash_graphql)
4630 |
4631 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4632 |
4633 | v1.5.0
4634 |
4635 | - GUIDES
4636 | - Modules
4637 | - Mix Tasks
4638 |
4639 | <!--THE END-->
4640 |
4641 | <!--THE END-->
4642 |
4643 | <!--THE END-->
4644 |
4645 | Search documentation of ash\_graphql
4646 |
4647 | Settings
4648 |
4649 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/relay.md#L1 "View Source") Relay
4650 |
4651 | Enabling Relay for a resource sets it up to follow the [Relay specification](https://relay.dev/graphql/connections.htm).
4652 |
4653 | The two changes that are made currently are:
4654 |
4655 | - the type for the resource will implement the [`Node`](../elixir/Node.html) interface
4656 | - pagination over that resource will behave as a `Connection`.
4657 |
4658 | ## [](relay.html#using-ash-s-built-in-relay-support)Using Ash's built-in Relay support
4659 |
4660 | Set `relay? true` on the resource:
4661 |
4662 | ```
4663 | graphql do
4664 | relay? true
4665 |
4666 | ...
4667 | end
4668 | ```
4669 |
4670 | ## [](relay.html#relay-global-ids)Relay Global IDs
4671 |
4672 | Use the following option to generate Relay Global IDs (see [here](https://relay.dev/graphql/objectidentification.htm)).
4673 |
4674 | ```
4675 | use AshGraphql, relay_ids?: true
4676 | ```
4677 |
4678 | This allows refetching a node using the `node` query and passing its global ID.
4679 |
4680 | ### [](relay.html#translating-relay-global-ids-passed-as-arguments)Translating Relay Global IDs passed as arguments
4681 |
4682 | When `relay_ids?: true` is passed, users of the API will have access only to the global IDs, so they will also need to use them when an ID is required as argument. You actions, though, internally use the normal IDs defined by the data layer.
4683 |
4684 | To handle the translation between the two ID domains, you can use the `relay_id_translations` option. With this, you can define a list of arguments that will be translated from Relay global IDs to internal IDs.
4685 |
4686 | For example, if you have a `Post` resource with an action to create a post associated with an author:
4687 |
4688 | ```
4689 | create :create do
4690 | argument :author_id, :uuid
4691 |
4692 | # Do stuff with author_id
4693 | end
4694 | ```
4695 |
4696 | You can add this to the mutation connected to that action:
4697 |
4698 | ```
4699 | mutations do
4700 | create :create_post, :create do
4701 | relay_id_translations [input: [author_id: :user]]
4702 | end
4703 | end
4704 | ```
4705 |
4706 | ## [](relay.html#using-with-absinthe-relay-instead-of-ash-s-relay-type)Using with Absinthe.Relay instead of Ash's relay type
4707 |
4708 | Use the following option when calling `use AshGraphql`
4709 |
4710 | ```
4711 | use AshGraphql, define_relay_types?: false
4712 | ```
4713 |
4714 | [← Previous Page Modifying the Resolution](modifying-the-resolution.html)
4715 |
4716 | [Next Page → Custom Queries & Mutations](custom-queries-and-mutations.html)
4717 |
4718 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/relay.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4719 |
4720 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4721 | [](https://github.com/ash-project/ash_graphql)
4722 |
4723 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4724 |
4725 | v1.5.0
4726 |
4727 | - GUIDES
4728 | - Modules
4729 | - Mix Tasks
4730 |
4731 | <!--THE END-->
4732 |
4733 | <!--THE END-->
4734 |
4735 | <!--THE END-->
4736 |
4737 | Search documentation of ash\_graphql
4738 |
4739 | Settings
4740 |
4741 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/sdl-file.md#L1 "View Source") Using the SDL File
4742 |
4743 | By passing the `generate_sdl_file` to `use AshGraphql`, AshGraphql will generate a schema file when you run [`mix ash.codegen`](../ash/3.4.50/Mix.Tasks.Ash.Codegen.html). For example:
4744 |
4745 | ```
4746 | use AshGraphql,
4747 | domains: [Domain1, Domain2],
4748 | generate_sdl_file: "priv/schema.graphql"
4749 | ```
4750 |
4751 | ### [](sdl-file.html#ensure-your-schema-is-up-to-date-gitignored-or-not-generated)Ensure your schema is up to date, gitignored, or not generated
4752 |
4753 | We suggest first adding `mix ash.codegen --check` to your CI/CD pipeline to ensure the schema is always up-to-date. Alternatively you can add the file to your `.gitignore`, or you can remove the `generate_sdl_file` option to skip generating the file.
4754 |
4755 | With the `generate_sdl_file` option, calls to `mix ash.codegen <name>` will generate a `.graphql` file at the specified path.
4756 |
4757 | Some things that you can use this SDL file for:
4758 |
4759 | ## [](sdl-file.html#documentation)Documentation
4760 |
4761 | The schema file itself represents your entire GraphQL API definition, and examining it can be very useful.
4762 |
4763 | ## [](sdl-file.html#code-generation)Code Generation
4764 |
4765 | You can use tools like [GraphQL codegen](https://the-guild.dev/graphql/codegen) to generate a client for your GraphQL API.
4766 |
4767 | ## [](sdl-file.html#validating-changes)Validating Changes
4768 |
4769 | Use the SDL file to check for breaking changes in your schema, especially if you are exposing a public API. A plug and play github action for this can be found here: [https://the-guild.dev/graphql/inspector/docs/products/action](https://the-guild.dev/graphql/inspector/docs/products/action)
4770 |
4771 | [← Previous Page Generic Actions](generic-actions.html)
4772 |
4773 | [Next Page → Use Enums with GraphQL](use-enums-with-graphql.html)
4774 |
4775 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/sdl-file.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4776 |
4777 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4778 | [](https://github.com/ash-project/ash_graphql)
4779 |
4780 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4781 |
4782 | v1.5.0
4783 |
4784 | - GUIDES
4785 | - Modules
4786 | - Mix Tasks
4787 |
4788 | <!--THE END-->
4789 |
4790 | <!--THE END-->
4791 |
4792 | <!--THE END-->
4793 |
4794 | Search documentation of ash\_graphql
4795 |
4796 | Settings
4797 |
4798 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/use-enums-with-graphql.md#L1 "View Source") Use Enums with GraphQL
4799 |
4800 | If you define an [`Ash.Type.Enum`](../ash/3.4.50/Ash.Type.Enum.html), that enum type can be used both in attributes *and* arguments. You will need to add `graphql_type/0` to your implementation. AshGraphql will ensure that a single type is defined for it, which will be reused across all occurrences. If an enum type is referenced, but does not have `graphql_type/0` defined, it will be treated as a string input.
4801 |
4802 | For example:
4803 |
4804 | ```
4805 | defmodule AshPostgres.Test.Types.Status do
4806 | @moduledoc false
4807 | use Ash.Type.Enum, values: [:open, :closed]
4808 |
4809 | def graphql_type(_), do: :ticket_status
4810 |
4811 | # Optionally, remap the names used in GraphQL, for instance if you have a value like `:"10"`
4812 | # that value is not compatible with GraphQL
4813 |
4814 | def graphql_rename_value(:"10"), do: :ten
4815 | def graphql_rename_value(value), do: value
4816 |
4817 | # You can also provide descriptions for the enum values, which will be exposed in the GraphQL
4818 | # schema.
4819 | # Remember to have a fallback clause that returns nil if you don't provide descriptions for all
4820 | # values.
4821 |
4822 | def graphql_describe_enum_value(:open), do: "The post is open"
4823 | def graphql_describe_enum_value(_), do: nil
4824 | end
4825 | ```
4826 |
4827 | ### [](use-enums-with-graphql.html#using-custom-absinthe-types)Using custom absinthe types
4828 |
4829 | You can implement a custom enum by first adding the enum type to your absinthe schema (more [here](../absinthe/Absinthe.Type.Enum.html)). Then you can define a custom Ash type that refers to that absinthe enum type.
4830 |
4831 | ```
4832 | # In your absinthe schema:
4833 |
4834 | enum :status do
4835 | value(:open, description: "The post is open")
4836 | value(:closed, description: "The post is closed")
4837 | end
4838 | ```
4839 |
4840 | ```
4841 | # Your custom Ash Type
4842 | defmodule AshGraphql.Test.Status do
4843 | use Ash.Type.Enum, values: [:open, :closed]
4844 |
4845 | use AshGraphql.Type
4846 |
4847 | @impl true
4848 | # tell Ash not to define the type for that enum
4849 | def graphql_define_type?(_), do: false
4850 | end
4851 | ```
4852 |
4853 | [← Previous Page Using the SDL File](sdl-file.html)
4854 |
4855 | [Next Page → Use JSON with GraphQL](use-json-with-graphql.html)
4856 |
4857 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/use-enums-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4858 |
4859 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4860 | [](https://github.com/ash-project/ash_graphql)
4861 |
4862 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4863 |
4864 | v1.5.0
4865 |
4866 | - GUIDES
4867 | - Modules
4868 | - Mix Tasks
4869 |
4870 | <!--THE END-->
4871 |
4872 | <!--THE END-->
4873 |
4874 | <!--THE END-->
4875 |
4876 | Search documentation of ash\_graphql
4877 |
4878 | Settings
4879 |
4880 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/use-json-with-graphql.md#L1 "View Source") Use JSON with GraphQL
4881 |
4882 | AshGraphql provides two JSON types that may be used. They are the same except for how the type is serialized in responses.
4883 |
4884 | - `:json_string` - serializes the json to a string, e.g `"{\"foo\":1}"`
4885 | - `:json` - leaves the json as an object, e.g `{foo: 1}`
4886 |
4887 | By default, `:json_string` is used. The configuration for this is (uncharacteristically) placed in application config, for example:
4888 |
4889 | ```
4890 | config :ash_graphql, :json_type, :json
4891 | ```
4892 |
4893 | [← Previous Page Use Enums with GraphQL](use-enums-with-graphql.html)
4894 |
4895 | [Next Page → Using Subscriptions](use-subscriptions-with-graphql.html)
4896 |
4897 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/use-json-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4898 |
4899 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4900 | [](https://github.com/ash-project/ash_graphql)
4901 |
4902 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4903 |
4904 | v1.5.0
4905 |
4906 | - GUIDES
4907 | - Modules
4908 | - Mix Tasks
4909 |
4910 | <!--THE END-->
4911 |
4912 | <!--THE END-->
4913 |
4914 | <!--THE END-->
4915 |
4916 | Search documentation of ash\_graphql
4917 |
4918 | Settings
4919 |
4920 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/use-maps-with-graphql.md#L1 "View Source") Use Maps with GraphQL
4921 |
4922 | If you define an [`Ash.Type.NewType`](../ash/3.4.50/Ash.Type.NewType.html) that is a subtype of `:map`, *and* you add the `fields` constraint which specifies field names and their types, [`AshGraphql`](AshGraphql.html) will automatically derive an appropriate GraphQL type for it.
4923 |
4924 | For example:
4925 |
4926 | ```
4927 | defmodule MyApp.Types.Metadata do
4928 | @moduledoc false
4929 | use Ash.Type.NewType, subtype_of: :map, constraints: [
4930 | fields: [
4931 | title: [
4932 | type: :string
4933 | ],
4934 | description: [
4935 | type: :string
4936 | ]
4937 | ]
4938 | ]
4939 |
4940 | def graphql_type(_), do: :metadata
4941 | end
4942 | ```
4943 |
4944 | ## [](use-maps-with-graphql.html#bypassing-type-generation-for-an-map)Bypassing type generation for an map
4945 |
4946 | Add the `graphql_define_type?/1` callback, like so, to skip Ash's generation (i.e if you're defining it yourself)
4947 |
4948 | ```
4949 | @impl true
4950 | def graphql_define_type?(_), do: false
4951 | ```
4952 |
4953 | [← Previous Page Use Unions with GraphQL](use-unions-with-graphql.html)
4954 |
4955 | [Next Page → Monitoring](monitoring.html)
4956 |
4957 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/use-maps-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
4958 |
4959 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
4960 | [](https://github.com/ash-project/ash_graphql)
4961 |
4962 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
4963 |
4964 | v1.5.0
4965 |
4966 | - GUIDES
4967 | - Modules
4968 | - Mix Tasks
4969 |
4970 | <!--THE END-->
4971 |
4972 | <!--THE END-->
4973 |
4974 | <!--THE END-->
4975 |
4976 | Search documentation of ash\_graphql
4977 |
4978 | Settings
4979 |
4980 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/use-subscriptions-with-graphql.md#L1 "View Source") Using Subscriptions
4981 |
4982 | You can do this with Absinthe directly, and use [`AshGraphql.Subscription.query_for_subscription/3`](AshGraphql.Subscription.html#query_for_subscription/3). Here is an example of how you could do this for a subscription for a single record. This example could be extended to support lists of records as well.
4983 |
4984 | ```
4985 | # in your absinthe schema file
4986 | subscription do
4987 | field :field, :type_name do
4988 | config(fn
4989 | _args, %{context: %{current_user: %{id: user_id}}} ->
4990 | {:ok, topic: user_id, context_id: "user/#{user_id}"}
4991 |
4992 | _args, _context ->
4993 | {:error, :unauthorized}
4994 | end)
4995 |
4996 | resolve(fn args, _, resolution ->
4997 | # loads all the data you need
4998 | AshGraphql.Subscription.query_for_subscription(
4999 | YourResource,
5000 | YourDomain,
5001 | resolution
5002 | )
5003 | |> Ash.Query.filter(id == ^args.id)
5004 | |> Ash.read(actor: resolution.context.current_user)
5005 | end)
5006 | end
5007 | end
5008 | ```
5009 |
5010 | ## [](use-subscriptions-with-graphql.html#subscription-dsl-beta)Subscription DSL (beta)
5011 |
5012 | The subscription DSL is currently in beta and before using it you have to enable them in your config.
5013 |
5014 | ### [](use-subscriptions-with-graphql.html#subscription-response-order)Subscription response order
5015 |
5016 | The order in which the subscription responses are sent to the client is not guaranteed to be the same as the order in which the mutations were executed.
5017 |
5018 | ```
5019 | config :ash_graphql, :subscriptions, true
5020 | ```
5021 |
5022 | First you'll need to do some setup, follow the the [setup guide](../absinthe/subscriptions.html#absinthe-phoenix-setup) in the absinthe docs, but instead of using `Absinthe.Pheonix.Endpoint` use [`AshGraphql.Subscription.Endpoint`](AshGraphql.Subscription.Endpoint.html).
5023 |
5024 | By default subscriptions are resolved synchronously as part of the mutation. This means that a resolver is run for every subscriber that is not deduplicated. If you have a lot of subscribers you can add the [`AshGraphql.Subscription.Batcher`](AshGraphql.Subscription.Batcher.html) to your supervision tree, which batches up notifications and runs subscription resolution out-of-band.
5025 |
5026 | ```
5027 | @impl true
5028 | def start(_type, _args) do
5029 | children = [
5030 | ...,
5031 | {Absinthe.Subscription, MyAppWeb.Endpoint},
5032 | AshGraphql.Subscription.Batcher
5033 | ]
5034 |
5035 | # See https://hexdocs.pm/elixir/Supervisor.html
5036 | # for other strategies and supported options
5037 | opts = [strategy: :one_for_one, name: MyAppWeb.Supervisor]
5038 | Supervisor.start_link(children, opts)
5039 | end
5040 | ```
5041 |
5042 | Afterwards, add an empty subscription block to your schema module.
5043 |
5044 | ```
5045 | defmodule MyAppWeb.Schema do
5046 | ...
5047 |
5048 | subscription do
5049 | end
5050 | end
5051 | ```
5052 |
5053 | Now you can define subscriptions on your resource or domain
5054 |
5055 | ```
5056 | defmodule MyApp.Resource do
5057 | use Ash.Resource,
5058 | data_layer: Ash.DataLayer.Ets,
5059 | extensions: [AshGraphql.Resource]
5060 |
5061 | graphql do
5062 | subscriptions do
5063 | subscribe :resource_created do
5064 | action_types :create
5065 | end
5066 | end
5067 | end
5068 | end
5069 | ```
5070 |
5071 | For further Details checkout the DSL docs for [resource](dsl-ashgraphql-resource.html#graphql-subscriptions) and [domain](dsl-ashgraphql-domain.html#graphql-subscriptions)
5072 |
5073 | ### [](use-subscriptions-with-graphql.html#deduplication)Deduplication
5074 |
5075 | By default, Absinthe will deduplicate subscriptions based on the `context_id`. We use the some of the context like actor and tenant to create a `context_id` for you.
5076 |
5077 | If you want to customize the deduplication you can do so by adding a actor function to your subscription. This function will be called with the actor that subscribes and you can return a more generic actor, this way you can have one actor for multiple users, which will lead to less resolver executions.
5078 |
5079 | ```
5080 | defmodule MyApp.Resource do
5081 | use Ash.Resource,
5082 | data_layer: Ash.DataLayer.Ets,
5083 | extensions: [AshGraphql.Resource]
5084 |
5085 | graphql do
5086 | subscriptions do
5087 | subscribe :resource_created do
5088 | action_types :create
5089 | actor fn actor ->
5090 | if check_actor(actor) do
5091 | %{id: "your generic actor", ...}
5092 | else
5093 | actor
5094 | end
5095 | end
5096 | end
5097 | end
5098 | end
5099 | end
5100 | ```
5101 |
5102 | [← Previous Page Use JSON with GraphQL](use-json-with-graphql.html)
5103 |
5104 | [Next Page → Use Unions with GraphQL](use-unions-with-graphql.html)
5105 |
5106 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/use-subscriptions-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
5107 |
5108 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
5109 | [](https://github.com/ash-project/ash_graphql)
5110 |
5111 | [ash\_graphql](https://github.com/ash-project/ash_graphql)
5112 |
5113 | v1.5.0
5114 |
5115 | - GUIDES
5116 | - Modules
5117 | - Mix Tasks
5118 |
5119 | <!--THE END-->
5120 |
5121 | <!--THE END-->
5122 |
5123 | <!--THE END-->
5124 |
5125 | Search documentation of ash\_graphql
5126 |
5127 | Settings
5128 |
5129 | # [View Source](https://github.com/ash-project/ash_graphql/blob/v1.5.0/documentation/topics/use-unions-with-graphql.md#L1 "View Source") Use Unions with GraphQL
5130 |
5131 | Unions must be defined with [`Ash.Type.NewType`](../ash/3.4.50/Ash.Type.NewType.html):
5132 |
5133 | ```
5134 | defmodule MyApp.Armor do
5135 | use Ash.Type.NewType, subtype_of: :union, constraints: [
5136 | types: [
5137 | plate: [
5138 | # This is an embedded resource, with its own fields
5139 | type: MyApp.Armor.Plate
5140 | ],
5141 | chain_mail: [
5142 | # And so is this
5143 | type: MyApp.Armor.ChainMail
5144 | ],
5145 | custom: [
5146 | type: :string
5147 | ]
5148 | ]
5149 | ]
5150 |
5151 | use AshGraphql.Type
5152 |
5153 | # Add this to define the union in ash_graphql
5154 | def graphql_type(_), do: :armor
5155 | end
5156 | ```
5157 |
5158 | By default, the type you would get for this on input and output would look something like this:
5159 |
5160 | ```
5161 | type Armor = {plate: {value: Plate}} | {chain_mail: {value: ChainMail}} | {custom: {value: String}}
5162 | ```
5163 |
5164 | We do this by default to solve for potentially ambiguous types. An example of this might be if you had multiple different types of strings in a union, and you wanted the client to be able to tell exactly which type of string they'd been given. i.e `{social: {value: "555-55-5555"}} | {phone_number: {value: "555-5555"}}`.
5165 |
5166 | However, you can clean the type in cases where you have no such conflicts by by providing
5167 |
5168 | ```
5169 | # Put anything in here that does not need to be named/nested with `{type_name: {value: value}}`
5170 | def graphql_unnested_unions(_constraints), do: [:plate, :chain_mail]
5171 | ```
5172 |
5173 | Which, in this case, would yield:
5174 |
5175 | ```
5176 | type Armor = Plate | ChainMail | {custom: {value: String}}
5177 | ```
5178 |
5179 | ## [](use-unions-with-graphql.html#bypassing-type-generation-for-a-union)Bypassing type generation for a union
5180 |
5181 | Add the `graphql_define_type?/1` callback, like so, to skip Ash's generation (i.e if you're defining it yourself)
5182 |
5183 | ```
5184 | @impl true
5185 | def graphql_define_type?(_), do: false
5186 | ```
5187 |
5188 | [← Previous Page Using Subscriptions](use-subscriptions-with-graphql.html)
5189 |
5190 | [Next Page → Use Maps with GraphQL](use-maps-with-graphql.html)
5191 |
5192 | [Hex Package](https://hex.pm/packages/ash_graphql/1.5.0) [Hex Preview](https://preview.hex.pm/preview/ash_graphql/1.5.0) ([current file](https://preview.hex.pm/preview/ash_graphql/1.5.0/show/documentation/topics/use-unions-with-graphql.md)) Search HexDocs [Download ePub version](ash_graphql.epub "ePub version")
5193 |
5194 | Built using [ExDoc](https://github.com/elixir-lang/ex_doc "ExDoc") (v0.36.1) for the [Elixir programming language](https://elixir-lang.org "Elixir")
5195 |
```