View Source AshGraphql (ash_graphql v1.4.3)

AshGraphql is a GraphQL extension for the Ash framework.

For more information, see the getting started guide

Summary

Functions

Applies AshGraphql's error handling logic if the value is an {:error, error} tuple, otherwise returns the value

Use this to load any requested fields for a result when it is returned from a custom resolver or mutation.

The same as load_fields/4, but modifies the provided query to load the required fields.

Functions

Link to this function

handle_errors(result, resource, resolution, opts \\ [])

View Source
@spec handle_errors(
  result :: term(),
  resource :: Ash.Resource.t(),
  resolution :: Absinthe.Resolution.t(),
  opts :: Keyword.t()
) :: term()

Applies AshGraphql's error handling logic if the value is an {:error, error} tuple, otherwise returns the value

Useful for automatically handling errors in custom queries

Options

  • domain: The domain to use when loading the fields. Determined from the resource by default.
Link to this function

load_fields(data, resource, resolution, opts \\ [])

View Source
@spec load_fields(
  input,
  Ash.Resource.t(),
  Absinthe.Resolution.t(),
  opts :: Keyword.t()
) ::
  {:ok, input} | {:error, term()}
when input: Ash.Resource.record() | [Ash.Resource.record()] | Ash.Page.page()

Use this to load any requested fields for a result when it is returned from a custom resolver or mutation.

Determining required fields

If you have a custom query/mutation that returns the record at a "path" in the response, then specify the path. In the example below, path would be ["record"]. This is how we know what fields to load.

query something() {
  result {
    record { # <- this is the instance
      id
      name
    }
  }
}

Options

  • path: The path to the record(s) in the response
  • domain: The domain to use when loading the fields. Determined from the resource by default.
  • authorize?: Whether to authorize access to fields. Defaults to the domain's setting (which defaults to true).
  • actor: The actor to use when authorizing access to fields. Defaults to the actor in the resolution context.
  • tenant: The tenant to use when authorizing access to fields. Defaults to the tenant in the resolution context.
Link to this function

load_fields_on_query(query, resolution, opts \\ [])

View Source
@spec load_fields_on_query(
  query :: Ash.Query.t() | Ash.Resource.t(),
  Absinthe.Resolution.t(),
  Keyword.t()
) :: Ash.Query.t()

The same as load_fields/4, but modifies the provided query to load the required fields.

This allows doing the loading in a single query rather than two separate queries.