graphql

fabrao 2021-04-19T03:16:36.012200Z

Hello all, how do I use relationship one-to-many? Is it in object or query?

2021-04-19T08:37:30.012300Z

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

fabrao 2021-04-19T09:14:24.012500Z

but how do you make the relationship one to many in resolver?

fabrao 2021-04-19T09:17:14.012700Z

like if you have relationship product -> items

2021-04-19T12:11:08.012900Z

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

hlship 2021-04-19T16:12:03.013100Z

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.

fabrao 2021-04-20T21:49:10.013400Z

Lennart, but the resolver is formatted like what?