View Source AshGraphql.Type behaviour (ash_graphql v1.3.4)

Callbacks used to enrich types with GraphQL-specific metadata.

Summary

Callbacks

Used for maps/enums/unions that would define a type automatically, to disable them.

Used for Ash.Type.Enum to provide a description for individual values. For example

Sets the name of the graphql input type for a given Ash type. For example: :weekday.

Used for Ash.Type.Enum to rename individual values. For example

Sets the name of the graphql type for a given Ash type. For example: :weekday.

Used for map/embedded types embedded in unions, to avoid nesting them in a key by their name.

Callbacks

Link to this callback

graphql_define_type?(constraints)

View Source (optional)
@callback graphql_define_type?(Ash.Type.constraints()) :: false

Used for maps/enums/unions that would define a type automatically, to disable them.

Link to this callback

graphql_describe_enum_value(atom)

View Source (optional)
@callback graphql_describe_enum_value(atom()) :: String.t() | nil

Used for Ash.Type.Enum to provide a description for individual values. For example:

defmodule MyEnum do
use Ash.Type.Enum, values: [:foo, :bar, :baz]

  def graphql_describe_enum_value(:baz), do: "A baz"
  def graphql_describe_enum_value(_), do: nil
end
Link to this callback

graphql_input_type(constraints)

View Source (optional)
@callback graphql_input_type(Ash.Type.constraints()) :: atom()

Sets the name of the graphql input type for a given Ash type. For example: :weekday.

This will do different things depending on the type you're adding it to.

Regular Types

This expresses that you will define a custom type for representing this input in your graphql

NewTypes

If it is a subtype of a union, or map/keyword with fields the type will be created with that name. So you can use this to decide what it will be named. Otherwise, it behaves as stated above for regular types.

Link to this callback

graphql_rename_value(constraints)

View Source (optional)
@callback graphql_rename_value(Ash.Type.constraints()) :: String.t() | atom()

Used for Ash.Type.Enum to rename individual values. For example:

defmodule MyEnum do
  use Ash.Type.Enum, values: [:foo, :bar, :baz]

  def graphql_rename_value(:baz), do: :buz
  def graphql_rename_value(other), do: other
end
Link to this callback

graphql_type(constraints)

View Source (optional)
@callback graphql_type(Ash.Type.constraints()) :: atom()

Sets the name of the graphql type for a given Ash type. For example: :weekday.

This will do different things depending on the type you're adding it to.

Regular Types

This expresses that you will define a custom type for representing this in your graphql

NewTypes

If it is a subtype of a union, or map/keyword with fields the type will be created with that name. So you can use this to decide what it will be named. Otherwise, it behaves as stated above for regular types.

Link to this callback

graphql_unnested_unions(constraints)

View Source (optional)
@callback graphql_unnested_unions(Ash.Type.constraints()) :: [atom()]

Used for map/embedded types embedded in unions, to avoid nesting them in a key by their name.

See the unions guide for more.