Fork me on GitHub
#pathom
<
2020-05-26
>
wilkerlucio01:05:38

@myguidingstar I suggest you use the async-parser for that

jacklombard05:05:26

Hey all, how does HTTP/CDN caching work for pathom/transit? Can it be done? If yes, is purging the cache straight forward?

codonnell10:05:09

If you wanted to do http caching of eql queries, you could try passing the eql as a query param. Pathom doesn't specify how eql gets from your client to the server. That is completely up to you.

👍 4
myguidingstar06:05:27

@wilkerlucio my question is what else I need to change to use async, given that I use (-> env ::pcp/node) in my dynamic resolver

wilkerlucio07:05:38

that could be a bug, does it work normally on sync parsers but not on async?

myguidingstar08:05:07

yes, it works on sync

myguidingstar06:05:09

I tried p/parallel-parser and async-parser, but ::pcp/nodereturns nil in both cases, so I guess there's something I miss

myguidingstar08:05:00

my bad, I pass the wrong order of params to resolve function

myguidingstar08:05:12

(-> env ::pcp/node)does work for async parser

Jakub Holý (HolyJak)14:05:36

@wilkerlucio FYI Import of latest v 1.0.10 to cljdoc failed https://cljdoc.org/builds/31120

👀 4
Michael W15:05:54

Are there any good examples of using the parser? I'm still new to clojure, got my api data sources all wired up into pathom, and now I can't seem to figure out how no run multiple queries and pull the data out. I can do 1, and I get the data in a PersistentArrayMap but I'm kinda lost at that point...

codonnell16:05:45

@michael819 you could take a look at pathom's tests.

Michael W16:05:29

I have been looking at those, but when I run a query I get a map back with the query as the key, but in those tests it looks like there is no key, just a map of results

codonnell16:05:29

How are you calling the parser?

Michael W16:05:03

(parser {} [{[:ddi/ip "192.168.1.111"] [:ddi/name :ddi/mac :aci/mac]}])
{[:ddi/ip "192.168.1.111"] {:ddi/name "", :ddi/mac "00:25:b5:21:a0:57", :aci/mac "00:25:b5:21:a0:57"}}

codonnell16:05:05

That looks right to me

codonnell16:05:27

The key in your result map is the ident for which you made the query

codonnell16:05:40

And the value has all the attributes you queried for

Michael W16:05:55

Yeah, but in the tests for pathom his = assertions all just have the results, without the ident key

codonnell16:05:14

Can you link to a specific test?

Michael W16:05:55

(is (= (parser {} [:foo])
           {:foo "bar"}))

    (is (= (parser {} [:foo :aa])
           {:foo "bar"
            :aa  :not-found}))

Michael W16:05:35

All the assertions are just for the results, there is no map key for the ident, which is what confused me.

Michael W16:05:00

The link you provided is much clearer, I see you using select-keys and get to pull the results out using the ident.

👍 4
codonnell16:05:11

Those tests aren't using pathom connect, which is why the result structure is different.

codonnell16:05:21

I won't recommend looking at pathom's tests in the future; they aren't super helpful for a beginner, it seems! 😅

codonnell16:05:29

Even the connect tests are mostly verifying internals or seem to be constructed to verify certain bits of behavior rather than to illustrate how the parser is meant to be used.

Michael W16:05:20

I thought the developer guide was good except that one thing, everything in there doesn't show how to really use the parser.

codonnell17:05:43

@michael819 Top level keys like that are another way to use the parser. In my experience they're usually used to get to a set of entities, but they can also be used as global constants (or to do something like inject the current timestamp) as they seem to be in the test you linked. You could reproduce the parser from your test with this resolver:

(defresolver foo-resolver [_ _]
  {::pc/input #{}
   ::pc/output [:foo]}
  {:foo "bar"})

(def parser ...)

(parser {} [:foo])
{:foo "bar"}
Here's an actual resolver from the project the blog post I linked above was talking about that also uses a top level key:
(defresolver created-gift-lists
  [{::db/keys [pool] :keys [requester-id]} _]
  {::pc/input #{}
   ::pc/output [{:created-gift-lists [::gift-list/id]}]}
  {:created-gift-lists
   (db/execute! pool
     {:select [:gl.id]
      :from [[:gift_list :gl]]
      :where [:= requester-id :gl.created_by_id]
      :order-by [:gl.created_at]})})

(def parser ...)

(parser {:requester-id 1} [{:created-gift-lists [::gift-list/id]}])
{:created-gift-lists [{::gift-list/id 1} {::gift-list/id 2}]}

codonnell17:05:53

I'm sure Wilker talks about this in at least one of his talks. Maybe this one? https://www.youtube.com/watch?v=IS3i3DTUnAI

myguidingstar17:05:47

@wilkerlucio I have this piece of code that works on clj but somehow slightly incorrect in cljs https://gist.github.com/myguidingstar/6bff072b099cc0d5a178c61f828eb925

myguidingstar17:05:36

I guess it's a bug with async planner in cljs