GraphQL.Response (GraphQL Client v0.2.1) View Source

Functions to handle GraphQL responses

Link to this section Summary

Types

t()

A struct that contains the GraphQL response data.

Functions

Creates a new failure response with the given errors

Create a new partial success response with the given data and errors

Creates a succes response with the given data

Link to this section Types

Specs

t() :: %GraphQL.Response{
  data: any(),
  errors: any(),
  success?: true | false | :partial
}

A struct that contains the GraphQL response data.

Link to this section Functions

Specs

failure(map()) :: t()

Creates a new failure response with the given errors

Examples

iex> failure([%{message: "some error", locations: [%{line: 2, column: 5}]}])
%GraphQL.Response{success?: false, errors: [%{message: "some error", locations: [%{line: 2, column: 5}]}]}
Link to this function

partial_success(data, errors)

View Source

Specs

partial_success(map(), list()) :: t()

Create a new partial success response with the given data and errors

Examples

iex> data = %{field: "value"}
%{field: "value"}
iex> errors = [%{message: "some error", locations: [%{line: 2, column: 5}]}]
[%{message: "some error", locations: [%{line: 2, column: 5}]}]
iex> partial_success(data, errors)
%GraphQL.Response{success?: :partial, data: %{field: "value"}, errors: [%{message: "some error", locations: [%{line: 2, column: 5}]}]}

Specs

success(map()) :: t()

Creates a succes response with the given data

Examples

iex> success(%{field: "value"})
%GraphQL.Response{success?: true, data: %{field: "value"}}