Fork me on GitHub
#pathom
<
2023-08-17
>
jeroenvandijk11:08:00

Is it possible to have resolvers return smart-maps?

jeroenvandijk11:08:41

I tried, but what I get back is normal maps and I can’t invoke new lookups

jeroenvandijk11:08:29

This idea might not be a good idea performance wise, but I was thinking it could be nice for expressiveness and optimise later

wilkerlucio13:08:37

not a thing, the map that returns from resolver is merged on a parent map, IMO this feels quite a mess, if you use the smart map directly, you can already read all the keys, I dont see the point of trying to mix them

nivekuil14:08:45

you can return anything, including an explicitly initialized smart map. doesn't sound like a great idea in general though since EQL is even more expressive

jeroenvandijk14:08:24

Yeah I tried explicitly initialized smart map, but I suspected it got merged like Wilker confirmed. I did succeed forwarding a smart map via metadata, but this forces me to know the structure and extract the metadata.

jeroenvandijk14:08:55

Anyway, thanks for the feedback. I guess i’m trying something weird. Will experiment a bit more

jeroenvandijk16:08:11

Is there an equivalent for passing query options to smart maps? E.g. let say I have a resolver :users/list that accepts the param :filter what would be the equivalent of the following?

(p.eql/process env '[(:users/list {:filter :active})]`)
The below works, but I don’t know how to apply my param :filter
(:users/list (psm/smart-map env {}))

✔️ 2
2
jeroenvandijk16:08:09

In analogy to the resolver I thought maybe this could work, but it doesn’t:

(get (psm/smart-map env {}) '(:users/list {:filter :active}))

jeroenvandijk16:08:09

After a bit more digging I found an example in the tests that seem to work for me:

(-> (psm/smart-map env {})
      (psm/sm-touch! '[(:users/list {:filter :active})])
      :users/list)

jeroenvandijk18:08:51

Maybe I’m wrong but so far it seems that

(= (p.eql/process query-env query-data)

     (->
       (psm/smart-map query-env {})
       (psm/sm-touch! query-data))) ;=> true

wilkerlucio18:08:03

yeah, touch is like a preload feature for smart maps

👌 2
Joel03:08:11

I guess nested data doesn’t make sense with Smart Maps?

jeroenvandijk09:08:07

So far I really like that with this feature you can treat everything like maps (and then potentially add optimizations later)