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

ValidationMessage options not working with a keyword list #7

Closed
benvp opened this issue Jun 25, 2019 · 1 comment
Closed

ValidationMessage options not working with a keyword list #7

benvp opened this issue Jun 25, 2019 · 1 comment

Comments

@benvp
Copy link

benvp commented Jun 25, 2019

I have an AbsintheErrorPayload struct which has been generated by the build_payload/2 middleware. Anyway, when having keyword list as the options the resolution breaks with the following error:

Request: POST /api/graphiql
** (exit) an exception was raised:
    ** (BadMapError) expected a map, got: {:constraint, :unique}
        (elixir) lib/map.ex:437: Map.get({:constraint, :unique}, :key, nil)
        (absinthe) lib/absinthe/middleware/map_get.ex:9: Absinthe.Middleware.MapGet.call/2
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:209: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:168: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/4
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:153: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:72: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:98: Absinthe.Phase.Document.Execution.Resolution.walk_results/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:87: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:257: Absinthe.Phase.Document.Execution.Resolution.build_result/4
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:153: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:72: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:98: Absinthe.Phase.Document.Execution.Resolution.walk_results/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:87: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:257: Absinthe.Phase.Document.Execution.Resolution.build_result/4
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:153: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:72: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:257: Absinthe.Phase.Document.Execution.Resolution.build_result/4
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:153: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:72: Absinthe.Phase.Document.Execution.Resolution.walk_result/5
        (absinthe) lib/absinthe/phase/document/execution/resolution.ex:53: Absinthe.Phase.Document.Execution.Resolution.perform_resolution/3

Here is the struct I used:

%AbsintheErrorPayload.Payload{
  messages: [],
  result: [
    %AbsintheErrorPayload.ValidationMessage{
      code: :unique,
      field: "credential.email",
      key: :email,
      message: "has already been taken",
      options: [constraint: :unique, constraint_name: "credentials_email_index"],
      template: "has already been taken"
    }
  ],
  successful: true
}

Edit: It only breaks if we query for the options in the GraphQL query.

@benvp benvp changed the title ValidationMessage options not working with atom values ValidationMessage options not working with a keyword list Jun 25, 2019
@pwightman
Copy link

I ran into this as well...is fixing this as easy as changing tidy_opts to convert to a map?

defp tidy_opts(opts) do
Keyword.drop(opts, [:validation, :max, :is, :min, :code])
end

e.g.

defp tidy_opts(opts) do
  opts
  |> Keyword.drop([:validation, :max, :is, :min, :code])
  |> Enum.into(%{})
end

If so, I'm happy to submit a PR 👍

chubarovNick pushed a commit to chubarovNick/absinthe_error_payload that referenced this issue Apr 1, 2020
* Fix options atoms list and options as map

* Fixes mirego#7 by refactoring options key-value list
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

No branches or pull requests

2 participants