Fork me on GitHub
#pathom
<
2019-04-11
>
rschmukler18:04:53

Have any of the developers of pathom considered making it so that the defresolver macro uses a constant symbol for the resolve function? In the context of repl driven development, it'd be nice to re-evaluate that macro without then having to also redefine the registry, and potentially restart a system (in the case of component or integrant). Is there much of a downside? If not, would you guys accept a PR making the change?

wilkerlucio19:04:36

the initial implementations used to do something in this direction, they relied on multi-methods for dispatching, the issue is that the setup is much harder (because you have to hook many other things). Having a simple map really cleaned up a lot of things, also improves isolation since now the full resolver is contained in that map (without extenal deps, like having it "installed" in the multi-method)

wilkerlucio19:04:18

I gotta move now, but I can tell you how to setup with multi-methods, the code still available and will be supported forever (although I like to encourage not doing so, because of the problems described, but still an option)

mitchelkuijpers21:04:33

If you create function during development which keeps creating a new parser then you can just redefine the macro and it will update

mitchelkuijpers21:04:36

That is what we do

mitchelkuijpers21:04:09

So we have something like this:

(defn parser [env query]
  (if utils/dev?
    ((create-parser) env query)
    (parser-inst env query)))

rschmukler21:04:01

Thanks for the replies! Sorry I didn't see them initially. The recreation of the parser is an interesting angle. I'll explore down that path and see where it gets me.

rschmukler21:04:12

@U060GQK8U your solution worked quite nicely! Thanks for the suggestion.

mitchelkuijpers23:04:58

Nice! :thumbsup:

wilkerlucio01:04:01

re-creating parsers is all fine for dev, but please don't do that in a per request basis in prod, a single parser is better in that scenario

rschmukler21:04:46

Another question: Is there any way to resolve the same key with different parameters as different names? For example [(:math/half-of {:n 4} (:math/half-of {:n 6})] results in {:math/half-of 2} with the resolver seemingly not even called the second time. I noticed that there's the ::pg/alias concept when porting EDN queries to GQL, but is there anything for handling it w/o using graphql?

wilkerlucio01:04:52

you can do it using: [(:math/half-of {:n 4 :pathom/as :another-name} (:math/half-of {:n 6})]

wilkerlucio01:04:56

but there is a caveat here

wilkerlucio01:04:17

pathom does cache all resolver calls by default

wilkerlucio01:04:58

and currently there is a problem that it doesn't consider the params in this caching, this will change in the future, but for now you have to remove cache for that to work, otherwise both calls will get the same value (because only the first will call the resolver, second will hit the cache)