ProcaWeb.Helper (proca v3.4.1)

Helper functions for formatting errors from resolvers

Link to this section Summary

Functions

Must be able to flatten an error structure like: %{fields: [%{value: [%{message: "can't be blank"}]}]}

GraphQL expect a flat list of %{message: "some text"}. Traverse changeset and flat error messages to such list.

Link to this section Functions

Link to this function

can_manage?(campaign, user, callback)

Link to this function

cant_msg(perms)

Link to this function

flatten_errors(errors, path \\ [])

Must be able to flatten an error structure like: %{fields: [%{value: [%{message: "can't be blank"}]}]}

  1. a list -> run recursively for each element, concatenate the result
  2. map with keys mapped to errors -> get each key and pass it futher
Link to this function

format_errors(changeset, path \\ [])

GraphQL expect a flat list of %{message: "some text"}. Traverse changeset and flat error messages to such list.

The code will just show last field key for a nested record, so parent record name will not end up in messages. Maybe we should join all field names by a dot and return suchj field, for instance: contact.email instead of email

Link to this function

format_result(arg)

Link to this function

fromat_result(arg)

Link to this function

has_error?(errors, field, msg)

Link to this function

msg_ext(msg, code, ext \\ %{})

Link to this function

rename_key(map, k1, k2)

Link to this function

replace_placeholders(msg, opts)

Link to this function

request_basic_auth(conn, msg)

Link to this function

validate(changeset)

Specs

validate(Ecto.Changeset.t()) :: {:ok | :error, Ecto.Changeset.t()}