ash-project / ash_graphql

The extension for building GraphQL APIs with Ash
https://hexdocs.pm/ash_graphql
MIT License
73 stars 49 forks source link

AshGraphql 0.28.1 breaks when resource is in more than one API #194

Closed sezaru closed 4 months ago

sezaru commented 4 months ago

Describe the bug This bug is for a project that I haven't update to Ash 3 yet, so I'm not sure if the same bug is reproducible in Ash 3 with the latest version of Ash Graphql.

Adding a resource that is used by AshGraphql in two or more APIs, will break compilation.

To Reproduce Have a resource that has AshGraphql.Resource extension, then add it to two different APIs which also uses AshGraphql.Api extension.

During compilation, it will fail with a bunch of errors like this one:

== Compilation error in file lib/core/graphql/schema.ex ==
** (Absinthe.Schema.Error) Compilation failed:
---------------------------------------
## Locations
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3132
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3132

Type name "AppointmentDataType" 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
---------------------------------------
## Locations
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3132
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3132

Absinthe type identifier :appointment_data_type 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
---------------------------------------
## Locations
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3146
/var/home/sezdocs/projects/rebuilt/platform/core/deps/ash_graphql/lib/resource/resource.ex:3146

Type name "AppointmentSortField" 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

Expected behavior I think that AshGraphql should identify that the resource is the same and work with multiple APIs

** Runtime

zachdaniel commented 4 months ago

AFAIK this is fixed in 3.0. Do you need a back port fix or can you wait to update to 3.0 for the fix?

sezaru commented 4 months ago

We do plan to upgrade to Ash 3 in the next few weeks, so for now we can just "duplicate" the resource in the other API as a workaround. Thanks!