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

[Enum] Default value not interpreted properly in case of keyword list #941

Closed
jonatanklosko opened this issue Jun 8, 2020 · 0 comments · Fixed by #944
Closed

[Enum] Default value not interpreted properly in case of keyword list #941

jonatanklosko opened this issue Jun 8, 2020 · 0 comments · Fixed by #944

Comments

@jonatanklosko
Copy link
Contributor

jonatanklosko commented Jun 8, 2020

Given the following enum definition

enum :project_order_by do
  value :inserted_at_asc, as: [asc: :inserted_at]
  value :inserted_at_desc, as: [desc: :inserted_at]
end

and the following field with a default enum argument

field :projects, list_of(:project) do
  arg :order_by, non_null(:project_order_by), default_value: [asc: :inserted_at]
  resolve &Resolvers.Projects.list_projects/3
end

I get the following error

The default_value for an enum must be present in the enum values.

Could not use default value of `[asc: :inserted_at]` for :project_order_by.

Valid values are:

 * [desc: :inserted_at]
 * [asc: :inserted_at]

Reason

List.wrap(default_value)
|> Enum.all?(fn default -> default in values end)

The above call to List.wrap does nothing in case of [asc: :inserted_at], but then it uses Enum.all? and ends up checking if {:asc, :inserted_at} belongs to values instead of [asc: :inserted_at].

What is the reasoning behind using List.wrap?
Edit: it was introduced in #762 to handle default value for list_of(enum).

Environment

  • Elixir version (elixir -v): Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • Absinthe version (mix deps | grep absinthe): 1.5.1
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 a pull request may close this issue.

1 participant