Rivet.Graphql (rivet v2.7.1)
View SourceHelper functions for Absinthe resolvers.
Summary
Functions
Easy parser to connect Absinthe scalers with EctoEnum.
Functions
iex> current_hostname(%{context: %{hostname: "narf"}})
{:ok, "narf"}
iex> current_hostname(:nope)
{:error, "No Host on session"}
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> error_string({:error, "narf"})
"narf"
iex> err = RivetTestLib.Yoink.build(%{name: :nope})
iex> error_string(err)
"name is invalid"
iex> error_string({:error, err})
"name is invalid"
iex> graphql_log("narf")
:ok
iex> graphql_log(nil)
:ok
iex> graphql_result({:ok, :narf})
{:ok, :narf}
iex> graphql_result({:error, :args}, :narf)
{:error, "Invalid Arguments"}
iex> graphql_status_result({:error, "Unauthenticated"})
{: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}}
iex> graphql_status_result({:error, "narf", a: :b})
{:ok, %{success: false, reason: "narf"}}
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"})
{:ok, []}
iex> ok_as_list({:error, :not_found})
{:ok, []}
iex> ok_as_list({:ok, :narf})
{:ok, [:narf]}
iex> ok_as_list({:error, :narf})
{:error, :narf}
iex> optional_arg(%{}, :narf)
[]
iex> optional_arg(%{narf: :something}, :narf)
[narf: :something]
iex> parse_atom(%{value: "narf"})
{:ok, :narf}
iex> parse_atom(%{value: 10})
:error
iex> parse_atom(:narf)
:error
Easy parser to connect Absinthe scalers with EctoEnum.