Flop.Relay.connection_from_result

You're seeing just the function connection_from_result, go back to Flop.Relay module for more information.
Link to this function

connection_from_result(arg, opts \\ [])

View Source (since 0.8.0)

Specs

connection_from_result({[any()], Flop.Meta.t()}, [Flop.option()]) ::
  connection()

Takes the query results returned by Flop.run/3, Flop.validate_and_run/3 or Flop.validate_and_run!/3 and turns them into the Relay connection format.

Example

iex> flop = %Flop{order_by: [:name]}
iex> meta = %Flop.Meta{flop: flop, start_cursor: "a", end_cursor: "b"}
iex> result = {[%Flop.Fruit{name: "Apple", family: "Rosaceae"}], meta}
iex> Flop.Relay.connection_from_result(result)
%{
  edges: [
    %{
      cursor: "g3QAAAABZAAEbmFtZW0AAAAFQXBwbGU=",
      node: %Flop.Fruit{family: "Rosaceae", id: nil, name: "Apple"}
    }
  ],
  page_info: %{
    end_cursor: "b",
    has_next_page: false,
    has_previous_page: false,
    start_cursor: "a"
  }
}

See Flop.Relay.edges_from_result/2 for an example of adding additional fields to the edge.

Options

  • :get_cursor_value_func: 2-arity function that takes an item from the query result and the order_by fields and returns the unencoded cursor value.