2020-08-14 09:39:59 +12:00
defmodule AshGraphql.Resource.Mutation do
2020-08-15 02:20:47 +12:00
@moduledoc " Represents a configured mutation on a resource "
2022-09-26 17:12:10 +13:00
defstruct [
:name ,
:action ,
:type ,
:identity ,
:read_action ,
2024-05-25 07:51:19 +12:00
:resource ,
2022-09-26 17:12:10 +13:00
:upsert? ,
2022-10-10 14:05:58 +13:00
:upsert_identity ,
2024-02-07 03:46:09 +13:00
:modify_resolution ,
2024-03-12 03:46:42 +13:00
:relay_id_translations ,
2024-04-30 07:01:26 +12:00
:description ,
2024-03-12 03:46:42 +13:00
hide_inputs : [ ]
2022-09-26 17:12:10 +13:00
]
2020-08-14 09:39:59 +12:00
@create_schema [
name : [
type : :atom ,
doc : " The name to use for the mutation. " ,
default : :get
] ,
action : [
type : :atom ,
doc : " The action to use for the mutation. " ,
required : true
2021-04-06 06:41:16 +12:00
] ,
2024-04-30 07:01:26 +12:00
description : [
type : :string ,
doc :
" The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used. "
] ,
2021-04-06 06:41:16 +12:00
upsert? : [
type : :boolean ,
default : false ,
2024-04-02 07:03:06 +13:00
doc : " Whether or not to use the `upsert?: true` option when calling `YourDomain.create/2`. "
2021-06-15 04:08:26 +12:00
] ,
2022-10-10 14:05:58 +13:00
upsert_identity : [
type : :atom ,
default : false ,
doc : " Which identity to use for the upsert "
] ,
2021-06-15 04:08:26 +12:00
modify_resolution : [
type : :mfa ,
doc : """
2023-09-16 05:45:12 +12:00
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 ] ( / documentation / topics / modifying - the - resolution . html ) for more .
2021-06-15 04:08:26 +12:00
"""
2024-02-07 03:46:09 +13:00
] ,
2024-03-12 03:46:42 +13:00
hide_inputs : [
type : { :list , :atom } ,
default : [ ] ,
doc : " A list of inputs to hide from the mutation. "
] ,
2024-02-07 03:46:09 +13:00
relay_id_translations : [
type : :keyword_list ,
doc : """
A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs . See the [ Relay guide ] ( / documentation / topics / relay . md #translating-relay-global-ids-passed-as-arguments) for more.
""" ,
default : [ ]
2020-08-14 09:39:59 +12:00
]
]
@update_schema [
name : [
type : :atom ,
doc : " The name to use for the mutation. " ,
default : :get
] ,
action : [
type : :atom ,
doc : " The action to use for the mutation. " ,
required : true
2020-11-18 20:14:33 +13:00
] ,
identity : [
type : :atom ,
2021-04-20 07:26:20 +12:00
doc : """
2023-09-16 05:45:12 +12:00
The identity to use to fetch the record to be updated . Use ` false ` if no identity is required .
2021-04-20 07:26:20 +12:00
"""
] ,
read_action : [
type : :atom ,
doc :
" The read action to use to fetch the record to be updated. Defaults to the primary read action. "
2024-02-07 03:46:09 +13:00
] ,
2024-03-12 03:46:42 +13:00
hide_inputs : [
type : { :list , :atom } ,
doc : " A list of inputs to hide from the mutation. "
] ,
2024-02-07 03:46:09 +13:00
relay_id_translations : [
type : :keyword_list ,
doc : """
A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs . See the [ Relay guide ] ( / documentation / topics / relay . md #translating-relay-global-ids-passed-as-arguments) for more.
""" ,
default : [ ]
2020-08-14 09:39:59 +12:00
]
]
@destroy_schema [
name : [
type : :atom ,
doc : " The name to use for the mutation. " ,
default : :get
] ,
action : [
type : :atom ,
doc : " The action to use for the mutation. " ,
required : true
2020-11-18 20:14:33 +13:00
] ,
2021-04-20 07:26:20 +12:00
read_action : [
type : :atom ,
doc :
" The read action to use to fetch the record to be destroyed. Defaults to the primary read action. "
] ,
2020-11-18 20:14:33 +13:00
identity : [
type : :atom ,
2021-04-20 07:26:20 +12:00
doc : """
2023-09-16 05:45:12 +12:00
The identity to use to fetch the record to be destroyed . Use ` false ` if no identity is required .
2021-04-20 07:26:20 +12:00
"""
2024-02-07 03:46:09 +13:00
] ,
2024-03-12 03:46:42 +13:00
hide_inputs : [
type : { :list , :atom } ,
doc : " A list of inputs to hide from the mutation. "
] ,
2024-02-07 03:46:09 +13:00
relay_id_translations : [
type : :keyword_list ,
doc : """
A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs . See the [ Relay guide ] ( / documentation / topics / relay . md #translating-relay-global-ids-passed-as-arguments) for more.
""" ,
default : [ ]
2020-08-14 09:39:59 +12:00
]
]
def create_schema , do : @create_schema
def update_schema , do : @update_schema
def destroy_schema , do : @destroy_schema
end