I’m working to set up my first GraphQL API and I got stuck on how to properly join between 2 related models. In the classic example, one user has many posts. This tutorial showed how to join from a post to a user, but I can’t figure it out the other way around… I don’t see an example of this in the Absinthe book either.
My resolver module looks something like this:
defmodule ApiWeb.Schema.MySchema do
use Absinthe.Schema.Notation
use Absinthe.Ecto, repo: Api.Repo
object :parent_thing do
@desc "UUID unique identifier"
field(:id, :string)
@desc "Name of the thing"
field(:name, :string)
@desc "Children"
# This returns results, but with nil values
field(:children, list_of(:child_thing))
# This doesn't work at all
field(:children, list_of(:child_thing), resolve: assoc(:uploads))
# This works, but it does not filter the children by the parent
field(:children, list_of(:child_thing), resolve: &Api.Children.get_list/3)
end
object :child_thing do
@desc "UUID unique identifier"
field(:id, :string)
field(:parent_id, :string)
field(:name, :string)
end
end
Can anyone help shed some light on this? Thanks!