I have roughly the following model:
People, can make Recommendations, about Things that are in Categories.
Each has an Absinthe schema. I would like to add a field to People that lets a user query how many Things that person has Recommended in a Category, so:
query {
person(id: "id") {
name
categories {
name
numberOfRecommendations # computed, not a real field
}
}
}
This is straightforward to build if categories
is one table away, I just do a resolve dataloader(:categories)
on the Person
schema, and a run_batch
override on the Category
schema to define the custom aggregation of numberOfRecommendations
. However, since I’m two tables away here, I’m in effect aggregating twice, as I want the number of all recommendations, across all Things within a Category
I’m currently stringing this together by overriding run_batch
and building a query that does the necessary joins underneath and then doing the relevant count in another run_batch
on the Categories
context. I think I can get it to work, but it feels… kludgey. Is there a more idiomatic way to do this?