View Source DSL: AshGraphql.Domain

The entrypoint for adding GraphQL behavior to an Ash domain

graphql

Domain level configuration for GraphQL

Nested DSLs

Examples

graphql do
  authorize? false # To skip authorization for this domain
end

Options

NameTypeDefaultDocs
authorize?booleantrueWhether or not to perform authorization for this domain
traceratomA tracer to use to trace execution in the graphql. Will use config :ash, :tracer if it is set.
root_level_errors?booleanfalseBy 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_handlermfa{AshGraphql.DefaultErrorHandler, :handle_error, []}Set an MFA to intercept/handle any errors that are generated.
show_raised_errors?booleanfalseFor 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.

graphql.queries

Queries to expose for the resource.

Nested DSLs

Examples

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

graphql.queries.get

get resource, name, action

A query to fetch a record by primary key

Examples

get :get_post, :read

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

A query to fetch a record

Examples

read_one :current_user, :current_user

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

A query to fetch a list of records

Examples

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

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

Runs a generic action

Examples

action :check_status, :check_status

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 Post, :create_post, :create
  update Post, :update_post, :update
  destroy Post, :destroy_post, :destroy
end

graphql.mutations.create

create resource, name, action

A mutation to create a record

Examples

create :create_post, :create

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

A mutation to update a record

Examples

update :update_post, :update

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

A mutation to destroy a record

Examples

destroy :destroy_post, :destroy

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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 resource, name, action

Runs a generic action

Examples

action :check_status, :check_status

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
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.subscriptions

Subscriptions to expose for the resource.

Nested DSLs

Examples

subscription do
  subscribe Post, :post_created do
    action_types(:create)
  end
end

graphql.subscriptions.subscribe

subscribe resource, name

A subscription to listen for changes on the resource

Examples

subscribe :post_created do
  action_types(:create)
end

Arguments

NameTypeDefaultDocs
resourcemoduleThe resource that the action is defined on
nameatomThe name to use for the subscription.

Options

NameTypeDefaultDocs
actor(any -> any) | moduleThe actor to use for authorization.
actionslist(atom) | atomThe create/update/destroy actions the subsciption should listen to.
action_typeslist(atom) | atomThe type of actions the subsciption should listen to.
read_actionatomThe read action to use for reading data
hide_inputslist(atom)[]A list of inputs to hide from the subscription, usable if the read action has arguments.

Introspection

Target: AshGraphql.Resource.Subscription