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

Confusing warning when fields duplicated in a schema #1049

Closed
joeapearson opened this issue Mar 11, 2021 · 0 comments · Fixed by #1135
Closed

Confusing warning when fields duplicated in a schema #1049

joeapearson opened this issue Mar 11, 2021 · 0 comments · Fixed by #1135
Assignees

Comments

@joeapearson
Copy link

joeapearson commented Mar 11, 2021

This isn't really a bug per-se but a usability issue, and was entirely caused by my own mistake:

I suddenly found after a series of changes to my code that I was getting warnings like this:

warning: this clause cannot match because a previous clause at line 1 always matches
  lib/myapp_web/schema/my_types.ex:1

It turns out I had mistakenly added duplicate fields to one of my schema. The only way I could track it down was by progressively commenting out bits of my schema until I isolated the warning.

Environment

  • Elixir version (elixir -v):
    Erlang/OTP 23 [erts-11.1.8] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

      Elixir 1.11.3 (compiled with Erlang/OTP 23)
    
  • Absinthe version (mix deps | grep absinthe):
    * absinthe 1.6.0 (Hex package) (mix)
    locked at 1.6.0 (absinthe) 99915841
    * absinthe_plug 1.5.4 (Hex package) (mix)
    locked at 1.5.4 (absinthe_plug) 80360cd8

  • Client Framework and version (Relay, Apollo, etc): N/A

Expected behavior

A warning or error of some sort that informed me that I had made a silly mistake!

Actual behavior

I receive several warnings like this:

warning: this clause cannot match because a previous clause at line 1 always matches
  lib/myapp_web/schema/my_types.ex:1

The line number is always 1.

Relevant Schema/Middleware Code

Here's a minimal example that reproduces the behaviour:

object :my_object do
    field :my_field, :string
    field :my_field, :number
  end

Of course this is a contrived example because you can clearly see the mistake when there are but two properties. If your object schema is larger (like mine is) then it's harder to see. It'd be great if some sort of warning and or error was triggered (with the appropriate line number, instead of just line 1).

@benwilson512 benwilson512 self-assigned this Mar 11, 2021
maartenvanvliet added a commit to maartenvanvliet/absinthe that referenced this issue Dec 28, 2021
Fixes absinthe-graphql#1133
Also fixes absinthe-graphql#1049
as the schema's won't compile anymore, so the warning no longer happens
maartenvanvliet added a commit to maartenvanvliet/absinthe that referenced this issue Dec 28, 2021
Fixes absinthe-graphql#1133
Also fixes absinthe-graphql#1049
as the schema's won't compile anymore, so the warning no longer happens
benwilson512 pushed a commit that referenced this issue Jan 4, 2022
* Add unique field names validation

Fixes #1133
Also fixes #1049
as the schema's won't compile anymore, so the warning no longer happens

* Optimize duplicate?/3 check

* Add changelog entry
maartenvanvliet added a commit to maartenvanvliet/absinthe that referenced this issue Oct 3, 2022
See absinthe-graphql#1049
The issue was not resolved for field identifiers. This issue should resolve that.
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.

2 participants