VBT.Absinthe.Schema (vbt v0.1.0) View Source

Helper for building GraphQL schemas.

Use this module in place of use Absinthe.Schema in your schema modules. When used, the following extensions are brought to the client module:

  1. use Absinthe.Schema
  2. import_types VBT.Graphql.Types
  3. Installs the VBT.Absinthe.Schema.NormalizeErrors middleware to each field with a declared resolver.

This module sets up a middleware by default. You can add your own middlewares as follows:

defmodule MySchema do
  use VBT.Absinthe.Schema

  def middleware(middlewares, field, object) do
    middleware = [MyMiddleware1, MyMiddleware2 | middlewares]
    super(middlewares, field, object)
  end

  # ...
end

Link to this section Summary

Functions

Resolves the GraphQL type of a VBT business error, or returns nil if the provided argument is not a known VBT business error.

Link to this section Functions

Specs

error_type(any()) :: :business_error | nil

Resolves the GraphQL type of a VBT business error, or returns nil if the provided argument is not a known VBT business error.

This function can be useful when resolving union types. For example:

union :login_result do
  types [:login_, :business_error]
  resolve_type fn result, _ -> error_type(result) || :login end
end