Fork me on GitHub
#pathom
<
2020-05-06
>
ouvasam12:05:56

I have a problem using crux and pathom and i can't find the problem. I have a resolver that call a function with a datalog query in crux. The first time it is executed all his fine, the crux function is called and return the results. If i call it within a few seconds, the resolver is not called anymore or at least no error is seen. If i call the crux function from the ring query directly it works perfectly. So it seems that crux is ok. If i remove the crux call in the resolver it is call normally and return correctly I have no idea what could be wrong here ? If someone has an idea ? Many thanks

ouvasam12:05:21

Here is the code for the parser

(def parser
  (p/async-parser
   {::p/env     {::p/reader               [p/map-reader
                                           pc/async-reader2
                                           pc/ident-reader
                                           p/env-placeholder-reader]
                 ::p/placeholder-prefixes #{">"}}
    ::p/mutate  pc/mutate-async
    ::p/plugins [(pc/connect-plugin {::pc/register app-registry})
                 p/error-handler-plugin
                 p/trace-plugin
                 params-down-pathom-plugin]}))

ouvasam12:05:45

The code for the ring handler

(defn query
  [query]
  (let [params (clojure.walk/keywordize-keys (:params query))
        q (:query params)]
    (println "ring query" q)
    ; (println (crux-api/get-concept-translations-by-jurisdiction 1 (rand-nth (range 730 750))))
    {:status 200
     :body
     (encode-transit-json
      (<!! (parser params (clojure.edn/read-string q))))}))

ouvasam12:05:01

The code for the resolver that only work "sometime"

(pc/defresolver by-jurisdiction-id [{:keys [] :as env} params]
                {::pc/input #{:translation/query}
                 ::pc/output [:translations
                              [:translation/id
                               :translation/language
                               :translation/value
                               :translation/status
                               :jurisidction/id
                               :concept/id
                               :app/type]]}
                (let [query (parse-query-params env)
                      jurisdiction-id (:jurisdiction/id query)
                      concept-id (:concept/id query)
                      results (crux-api/get-concept-translations-by-jurisdiction)]
                    {:translations []}))

ouvasam12:05:50

the same without the crux call work perfectly

ouvasam13:05:37

I also ask on crux channel but can't find a solution ...

Chris O’Donnell15:05:32

Have you tried wrapping the resolver body in a try-catch to see if an exception is getting silently swallowed?

dvingo16:05:10

it looks like your resolver's output is invalid for a join

dvingo16:05:25

{:translations [..]}

ouvasam16:05:47

yes i tried to catch error but nothing

ouvasam16:05:12

output is still the same each time

ouvasam16:05:41

i did try with something that return the same

dvingo16:05:15

your output should be:

[{:translations
                              [:translation/id
                               :translation/language
                               :translation/value
                               :translation/status
                               :jurisidction/id
                               :concept/id
                               :app/type]}]

💯 4
ouvasam08:05:50

Many thanks for the answers, but even with this i still have troubles

ouvasam12:05:29

i found my problem ! I had two resolver with the same output signature but one with an input. It did a conflict apparently. Many thanks for your support

Eugen13:05:33

replace Fulco with pathom

cjmurphy13:05:04

@eugen.stan I know I suggested you come here, but now I'm not so sure what the API you are interested in would be. With Pathom there is no static API as such because Pathom receives EQL and sends back the query results.

Eugen13:05:50

I'm asking about HTTP API - the one the external developers would use

Eugen13:05:55

so Fulcro it is

cjmurphy13:05:58

Well Fulcro sends across the EQL, that it created from the composition of Fulcro component's queries. So again I'm not sure where the static API would be.

kszabo13:05:33

the recently released pathom-viz electron/stanadlone app is close as you can get currently without writing any code yourself

Eugen13:05:48

Thanks, something like that . it would be great if it can generate docs to be served by static web servers

kszabo13:05:17

yeah, there is no static site yet, but you can use the server-side rendering cljs of the above code to implement it

Eugen13:05:40

thanks, I will keep that in mind. In the mean time I filed a question issue . It should remain there as docs at least.

👍 4
Michael W16:05:03

How do you tie 2 different datasources to each other? I have 2 different apis, one works off id (ddi), I have that fully wired with resolvers, and can query it. The other api (aci) works off ip address, I have that fully wired with resolvers and can query it. How do I tell the first api that the ip field is what it needs to query from the other api and not the id field?

Michael W17:05:12

(parser {} [{[:ip/ip "10.4.94.48"] [:ip/ip :ip/pool :ip/subnet :ip/aci]}])
{[:ip/ip "10.4.94.48"] #:ip{:ip "10.4.94.48", :pool "17", :subnet "59", :aci :com.wsscode.pathom.core/not-found}}

Michael W17:05:43

(parser {} [{[:aci/ip "10.4.94.48"] [:aci/ip :aci/mac]}])
{[:aci/ip "10.4.94.48"] #:aci{:ip "10.4.94.48", :mac "00:50:56:BB:ED:01"}}

souenzzo17:05:16

add (pc/alias-resolver2 :ip/ip :aci/ip) to your registry @michael819

Michael W17:05:18

is that a plugin?

Chris O’Donnell17:05:25

No, it's a resolver. It is equivalent to the following two resolvers:

(defresolver ip->aci-resolver [_ input]
  {::pc/input #{:ip/ip}
   ::pc/output [:aci/ip]}
  {:aci/ip (get input :ip/ip)})

(defresolver aci->ip-resolver [_ input]
  {::pc/input #{:aci/ip}
   ::pc/output [:ip/ip]}
  {:ip/ip (get input :aci/ip)})

Michael W17:05:58

I tried that and it didn't work

sergey.shvets17:05:45

@michael819 I'm not sure I fully understand your question, but it seems like this might help: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/plugins.html#_example_shard_switch

Michael W17:05:27

Thanks, let me play with it some more, I know I am really close since I can query both apis independently I just need to figure out how to wire them together.

Michael W17:05:43

I'm looking at the shard thing now @bear-z

sergey.shvets17:05:10

Are your apis independent or there is some field that you can link them on?

sergey.shvets17:05:24

Because what souenzzo suggests should do the trick if you just need to connect one field to the other.

Michael W17:05:47

Yeah they have a common field, the ip address

sergey.shvets17:05:13

What is the end query you're trying to do?

sergey.shvets17:05:28

(parser {} [{[:ip/ip "10.4.94.48"] [:ip/ip :ip/pool :ip/subnet :ip/aci]}]) 
I think you need to change it to
(parser {} [{[:ip/ip "10.4.94.48"] [:ip/ip :ip/pool :ip/subnet :aci/ip :aci/mac]}])
And use alias-resolver2. That should work

Michael W17:05:16

So I have a DDI (DHCP/DNS/IPAM) that has bad mac addresses in it. I am trying to query for mac addresses that don't match between the systems, they both share the ip as a key.

Michael W17:05:10

I get nils for :aci/ip and :aci/mac

sergey.shvets17:05:05

have you registered your (pc/alias-resolver2 :ip/ip :aci) to the parser

Michael W17:05:28

(def ip-aci-alias (pc/alias-resolver2 :ip/ip :aci/ip))$
$
(def resolvers [aci-ip aci-mac$
                subnet-id subnet-ip subnet-start subnet-end$
                pool-id pool-ip$
                ip-id ip-ip ip-aci-alias])$

Michael W17:05:38

I have $ for end of line

sergey.shvets17:05:39

Can you confirm that resolver with #{:aci/ip} input gets called?

sergey.shvets17:05:09

There is a pathom-viz standalone app that can make your debugging much easier

Michael W17:05:44

Ah hah! Got it working, thanks @souenzzo @bear-z

Michael W17:05:05

(parser {} [{[:ip/ip "10.4.94.48"] [:ip/mac :aci/mac]}])
{[:ip/ip "10.4.94.48"] {:ip/mac "05:42:39:84:62:62", :aci/mac "00:50:56:BB:ED:01"}}

sergey.shvets17:05:22

Nice! What was the problem?

Michael W18:05:19

I had a typo in some other resolver where it was :aci/id not :aci/ip

sergey.shvets18:05:15

Glad you found it!

Michael W18:05:49

The alias ultimately glued the 2 systems together, so thanks again for the help, made my day!

parrot 8