Support Absinthe nested changeset validation errors#8
Support Absinthe nested changeset validation errors#8thetamind wants to merge 10 commits intoblunt-elixir:reorgfrom
Conversation
a52e4df to
f516164
Compare
f516164 to
20885e4
Compare
|
Thanks so much, @thetamind! I'll check this out as soon as I get a chance. |
| Enum.map(messages, fn message -> [message: "#{key} #{message}"] end) ++ acc | ||
| Enum.map(messages, fn | ||
| {field, messages} -> | ||
| [message: "#{key}.#{field} #{messages |> Enum.join(", ")}"] | ||
|
|
||
| message -> | ||
| [message: "#{key} #{message}"] | ||
| end) ++ acc |
There was a problem hiding this comment.
I had a bit of trouble converting this to recursively call format to support more than one level deep. May need to switch to Enum.flat_map or Enum.reduce or mess with ++ acc.
| } | ||
| ) | ||
|
|
||
| assert message =~ "address.line1 should start with a number, should be at least 3 character(s)" |
There was a problem hiding this comment.
| assert message =~ "address.line1 should start with a number, should be at least 3 character(s)" | |
| assert message =~ "input.address.line1 should start with a number, should be at least 3 character(s)" |
Should the message include a fully qualified key path including the top level input object?
Or should the message only mention the last field (line1) and the path key include a full path?
Blunt.Absinthe.Field.dispatch_and_resolve maybe unwraps :input from args and AbsintheErrors doesn't have that knowledge if it should prefix the error key path with :input.
Just to compare, the error from Absinthe for a nil value resulting in a type mismatch is this:
Argument "input" has invalid value $input.
In field "address": Expected type "AddressInput", found {line1: null}.
In field "line1": Expected type "String!", found null.
Blunt.Absinthe.AbsintheErrors.format/2: Add support for formatting error tuple from nested changeset validation errors.i.e.
{:field, ["should be X", "can't be Y"]}