View Source DSL: AshGraphql.Resource

This Ash resource extension adds configuration for exposing a resource in a graphql.

graphql

Configuration for a given resource in graphql

Nested DSLs

Examples

graphql do
  type :post

  queries do
    get :get_post, :read
    list :list_posts, :read
  end

  mutations do
    create :create_post, :create
    update :update_post, :update
    destroy :destroy_post, :destroy
  end
end

Options

NameTypeDefaultDocs
typeatomThe 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?booleantrueSet to false to disable the automatic generation of a filter input for read actions.
derive_sort?booleantrueSet to false to disable the automatic generation of a sort input for read actions.
encode_primary_key?booleantrueFor 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
relationshipslist(atom)A list of relationships to include on the created type. Defaults to all public relationships where the destination defines a graphql type.
field_nameskeywordA keyword list of name overrides for attributes.
hide_fieldslist(atom)A list of attributes to hide from the domain
show_fieldslist(atom)A list of attributes to show in the domain. If not specified includes all (excluding hide_fiels).
argument_nameskeywordA nested keyword list of action names, to argument name remappings. i.e create: [arg_name: :new_name]
keyset_fieldatomIf 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_typeskeywordA 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_typeskeywordA 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.
primary_key_delimiterString.t"~"If a composite primary key exists, this can be set to determine delimiter used in the id field value.
depth_limitintegerA simple way to prevent massive queries.
generate_object?booleantrueWhether or not to create the GraphQL object, this allows you to manually create the GraphQL object.
filterable_fieldslist(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.

graphql.queries

Queries (read actions) to expose for the resource.

Nested DSLs

Examples

queries do
  get :get_post, :read
  read_one :current_user, :current_user
  list :list_posts, :read
end

graphql.queries.get

get name, action

A query to fetch a record by primary key

Examples

get :get_post, :read

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the query.
actionatomThe action to use for the query.

Options

NameTypeDefaultDocs
identityatomThe identity to use for looking up the record. Pass false to not use an identity.
allow_nil?booleantrueWhether or not the action can return nil.
modify_resolutionmfaAn 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 for more.
type_nameatomOverride 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.
descriptionString.tThe query description that gets shown in the Graphql schema. If not provided, the action description will be used.
metadata_nameskeyword[]Name overrides for metadata fields on the read action.
metadata_typeskeyword[]Type overrides for metadata fields on the read action.
show_metadatalist(atom)The metadata attributes to show. Defaults to all.
as_mutation?booleanfalsePlaces the query in the mutations key instead. Not typically necessary, but is often paired with as_mutation?. See the the guide for more.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.
hide_inputslist(atom)[]A list of inputs to hide from the mutation.

Introspection

Target: AshGraphql.Resource.Query

graphql.queries.read_one

read_one name, action

A query to fetch a record

Examples

read_one :current_user, :current_user

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the query.
actionatomThe action to use for the query.

Options

NameTypeDefaultDocs
allow_nil?booleantrueWhether or not the action can return nil.
type_nameatomOverride 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.
descriptionString.tThe query description that gets shown in the Graphql schema. If not provided, the action description will be used.
metadata_nameskeyword[]Name overrides for metadata fields on the read action.
metadata_typeskeyword[]Type overrides for metadata fields on the read action.
show_metadatalist(atom)The metadata attributes to show. Defaults to all.
as_mutation?booleanfalsePlaces the query in the mutations key instead. Not typically necessary, but is often paired with as_mutation?. See the the guide for more.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.
hide_inputslist(atom)[]A list of inputs to hide from the mutation.

Introspection

Target: AshGraphql.Resource.Query

graphql.queries.list

list name, action

A query to fetch a list of records

Examples

list :list_posts, :read
list :list_posts_paginated, :read, relay?: true

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the query.
actionatomThe action to use for the query.

Options

NameTypeDefaultDocs
relay?booleanfalseIf true, the graphql queries/resolvers for this resource will be built to honor the relay specification. See the relay guide for more.
paginate_with:keyset | :offset | nil:keysetDetermine the pagination strategy to use, if multiple are available. If nil, no pagination is applied, otherwise the given strategy is used.
type_nameatomOverride 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.
descriptionString.tThe query description that gets shown in the Graphql schema. If not provided, the action description will be used.
metadata_nameskeyword[]Name overrides for metadata fields on the read action.
metadata_typeskeyword[]Type overrides for metadata fields on the read action.
show_metadatalist(atom)The metadata attributes to show. Defaults to all.
as_mutation?booleanfalsePlaces the query in the mutations key instead. Not typically necessary, but is often paired with as_mutation?. See the the guide for more.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.
hide_inputslist(atom)[]A list of inputs to hide from the mutation.

Introspection

Target: AshGraphql.Resource.Query

graphql.queries.action

action name, action

Runs a generic action

Examples

action :check_status, :check_status

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the query.
actionatomThe action to use for the query.

Options

NameTypeDefaultDocs
descriptionString.tThe description that gets shown in the Graphql schema. If not provided, the action description will be used.
hide_inputslist(atom)[]Inputs to hide in the mutation/query
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.

Introspection

Target: AshGraphql.Resource.Action

graphql.mutations

Mutations (create/update/destroy actions) to expose for the resource.

Nested DSLs

Examples

mutations do
  create :create_post, :create
  update :update_post, :update
  destroy :destroy_post, :destroy
end

graphql.mutations.create

create name, action

A mutation to create a record

Examples

create :create_post, :create

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the mutation.
actionatomThe action to use for the mutation.

Options

NameTypeDefaultDocs
descriptionString.tThe mutation description that gets shown in the Graphql schema. If not provided, the action description will be used.
upsert?booleanfalseWhether or not to use the upsert?: true option when calling YourDomain.create/2.
upsert_identityatomfalseWhich identity to use for the upsert
modify_resolutionmfaAn 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 for more.
hide_inputslist(atom)[]A list of inputs to hide from the mutation.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.

Introspection

Target: AshGraphql.Resource.Mutation

graphql.mutations.update

update name, action

A mutation to update a record

Examples

update :update_post, :update

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the mutation.
actionatomThe action to use for the mutation.

Options

NameTypeDefaultDocs
identityatomThe identity to use to fetch the record to be updated. Use false if no identity is required.
read_actionatomThe read action to use to fetch the record to be updated. Defaults to the primary read action.
hide_inputslist(atom)A list of inputs to hide from the mutation.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.

Introspection

Target: AshGraphql.Resource.Mutation

graphql.mutations.destroy

destroy name, action

A mutation to destroy a record

Examples

destroy :destroy_post, :destroy

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the mutation.
actionatomThe action to use for the mutation.

Options

NameTypeDefaultDocs
read_actionatomThe read action to use to fetch the record to be destroyed. Defaults to the primary read action.
identityatomThe identity to use to fetch the record to be destroyed. Use false if no identity is required.
hide_inputslist(atom)A list of inputs to hide from the mutation.
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.

Introspection

Target: AshGraphql.Resource.Mutation

graphql.mutations.action

action name, action

Runs a generic action

Examples

action :check_status, :check_status

Arguments

NameTypeDefaultDocs
nameatom:getThe name to use for the query.
actionatomThe action to use for the query.

Options

NameTypeDefaultDocs
descriptionString.tThe description that gets shown in the Graphql schema. If not provided, the action description will be used.
hide_inputslist(atom)[]Inputs to hide in the mutation/query
relay_id_translationskeyword[]A keyword list indicating arguments or attributes that have to be translated from global Relay IDs to internal IDs. See the Relay guide for more.

Introspection

Target: AshGraphql.Resource.Action

graphql.managed_relationships

Generates input objects for manage_relationship arguments on resource actions.

Nested DSLs

Examples

managed_relationships do
  manage_relationship :create_post, :comments
end

Options

NameTypeDefaultDocs
auto?booleantrueAutomatically derive types for all arguments that have a manage_relationship call change.

graphql.managed_relationships.managed_relationship

managed_relationship action, argument

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.

For example, given an action like:

actions do
create :create do
argument :comments, {:array, :map}

change manage_relationship(:comments, type: :direct_control) # <- we look for this change with a matching argument name
end
end

You could add the following managed_relationship

graphql do
...

managed_relationships do
managed_relationship :create, :comments
end
end

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:

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

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.

For non_null use {:non_null, type}, and for a list, use {:array, type}, for example:

{:non_null, {:array, {:non_null, :string}}} for a non null list of non null strings.

To remove a key from the input object, simply pass nil as the type.

Arguments

NameTypeDefaultDocs
actionatomThe action that accepts the argument
argumentatomThe argument for which an input object should be derived.

Options

NameTypeDefaultDocs
lookup_with_primary_key?booleanIf 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_identitieslist(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_nameatomThe name of the input object that will be derived. Defaults to <action_type>_<resource>_<argument_name>_input
typesanyA keyword list of field names to their graphql type identifiers.
ignore?booleanfalseUse this to ignore a given managed relationship, preventing auto? true from deriving a type for it.

Introspection

Target: AshGraphql.Resource.ManagedRelationship