pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
andrewzhurov 2020-08-09T17:01:19.410400Z

Heyo, fellas! 👋

andrewzhurov 2020-08-09T17:03:53.411100Z

I'm new to the tech, been trying to run locally

[{([:customer/id 123] {:pathom/context {:customer/first-name "Foo" :customer/last-name "Bar"}})
  [:customer/full-name]}]
and it fails with
1. Unhandled java.lang.IllegalArgumentException
   Key must be integer

    APersistentVector.java:  294  clojure.lang.APersistentVector/invoke
                      REPL:   96  app.server-components.pathom/eval48368
                      REPL:   95  app.server-components.pathom/eval48368
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7132  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   91  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  155  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  190  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  189  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  830  java.lang.Thread/run

andrewzhurov 2020-08-09T17:04:41.411800Z

Bit more of context:

(defn build-parser [db-connection]
  (let [real-parser (p/parallel-parser
                      {::p/mutate  pc/mutate-async
                       ::p/env     {::p/reader               [p/map-reader pc/parallel-reader
                                                              pc/open-ident-reader p/env-placeholder-reader]
                                    ::p/placeholder-prefixes #{">"}}
                       ::p/plugins [(pc/connect-plugin {::pc/register all-resolvers})
                                    (p/env-wrap-plugin (fn [env]
                                                         ;; Here is where you can dynamically add things to the resolver/mutation
                                                         ;; environment, like the server config, database connections, etc.
                                                         (assoc env
                                                                :db (d/db db-connection)
                                                                :conn db-connection
                                                                :config config)))
                                    (preprocess-parser-plugin log-requests)
                                    p/error-handler-plugin
                                    p/request-cache-plugin
                                    (p/post-process-parser-plugin p/elide-not-found)
                                    p/trace-plugin]})
        ;; NOTE: Add -Dtrace to the server JVM to enable Fulcro Inspect query performance traces to the network tab.
        ;; Understand that this makes the network responses much larger and should not be used in production.
        trace?      (not (nil? (System/getProperty "trace")))]
    (fn wrapped-parser [env tx]
      (async/<!! (real-parser env (if trace?
                                    (conj tx :com.wsscode.pathom/trace)
                                    tx))))))

((build-parser (client/get-conn))
 {} [{([:customer/id 123] {:pathom/context {:customer/first-name "Foo" :customer/last-name "Bar"}})
      [:customer/full-name]}])
com.wsscode/pathom {:mvn/version "2.2.31"}

andrewzhurov 2020-08-09T17:04:48.412Z

Any leads?

andrewzhurov 2020-08-09T17:05:45.413Z

Sorry if it had been asked, googled something close in clojurians slack log, but the site appears down for me

jaihindhreddy 2020-08-09T17:36:35.416700Z

The "Bit more of context" part isn't necessary. Clojure vectors can be called as functions. You can call vectors with indices, and get back elements at those indices. For example, ([:a :b] 0) evaluates to :a and ([:a :b] 1) evaluates to :b. In your case, you're trying to call [:customer/id 123] like a function, but with something that's not an int (like indices). So, you're getting the IllegalArgumentException

jaihindhreddy 2020-08-09T17:37:36.417800Z

You can quote the list to get around this. For example, try ([:a :b] 100) and '([:a :b] 100) in your REPL.

lgessler 2020-08-09T17:54:47.417900Z

you can get the cached version by clicking the little arrow next to the result and hitting "Cached"

andrewzhurov 2020-08-09T19:02:45.419800Z

> Clojure vectors can be called as functions being my third year in production I learn that only now haha 😅 thank ya

👍 1
andrewzhurov 2020-08-09T19:04:53.419900Z

oh indeed, nice move