absinthe_relay_oxo v1.2.1 Absinthe.Relay.Connection.Notation

Macros used to define Connection-related schema entities

See Absinthe.Relay.Connection for more information.

Summary

Macros

Define a connection type for a given node type

Customize the edge type

Macros

connection(attrs)
connection(attrs, list)

Define a connection type for a given node type.

Examples

A basic connection for a node type, :pet. This well generate simple :pet_connection and :pet_edge types for you:

connection node_type: :pet

You can provide a custom name for the connection type (just don’t include the word “connection”). You must still provide the :node_type. You can create as many different connections to a node type as you want.

This example will create a connection type, :favorite_pets_connection, and an edge type, :favorite_pets_edge:

connection :favorite_pets, node_type: :pet

You can customize the connection object just like any other object:

connection :favorite_pets, node_type: :pet do
  field :total_age, :float do
    resolve fn
      _, %{source: conn} ->
        sum = conn.edges
        |> Enum.map(fn edge -> edge.node.age)
        |> Enum.sum
        {:ok, sum}
    end
  end
  edge do
    # ...
  end
end

Just remember that if you use the block form of connection, you must call the edge macro within the block to make sure the edge type is generated. See the edge macro below for more information.

connection(identifier, attrs, list)
edge(list)
edge(attrs, list)

Customize the edge type.

Examples

connection node_type: :pet do
  # ...
  edge do
    field :node_name_backwards, :string do
      resolve fn
        _, %{source: edge} ->
          {:ok, edge.node.name |> String.reverse}
      end
    end
  end
end