Skip to content

Executing a query should error when aliasing a field with the same name as a field of incompatible type #1153

Open
@caitlinhalla

Description

@caitlinhalla

Environment

  • Elixir version: 1.12.1-otp-24
  • Absinthe version: pinned at sha: "738f97b96d77f793a99098aa9008683d9b6ab991" in our service, however, also validated that this occurs in Absinthe 1.7.0

Expected behavior

I would expect the execution of the following query containing a field aliased with the same name as a field of incompatible type to error:
query { thing(id: "foo") { otherThing: name otherThing { name } } }

Instead, the aliased field is simply omitted from the response as follows:
{:ok, %{data: %{"thing" => %{"otherThing" => "Foo"}}}}

Relevant thread in #absinthe-graphql: https://elixir-lang.slack.com/archives/C0PR49P4P/p1644946451423759 that points to the spec for this case.

Relevant Schema/Middleware Code

I traced this issue to Absinthe.Resolution.Projector.project/5, which is where field selections are collected by using either the alias or field name as the key in the accumulator here: https://github.com/absinthe-graphql/absinthe/blob/master/lib/absinthe/resolution/projector.ex#L52.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions