Rivet.Graphql (rivet v2.5.2)
View SourceHelper 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
iex> current_hostname(%{context: %{hostname: "narf"}})
iex> current_hostname(:nope)
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_result({:error, :args}, :narf)
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}}
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"}}
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})
iex> optional_arg(%{}, :narf) [] iex> optional_arg(%{narf: :something}, :narf) [narf: :something]
iex> parse_atom(%{value: "narf"})
iex> parse_atom(%{value: 10}) :error iex> parse_atom(:narf) :error