Skip to content

Support Absinthe nested changeset validation errors#8

Open
thetamind wants to merge 10 commits intoblunt-elixir:reorgfrom
thetamind:absinthe-nested-errors
Open

Support Absinthe nested changeset validation errors#8
thetamind wants to merge 10 commits intoblunt-elixir:reorgfrom
thetamind:absinthe-nested-errors

Conversation

@thetamind
Copy link

@thetamind thetamind commented Oct 5, 2022

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"]}

@thetamind thetamind force-pushed the absinthe-nested-errors branch 2 times, most recently from a52e4df to f516164 Compare October 6, 2022 16:16
@thetamind thetamind force-pushed the absinthe-nested-errors branch from f516164 to 20885e4 Compare October 6, 2022 16:29
@trbngr
Copy link
Contributor

trbngr commented Oct 6, 2022

Thanks so much, @thetamind!

I'll check this out as soon as I get a chance.

Comment on lines 30 to 36
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants