Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list typings for payload and options #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions lib/absinthe_error_payload/payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ defmodule AbsintheErrorPayload.Payload do

```elixir
object :user_payload do
field :successful, non_null(:boolean), description: "Indicates if the mutation completed successfully or not. "
field :messages, list_of(:validation_message), description: "A list of failed validations. May be blank or null if mutation succeeded."
field :result, :user, description: "The object created/updated/deleted by the mutation"
field :successful, non_null(:boolean), description: "..."
field :messages, non_null(list_of(non_null(:validation_message))), description: "..."
field :result, :user, description: "..."
end
```

Expand All @@ -122,7 +122,7 @@ defmodule AbsintheErrorPayload.Payload do
quote location: :keep do
object unquote(payload_name) do
field(:successful, non_null(:boolean), description: "Indicates if the mutation completed successfully or not. ")
field(:messages, list_of(:validation_message), description: "A list of failed validations. May be blank or null if mutation succeeded.")
field(:messages, non_null(list_of(non_null(:validation_message))), description: "A list of failed validations. Empty if mutation succeeded.")
field(:result, unquote(result_object_name), description: "The object created/updated/deleted by the mutation. May be null if mutation failed.")
end
end
Expand Down Expand Up @@ -203,19 +203,6 @@ defmodule AbsintheErrorPayload.Payload do
%{resolution | value: result, errors: []}
end

@doc """
Convert resolution errors to a mutation payload

The build payload middleware will accept lists of `AbsintheErrorPayload.ValidationMessage` or string errors.

Valid formats are:
```
[%ValidationMessage{},%ValidationMessage{}]
"This is an error"
["This is an error", "This is another error"]
```
"""

def build_payload(%{errors: errors} = resolution, _config) do
result = convert_to_payload({:error, errors})
%{resolution | value: result, errors: []}
Expand Down
4 changes: 2 additions & 2 deletions lib/absinthe_error_payload/validation_message_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule AbsintheErrorPayload.ValidationMessageTypes do
field :message, :string, description: "..."
field :code, non_null(:string), description: "..."
field :template, :string, description: "..."
field :options, list_of(:validation_option), description: "..."
field :options, non_null(list_of(non_null(:validation_option))), description: "..."
end
```

Expand Down Expand Up @@ -103,6 +103,6 @@ defmodule AbsintheErrorPayload.ValidationMessageTypes do
field(:template, :string, description: @descs.template)

@desc "A list of substitutions to be applied to a validation message template"
field(:options, list_of(:validation_option), description: @descs.option_list)
field(:options, non_null(list_of(non_null(:validation_option))), description: @descs.option_list)
end
end