Hello all, how do I use relationship one-to-many? Is it in object or query?
I don’t fully understand the question. In lacinia, you can just mark a field as having type (list :Thing)
, then you can just return a list from your resolver
but how do you make the relationship one to many in resolver?
like if you have relationship product -> items
You just return a list of things. So say that you have a type Product { }
, that has a field Product#items
, which has type (list :Item)
, you can create a resolver that returns that list of items
So, typically, your root query resolver can hit a DB and pull a record that includes an id of some kind. The query document selects fields from that data, but will also pass it (not the selected map, the raw map as returned from your own code) down a level; that can extract the id and run a new query that returns a list of child objects. It's right in the name: a graph of objects. Complexities hidden on the server, client is free to navigate that graph all in one go (rather than REST where you either get too much data, or have to make multiple queries). Of course, nothing is free, but more advanced Lacinia users can mitigate costs by pre-selecting data.
Lennart, but the resolver is formatted like what?