Relations with GraphQL
I want to make a simple
belongs_to
relationship. I tried so many things but I can almost never even compile it. :/ I'm not looking to debug anything, I just can't get it from the documentation. I even tried searching for :ash_graphql
usages in the wild with GitHub Code Search. How do I wire this up with GraphQL?6 Replies
What kind of errors are you getting? We are using ash_graphql alot and this pretty much just worked for us. Are you sure you have all the resources in the registry, all resources have the AshGraphql extension and have declared a type in the graphql section. And did you add the
use AshGraphql, apis: [..]
statement to your absinthe schema?Oops, sorry, I completely overlooked this. I forgot to list one of the resources. Also, is
type: :append_and_remove
the right type for belongs_to
. E.g. I have a post and that post can only belong to one category?you mean
type: :append_and_remove
in the context of manage_relationship? You only need that if you want to create/update both resources at once, not for reads. But the type also depends on your usecase, I would check out this section of the docs to get an understanding of what the type is doing https://www.ash-hq.org/docs/module/ash/latest/ash-changeset#function-manage_relationship-4I read this part but I'm not sure I understand it correctly. My goal is to assign an existing category to a newly created post. Do I need
manage_relationship
in that case?if that is the case I probably wouldn't use manage_relationship at all. You just set the
category_id
on the post in this case and the categories were created beforehandAlright, thank you for your help. I'm loving Ash so far! The community is amazing.
I'm gonna mark this as solved.