Ash FrameworkAF
Ash Framework4mo ago
4 replies
Geril

GraphQL input type with `Ash.Changeset.manage_relationship` instead of `change manage_relationship(`

I'm working with Ash and AshGraphql and running into an issue with GraphQL input type generation when handling relationships in custom changes.

Setup:

- I have a File resource with a has_one :image relationship
- I want to create both the file and its related image in a single mutation
- I'm using a custom change module to handle the relationship logic

Problem:
When I use Ash.Changeset.manage_relationship in my custom change module (to create an image resource conditionally) instead of using change manage_relationship(:image, :image, type: :create), the GraphQL API only accepts raw JSON for the image argument instead of generating proper nested input types.

What I've tried:
1. Using the built-in manage_relationship change (this works):
create :create do
  accept [:original_name, :content_type, :access, :type]
  argument :image, :map, allow_nil?: true
  
  change manage_relationship(:image, :image, type: :create)
  # Other changes...
end


☝️ This generates proper GraphQL input types automatically.

2. Using custom change with GraphQL managed_relationships (doesn't work):
# In graphql block
managed_relationships do
  managed_relationship :create, :image
end

# In action
create :create do
  accept [:original_name, :content_type, :access, :type]
  argument :image, :map, allow_nil?: true
  
  change MyApp.Files.File.Changes.CreateImplementation
  # Other changes...
end


Question:
Is there a way to get AshGraphql to automatically generate proper nested input types when using Ash.Changeset.manage_relationship in custom changes?

The managed_relationships configuration in the GraphQL block doesn't seem to work when the actual relationship management is handled in a custom change rather than the built-in manage_relationship change.

Am I missing something? Is there a way to tell AshGraphql about the relationship structure when using custom changes?

Thanks a lot!
Was this page helpful?