Hi,
I have a schema that looks like this
object :post do
field(:id, non_null(:id))
field(:products, list_of(non_null(:post_product)), resolve: dataloader(:repo))
field(:description, :string)
end
object :post_product do
field(:product_id, non_null(:string)
field(:url, :string) do
resolve(&Resolver.build_url/3)
end
end
I need the post.id
to build the product URL, it should be something like this .../posts/{post_id}/products/{product_id}
One product
may be in multiple posts, so inside the Product
schema I have a list of Post
.
The client can only query products through posts, so they’re always inside a Post
scope.
How can I pass the post_id
to the post_product.url
resolver?
Or I’m going with a bad solution for this?
Thanks in advance
UPDATE: After the answer from @fuelen I realize that my example didn’t match what I need to do, so I change the question and the example