Ash FrameworkAF
Ash Framework3y ago
119 replies
\ ឵឵឵

Using Ash Resources as input types

I've occasionally encountered issues using Ash resources as input types to actions of other resources. The most common patterns I've seen to resolve this are to simply turn the inputs into a map and let
manage_relationship
figure it out, or to take as a parameter only the :uuid and similarly construct a map with just %{id: uuid} for
manage_relationship
.

The culprit in some cases seems to be AshGraphql, which errors following this pattern:
== Compilation error in file lib/app/schema.ex ==
  ** (RuntimeError) Cannot construct an input type for App.Post
      (ash_graphql 0.23.2) lib/resource/resource.ex:3300: AshGraphql.Resource.do_field_type/4
      (ash_graphql 0.23.2) lib/resource/resource.ex:866: anonymous fn/6 in AshGraphql.Resource.mutation_fields/4
      (elixir 1.14.4) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
      (ash_graphql 0.23.2) lib/resource/resource.ex:859: AshGraphql.Resource.mutation_fields/4
      (ash_graphql 0.23.2) lib/resource/resource.ex:461: anonymous fn/5 in AshGraphql.Resource.mutations/4
      (elixir 1.14.4) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
      (elixir 1.14.4) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
      (ash_graphql 0.23.2) lib/resource/resource.ex:431: AshGraphql.Resource.mutations/4


Internally, there is not a lot of danger to using the :map approach, since
manage_relationship
still knows what kind of resource it's supposed to be creating and will error accordingly, but it would be quite nice to be able to declare the input type as the resource itself and get it reported in the GQL schema, generated docs, etc.
Was this page helpful?