ash_graphql/lib/resource/mutation.ex

94 lines
2.5 KiB
Elixir
Raw Normal View History

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"
defstruct [
:name,
:action,
:type,
:identity,
:read_action,
:upsert?,
:modify_resolution
]
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
],
upsert?: [
type: :boolean,
default: false,
doc: "Whether or not to use the `upsert?: true` option when calling `YourApi.create/2`."
],
modify_resolution: [
type: :mfa,
doc: """
An MFA that will be called with the resolution, the changeset, and the result of the action as the first three arguments (followed by the arguments in the mfa).
Must return a new absinthe resolution. This can be used to implement things like setting cookies based on resource actions. A method of using resolution context
for that is documented here: https://hexdocs.pm/absinthe_plug/Absinthe.Plug.html#module-before-send
"""
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
],
identity: [
type: :atom,
doc: """
The identity to use to fetch the record to be updated.
If no identity is required (e.g for a read action that already knows how to fetch the item to be updated), use `false`.
"""
],
read_action: [
type: :atom,
doc:
"The read action to use to fetch the record to be updated. Defaults to the primary read action."
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
],
read_action: [
type: :atom,
doc:
"The read action to use to fetch the record to be destroyed. Defaults to the primary read action."
],
identity: [
type: :atom,
doc: """
The identity to use to fetch the record to be destroyed.
If no identity is required (e.g for a read action that already knows how to fetch the item to be updated), use `false`.
"""
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