Hello everyone! It's my first couple of weeks using Pathom and I got amazing results from it! Really great piece of software metal I've ran into a blocker though, which is probably skills issues ๐ Maybe someone can point me to the right direction. So I have a batch resolver that returns a vector of things. Is it possible to create a resolver that groups the output from the batch resolver and returns a map? I've tried the straightforward way of specifying the the input of the grouping resolver is the output of the batch resolver but then the grouping resolver just returns a vector of things as well, which makes sense cause I'm guessing it's triggered per each output of the batch resolver. So maybe I'm just trying to do something that Pathom isn't supposed to do... ๐คท Appreciate any help. And grateful for Pathom ๐
glad to hear you got it figured! another place you can see a similar example is in the docs for resolvers using nested inputs: https://pathom3.wsscode.com/docs/resolvers#nested-inputs
Are you looking to do something like a reduce step in Pathom? If so, Iโm not aware of any way to do that except by calling Pathom twice, with the reduce step between the calls.
> Are you looking to do something like a reduce step in Pathom? Yep, I guess that's what I'm trying to do ๐
I mean, you could theoretically call Pathom from a Pathom resolver and then reduce in the resolver. I havenโt had a reason to do so, but I donโt see why it wouldnโt be OK. Any caveats @wilkerlucio?
hello @countgizmo, thanks for the kind message and welcome, I'm trying to understand the shape of things you are trying to reduce from, when we talk batch we talk different entities grouping their request to optimize the load, so a batch always returns a vector given it has to distribute the results back to the callers
so I'm trying to understand where you are trying to inject the "grouped" results of that, can you give some example steps of how you image the data flowing?
Basically, you have some resolver returning a batch of [A B C], letโs say, and the goal is to take those (collectively) as input to some other resolver and produce a single entity D.
Iโm not aware of a way to do this with a single Pathom call, unless you recursively invoke Pathom in the resolver of D.
you can do something if you are in some control over the structure, but it really depends, if for instance you have a collection where each item is a value of the batch, you can in the parent ask for all of that and reduce
but in Pathom 3, batches go beyond a single sequence, so they might be anywhere in your request, and altough you could gather from a specific list, you can't when they are disparated, that's why I'm wonder what is the kind of shape transformations you look for
to illustrate, this is what I mean if they are a shared list in the children you can combine then with a nested input resolver:
(ns demos.batch-reduce
(:require [com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.interface.eql :as p.eql]))
(def user-scores
{1 {:user/score 10}
2 {:user/score 10}
3 {:user/score 10}})
(pco/defresolver all-users []
{::pco/output
[{:user.refs/all
[:user/id]}]}
{:user.refs/all
(mapv #(array-map :user/id %) (keys user-scores))})
(pco/defresolver user-score [ids]
{::pco/batch? true
::pco/input [:user/id]
::pco/output [:user/score]}
(mapv #(get user-scores (:user/id %)) ids))
(pco/defresolver scores-combined [{:keys [user.refs/all]}]
{::pco/input [{:user.refs/all [:user/score]}]}
{:user.reductions/scores-sum
(transduce (map :user/score) + 0 all)})
(def env
(pci/register
[all-users
user-score
scores-combined]))
(comment
(p.eql/process env [:user.reductions/scores-sum]))this not really a batch thing (would work the same without batching) but afaik it may be the kind of thing you are looking for
@wilkerlucio Thank you so much for the detailed example! ๐
I've used it as a reference and got my own code to work ๐
The example was very useful. I have also noticed that I need to better understand the EQL format for inputs. This line {::pco/input [{:user.refs/all [:user/score]}]} was actually a big revelation for me ๐ก
I'll go study https://edn-query-language.org/eql/1.0.0/specification.html#_joins more carefully.
And thank you @henrik for your analysis of my issue. It also helped me understand what I'm actually trying to achieve ๐