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):
☝️ This generates proper GraphQL input types automatically.
2. Using custom change with GraphQL managed_relationships (doesn't work):
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!2 Replies
There is, but its a bit hacky
you can add
change manage_relationship(..., ignore?: true)
to tell things about the types but actually ignore it on processing?I went around it with using
manage_relationship and validation layer to make sure they're not being abused 😄