Fork me on GitHub
#pathom
<
2023-01-28
>
donavan04:01:22

Is there an extension point (or a way of achieving the same result) similar to ::pcr/wrap-resolve in that it runs once per resolver but similar to ::pcr/wrap-merge-attribute in that the result has all its attributes merged in when it’s called?

caleb.macdonaldblack19:01:12

I’d be interested to know more about what you’re trying to do. Do you have an example? If you’re wanting to output arbitrary attributes and feed them into other resolvers, then I’m not sure it could work. Pathom will make a plan using explicitly defined inputs and outputs. It wouldn’t know how to execute the graph if arbitrary attributes are being returned that aren’t specified.

wilkerlucio17:01:34

yeah, would be good to understand what you are trying to do

wilkerlucio17:01:26

wrap-resolve and wrap-merge-attribute run in very distinct phases, so you can't have a mapping 1-1 with them, for example, a resolver that returns 5 attributes will have a single call to wrap-resolve, while it will make 5 calls to wrap-merge-attribute

donavan13:02:05

Hi @U066U8JQJ and @U3XCG2GBZ; apologies for the late response. I would like the output of a resolver be dependent on it’s inputs. Concretely (and I’m not sure if this is ultimately a good idea or not), I have a resolver that returns the data for a table of items. The items themselves have raw attributes (i.e. from a database entity) and derived attributes such as formatted values that are resolved by other resolvers. Now, I would like to sort the table before returning it and I would like to sort on the formatted values. I would like to do the sorting, in a sense, by operating on the result of the resolver (like ::pcr/wrap-resolve would allow me to do in a plugin or just in the body of the resolver) but I need the other (derived) attributes merged in. Does that make sense?

Jakub Holý (HolyJak)18:01:32

How can P3 defmutations access the env, e.g. to get a db connection? https://pathom3.wsscode.com/docs/mutations/#using-defmutation only demonstrates using input params 🙏 Reading the spec for the macro it seems it can take 0 - 2 arguments so I guess in the 2 arg version one of them is the env?

wilkerlucio18:01:35

same ways as resolvers, using the 2 args, env is the first

wilkerlucio19:01:57

thanks, merged!

🙏 2
dvingo01:01:50

+1 I found this super confusing that the order of the parameters is reversed with two args vs one. My default intuition was that the environment would be the first argument for 1-arity as well as 2.. soooo confused at first hah

Jakub Holý (HolyJak)09:01:22

I can see that. Though it makes sense from the UX perspective because you will almost always need the params argument, while env only sometimes (with the exc. of global resolvers and similar). Fortunately the docs are getting ever better 🙂

dvingo13:01:38

I just always provide two arguments now using the _ as needed. One less thing to think about.

souenzzo16:01:26

I think that always require the _env is simpler to understand.

wilkerlucio17:01:58

the 0 - 2 is purely a convenience, its better to think that with 1 the env is being removed, as opposed to think you add env with 2

wilkerlucio17:01:20

the order will not change (for compatibility), pathom 2 also has the same arity order, which makes them compatible

wilkerlucio17:01:06

the reasoning, as @U0522TWDA pointed out, is because its more common to need input without env than the other way around, so pathom provides arity 1 for those cases, there also times you don't care about env or input, then you can go with zero args

wilkerlucio17:01:32

note these suggar features are only available in the defresolver & defmutation macros, using pco/resolver and pco/mutation requires the usage of arity 2 every time

wilkerlucio17:01:54

the macros will generate an arity 2 fn anyway, this is only real signature for resolvers and mutations (its never a multi-arity fn)

dvingo17:01:39

I'm just thinking from API design point of view - reordering parameters is definitely confusing: see slide 34 (https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/32713.pdf)

dvingo17:01:34

especially b/c they're both hashmaps. But good to know about this background, agreed with Jakub updating the docs will help with this. And good to know I can just use pco/resolver and write my own macro with consistent parameters

wilkerlucio18:01:06

re-ordering is a way to see it, if you think multi-arities add to the end, this is contrived but I don't see different arities this way at all, to me each different arity is like having a different function (which is what actually happens, in cljs for example), in that sense, there is no guarantee or expection that must hold between different arities

❤️ 2
wilkerlucio18:01:27

one example that we use often is reduce, that in the arity 4 adds a thing at position 3

dvingo18:01:29

yea my mental model is (defresolver [env args]) and (defresolver [env])