Fork me on GitHub
#pathom
<
2022-10-19
>
wilkerlucio01:10:47

🚀 5
🎉 3
roklenarcic09:10:42

How do you write a resolver for a recursive datastructure?

donavan11:10:57

It’s relatively straightforward

roklenarcic12:10:56

Well how do I tell Pathom that the output of the resolver is a nested tree?

roklenarcic12:10:45

So obviously you can make a resolver that has the output [:id {:children [:id]}]

roklenarcic12:10:09

that resolver can answer a recursive query…

roklenarcic12:10:50

But it will be called for each node once. And I get the whole tree in a single DB query.

dvingo14:10:45

if you return the entire tree pathom will just return it and not continue calling the resolver

dvingo14:10:11

i've used that in the past as an optimization - calling db/pull directly instead of having nested pathom calls

Eric Dvorsak15:11:55

If you want to keep the decomposition into resolvers, you can also leverage batching in pathom3. let's say you have a resolver that gets a list of IDs, one that gets the attributes, and maybe a nested one that gets nested attributes from the db It will only take 3 queries, 1 per resolver, if you write batch queries In pathom2 that wasn't working for nested attributes