Rivet.Graphql (rivet v2.5.2)

View Source

Helper functions for Absinthe resolvers.

Summary

Functions

iex> current_hostname(%{context: %{hostname: "narf"}})

iex> error_string([{:error, :authz}]) "Unauthorized" iex> error_string("narf") "narf" iex> error_string(:authn) "Unauthenticated" iex> error_string(:authn) "Unauthenticated" iex> error_string(:narf) "narf" iex> error_string({:nobody, :expects}) "unexpected error, see logs"

iex> graphql_log("narf") :ok iex> graphql_log(nil) :ok

iex> graphql_result({:ok, :narf})

iex> graphql_status_result({:error, "Unauthenticated"})

Handle multi-results with total/matching tallys

iex> ok_as_list({:error, "Nothing found"})

iex> optional_arg(%{}, :narf) [] iex> optional_arg(%{narf: :something}, :narf) [narf: :something]

iex> parse_atom(%{value: "narf"})

Functions

current_hostname(arg1)

iex> current_hostname(%{context: %{hostname: "narf"}})

iex> current_hostname(:nope)

error_string(errs)

iex> error_string([{:error, :authz}]) "Unauthorized" iex> error_string("narf") "narf" iex> error_string(:authn) "Unauthenticated" iex> error_string(:authn) "Unauthenticated" iex> error_string(:narf) "narf" iex> error_string({:nobody, :expects}) "unexpected error, see logs"

graphql_error(method, err, logargs \\ [])

graphql_log(method, args \\ [])

iex> graphql_log("narf") :ok iex> graphql_log(nil) :ok

graphql_result(x, method \\ nil)

iex> graphql_result({:ok, :narf})

iex> graphql_result({:error, :args}, :narf)

graphql_status_result(state, key \\ nil)

iex> graphql_status_result({:error, "Unauthenticated"})

iex> graphql_status_result({:ok, %{success: true, result: :narf}}) {:ok, %{success: true, result: :narf}} iex> graphql_status_result({:ok, %{success: true, result: :narf}}, :narf) {:ok, %{success: true, narf: :narf}} iex> graphql_status_result({:ok, %{success: false, reason: :narf}}) {:ok, %{success: false, reason: :narf}} iex> graphql_status_result({:ok, 100}) {:ok, %{success: true, result: 100}} iex> graphql_status_result({:ok, 100}, :narf) {:ok, %{narf: 100, success: true}} iex> graphql_status_result({:error, :authz}) {:ok, %{reason: "Unauthorized", success: false}}

graphql_status_results(x, key \\ :results)

Handle multi-results with total/matching tallys

iex> graphql_status_results({:ok, %{success: true, results: :narf}}) {:ok, %{success: true, results: :narf}} iex> graphql_status_results({:ok, %{success: true, results: :narf}, :narf}, :key) {:ok, %{success: true, results: :narf, key: :narf}} iex> graphql_status_results({:ok, %{success: true, results: :narf}}, :results) {:ok, %{success: true, results: :narf}} iex> graphql_status_results({:ok, %{success: true, results: :narf}}, :narf) {:ok, %{success: true, narf: :narf}} iex> graphql_status_results({:ok, [:narf]}, :narf) {:ok, %{success: true, narf: [:narf], total: 1, matching: 1}} iex> graphql_status_results({:ok, :narf}, :narf) {:ok, %{success: true, narf: [:narf], total: 1, matching: 1}} iex> graphql_status_results({:error, :authn}) {:ok, %{success: false, reason: "Unauthenticated"}}

ok_as_list(pass)

iex> ok_as_list({:error, "Nothing found"})

iex> ok_as_list({:error, :not_found})

iex> ok_as_list({:ok, :narf})

iex> ok_as_list({:error, :narf})

optional_arg(map, arg)

iex> optional_arg(%{}, :narf) [] iex> optional_arg(%{narf: :something}, :narf) [narf: :something]

parse_atom(arg1)

iex> parse_atom(%{value: "narf"})

iex> parse_atom(%{value: 10}) :error iex> parse_atom(:narf) :error

parse_enum(arg1, enum)