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

Possible bug with the :name option of Absinthe.Schema.Notation.field/4 #1126

Open
srfsh opened this issue Nov 25, 2021 · 4 comments
Open

Possible bug with the :name option of Absinthe.Schema.Notation.field/4 #1126

srfsh opened this issue Nov 25, 2021 · 4 comments

Comments

@srfsh
Copy link

srfsh commented Nov 25, 2021

Environment

  • Elixir version (elixir -v): elixir 1.12.3 with erlang/otp 24
  • Absinthe version (mix deps | grep absinthe): absinthe 1.6.6
  • Client Framework and version (Relay, Apollo, etc): I am just using Absinthe.run!/3

Expected behavior

field/4 aliasing with :name should work in an input_object/3.

Actual behavior

field/4 aliasing with :name doesn't work in an input_object/3.

Relevant Schema/Middleware Code

Please inspect the following demo project and run mix test: https://github.com/srfsh/foo_bar
I think it only happens with fields that have more than one underscore. To demonstrate that, I added shop_id and awesome_owner_id. You can remove show_id related code and try with only awesome_owner_id (don't forget to run tests with and without awesome_ prefix if you do so).

I'll put the result of the test here (please look at the messages):

With shop_id
$ mix test


  1) test Query book() (SchemaTest)
     test/schema_test.exs:8
     match (=) failed
     code:  assert %{data: %{"book" => data}} = run!("  query {\n    book(id: \"some uuid\") {\n      id\n      title\n      shop\n      awesomeOwner\n    }\n  }\n", Schema)
     left:  %{data: %{"book" => data}}
     right: %{errors: [%{locations: [%{column: 7, line: 6}], message: "Cannot query field \"awesomeOwner\" on type \"Book\". Did you mean \"awesomeOwner\"?"}]}
     stacktrace:
       test/schema_test.exs:9: (test)



  2) test Mutation createBook() (SchemaTest)
     test/schema_test.exs:26
     match (=) failed
     code:  assert %{data: %{"createBook" => data}} = run!("  mutation {\n    createBook(book: {\n      title: \"title of the book\"\n      shop: \"some other uuid\"\n      awesomeOwner: \"some uuid\"\n    }) {\n      id\n      title\n      shop\n      awesomeOwner\n    }\n  }\n", Schema)
     left:  %{data: %{"createBook" => data}}
     right: %{
              errors: [%{locations: [%{column: 7, line: 10}], message: "Cannot query field \"awesomeOwner\" on type \"Book\". Did you mean \"awesomeOwner\"?"}, %{locations: [%{column: 16, line: 2}], message: "Argument \"book\" has invalid value {title: \"title of the book\", shop: \"some other uuid\", awesomeOwner: \"some uuid\"}.\nIn field \"awesomeOwner\": Expected type \"ID!\", found null.\nIn field \"awesomeOwner\":
Unknown field. Did you mean \"awesomeOwner\"?"}, %{locations: [%{column: 7, line: 3}], message: "Duplicate input field name."}, %{locations: [%{column: 7, line: 5}], message: "Duplicate input field name."}]
            }
     stacktrace:
       test/schema_test.exs:27: (test)

..

Finished in 0.1 seconds (0.00s async, 0.1s sync)
1 doctest, 3 tests, 2 failures

Randomized with seed 774466
Without shop_id
$ mix test


  1) test Query book() (SchemaTest)
     test/schema_test.exs:8
     match (=) failed
     code:  assert %{data: %{"book" => data}} = run!("  query {\n    book(id: \"some uuid\") {\n      id\n      title\n      awesomeOwner\n    }\n  }\n", Schema)
     left:  %{data: %{"book" => data}}
     right: %{errors: [%{locations: [%{column: 7, line: 5}], message: "Cannot query field \"awesomeOwner\" on type \"Book\". Did you mean \"awesomeOwner\"?"}]}
     stacktrace:
       test/schema_test.exs:9: (test)



  2) test Mutation createBook() (SchemaTest)
     test/schema_test.exs:24
     match (=) failed
     code:  assert %{data: %{"createBook" => data}} = run!("  mutation {\n    createBook(book: {\n      title: \"title of the book\"\n      awesomeOwner: \"some uuid\"\n    }) {\n      id\n      title\n      awesomeOwner\n    }\n  }\n", Schema)
     left:  %{data: %{"createBook" => data}}
     right: %{
              errors: [%{locations: [%{column: 7, line: 8}], message: "Cannot query field \"awesomeOwner\" on type \"Book\". Did you mean \"awesomeOwner\"?"}, %{locations: [%{column: 16, line: 2}], message: "Argument \"book\" has invalid value {title: \"title of the book\", awesomeOwner: \"some uuid\"}.\nIn field \"awesomeOwner\": Expected type \"ID!\", found null.\nIn field \"awesomeOwner\": Unknown field. Did you mean
\"awesomeOwner\"?"}, %{locations: [%{column: 7, line: 3}], message: "Duplicate input field name."}, %{locations: [%{column: 7, line: 4}], message: "Duplicate input field name."}]
            }
     stacktrace:
       test/schema_test.exs:25: (test)

..

Finished in 0.09 seconds (0.00s async, 0.09s sync)
1 doctest, 3 tests, 2 failures

Randomized with seed 711744

@jaromil
Copy link

jaromil commented Dec 9, 2021

Ping, can anyone have a look at this? it may be very easy to fix and we are available to provide more info and troubleshooting.

@maartenvanvliet
Copy link
Contributor

Can you try using snake case instead of camel case in the name? E.g.:
field :awesome_owner_id, non_null(:id), name: "awesome_owner"

@srfsh
Copy link
Author

srfsh commented Dec 9, 2021

Can you try using snake case instead of camel case in the name? E.g.: field :awesome_owner_id, non_null(:id), name: "awesome_owner"

It works. That's strange; I thought :name option was used for defining the ouput/display type (camelCase), not the one you pass to field/4 as the first parameter (snake_case). What is the intended usage of :name? The former or the latter?

@scrogson
Copy link

scrogson commented Jan 3, 2022

I just ran into this today. I have something where I'd like to define a field on an input object but control the name of the field so that :user_id_in can be defined in the schema as userId_in. But it doesn't seem to work in the way I think it should.

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

4 participants