Duplicate input types for GraphQL

Given a resource like this
defmodule Package
attributes do
attribute :options, {:array, Option}, allow_nil?: false
end

graphql do
type :package
mutations do
create :create
update :add_option, :add_option, identity: :key
end
end

actions do
defaults [:create]

update :add_option do
accept []
argument :option, Option, allow_nil?: false
...
end
end
defmodule Package
attributes do
attribute :options, {:array, Option}, allow_nil?: false
end

graphql do
type :package
mutations do
create :create
update :add_option, :add_option, identity: :key
end
end

actions do
defaults [:create]

update :add_option do
accept []
argument :option, Option, allow_nil?: false
...
end
end
I get multiple errors about duplicate related to Option (UnionType) and its children (OptionString, OptionBoolean).
Type name "OptionString" is not unique.

References to types must be unique.
Type name "OptionString" is not unique.

References to types must be unique.
If I comment out the update mutation, it generates all the types as expected for the create. The update mutation should not require any additional type or input types.
4 Replies
ZachDaniel
ZachDaniel2y ago
🤔 this looks like a bug pretty cut and dry Strange that its duplicating them somehow...ah, I think I might see? nope, still don't Could you open an issue on ash_graphql? A reproduction in the tests would be awesome If you have time also ❤️
Robert Graff
Robert GraffOP2y ago
will do. Spent some time unsuccessfully trying to write a test for ash_graphql, and while doing so figured out a work around. I did not define a graphql_type and so it was assuming one for me. Setting my own graphql_type fixes it.
def graphql_type(_), do: :option
def graphql_type(_), do: :option
So to recap: when I use a nested union as a singular argument and array attribute in two mutations while not defining a graphql_type, absinthe throws an after compile error:
## Locations
/workspace/app/deps/ash_graphql/lib/resource/resource.ex:1385
/workspace/app/deps/ash_graphql/lib/resource/resource.ex:1385

Absinthe type identifier :feature_variant is not unique.

References to types must be unique.

> All types within a GraphQL schema must have unique names. No two provided
> types may have the same name. No provided type may have a name which
> conflicts with any built in types (including Scalar and Introspection
> types).

Reference: https://github.com/facebook/graphql/blob/master/spec/Section%203%20--%20Type%20System.md#type-system


(absinthe 1.7.5) lib/absinthe/schema.ex:392: Absinthe.Schema.__after_compile__/2
(stdlib 4.3) lists.erl:1350: :lists.foldl/3
## Locations
/workspace/app/deps/ash_graphql/lib/resource/resource.ex:1385
/workspace/app/deps/ash_graphql/lib/resource/resource.ex:1385

Absinthe type identifier :feature_variant is not unique.

References to types must be unique.

> All types within a GraphQL schema must have unique names. No two provided
> types may have the same name. No provided type may have a name which
> conflicts with any built in types (including Scalar and Introspection
> types).

Reference: https://github.com/facebook/graphql/blob/master/spec/Section%203%20--%20Type%20System.md#type-system


(absinthe 1.7.5) lib/absinthe/schema.ex:392: Absinthe.Schema.__after_compile__/2
(stdlib 4.3) lists.erl:1350: :lists.foldl/3
In my repo, I can replicate it reliably. And I'm unable to replicate it in the ash_graphql test suite.
ZachDaniel
ZachDaniel2y ago
🤔 interesting. And you were working against ash_graphql main? Thanks for the extra details!
Robert Graff
Robert GraffOP2y ago
I am working on ash_graphql main. I can not figure out how to reproduce this in the test lib, but I have it working in app now using graphql_type() 🤷‍♂️

Did you find this page helpful?