VBT.Graphql.Case (vbt v0.1.0) View Source

ExUnit case template for writing tests which issue GraphQL requests.

Example:

defmodule SomeTest do
  use VBT.Graphql.Case,
    endpoint: MyEndpoint,
    api_path: "/api/graphql",
    repo: MyRepo,
    async: true

  describe "current_user" do
    test "returns current user's login" do
      {:ok, token} = call(auth_query, variables: %{login: login, password: password})
      assert {:ok, data} = call(current_user_query, auth: token)
      assert data.login == "expected login"
    end

    test "returns an error when not authenticated" do
      assert {:ok, response} = call(current_user_query, auth: token)
      assert "unauthenticated" in errors(response)
    end
end

Link to this section Summary

Functions

Makes a GraphQL query call.

Makes a GraphQL call, returning data on success, raising an assertion error otherwise.

Returns error messages from the GraphQL response errors.

Returns error messages for the given field from the GraphQL response errors.

Link to this section Types

Specs

call_opts() :: [
  variables: variables(),
  auth: String.t() | nil,
  headers: [header()],
  endpoint: module(),
  api_path: String.t()
]

Specs

data() :: %{required(atom()) => data_value()}

Specs

data_value() :: number() | String.t() | data() | [data_value()]

Specs

error() :: %{
  :message => String.t(),
  optional(:path) => [String.t()],
  optional(:locations) => [
    %{column: non_neg_integer(), line: non_neg_integer()}
  ],
  optional(:extensions) => [%{field: String.t()}]
}

Specs

header() :: {String.t(), String.t()}

Specs

response() :: %{data: data(), errors: [error()]}

Specs

variables() :: %{required(atom()) => any()} | Keyword.t()

Link to this section Functions

Link to this function

call(query_string, opts \\ [])

View Source

Specs

call(String.t(), call_opts()) :: {:ok, data()} | {:error, response()}

Makes a GraphQL query call.

Link to this function

call!(query_string, opts \\ [])

View Source

Specs

call!(String.t(), call_opts()) :: data()

Makes a GraphQL call, returning data on success, raising an assertion error otherwise.

Specs

errors(response()) :: [String.t()]

Returns error messages from the GraphQL response errors.

Link to this function

field_errors(response, field)

View Source

Specs

field_errors(response(), String.t()) :: [String.t()]

Returns error messages for the given field from the GraphQL response errors.