ash_graphql/lib/resource/mutation.ex

138 lines
3.9 KiB
Elixir
Raw Permalink 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,
:resource,
:upsert?,
:upsert_identity,
:modify_resolution,
:relay_id_translations,
:description,
hide_inputs: []
]
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
],
description: [
type: :string,
doc:
"The mutation description that gets shown in the Graphql schema. If not provided, the action description will be used."
],
upsert?: [
type: :boolean,
default: false,
improvement!: port AshGraphql to Ash 3.0 (#123) Step 1: update Ash Step 2: mass rename Api to Domain Step 3: Ash.Query.expr -> Ash.Expr.expr Also change ref interpolation Step 4: remove all warnings Step 5: remove registries from tests Step 6: fix filter Step 7: private? -> !public? Step 8: Ash.Calculation -> Ash.Resource.Calculation Step 9: use depend_on_resources/1 -> resources/1 Step 10: add Domain to all resources Step 11: use Ash module for all actions Step 12: add public? true all around Step 13: remove verbose? from options passed during Domain calls Step 14: add simple_sat Step 15: Ash.ErrorKind is no more, so remove code from errors Step 16: sprinkle default_accept :* around tests Step 17: replace Ash.Changeset.new/2 with Ash.Changeset.for_* Step 18: calculation fixups - Context is now a struct and arguments go under the arguments key - Function based calculations receive a list of records - Add a select to query-based loads - select -> load Step 19: pass the correct name to pass the policy in tests Step 20: Ash.Query.new/2 is no more Step 21: add AshGraphql.Resource.embedded? utility function Use that instead of Ash.Type.embedded_type?(resource_or_type) since resources are not types anymore Step 22: handle struct + instance_of: Resource in unions Resources are not type anymore so they need to be passed this way in unions Step 23: ensure we only check GraphQL actions for pagination All reads are now paginated by default, so this triggered a compilation error Step 24: swap arguments for sort on calculations Step 25: remove unused debug? option
2024-04-02 07:03:06 +13:00
doc: "Whether or not to use the `upsert?: true` option when calling `YourDomain.create/2`."
],
upsert_identity: [
type: :atom,
default: false,
doc: "Which identity to use for the upsert"
],
modify_resolution: [
type: :mfa,
doc: """
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.
"""
],
hide_inputs: [
type: {:list, :atom},
default: [],
doc: "A list of inputs to hide from the mutation."
],
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
],
identity: [
type: :atom,
doc: """
The identity to use to fetch the record to be updated. Use `false` if no identity is required.
"""
],
read_action: [
type: :atom,
doc:
"The read action to use to fetch the record to be updated. Defaults to the primary read action."
],
hide_inputs: [
type: {:list, :atom},
doc: "A list of inputs to hide from the mutation."
],
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
],
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. Use `false` if no identity is required.
"""
],
hide_inputs: [
type: {:list, :atom},
doc: "A list of inputs to hide from the mutation."
],
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