Fork me on GitHub
#pathom
<
2019-01-23
>
Daniel Hines16:01:12

Are there any examples of consuming pathom from JS?

souenzzo17:01:35

@d4hines you say JS as browser or JS as node? it's CLJS or "raw JS"? If you have a pathom API in /api you can do fetch("/api" {method: "POST", body: "[:api/hello]"}).then(x => x.text()).then(console.log) it will print "{:api/hello \"Hello\"}"

Daniel Hines17:01:46

Oh, ok, I assumed transit was built in or something. That still leaves how to deal with namespaced keywords and other impedance mismatches between EDN and JSON, but that’s not unique to pathom.

souenzzo17:01:23

you can also run pathon on client with something like parser(ctx, edn.read_string("[:api/hello]")).then(edn => console.log(edn.to_js(edn))) will print {api_hello: "Hello"} There is really many ways to use pathom.

Daniel Hines17:01:10

Ok, that last example pretty well solves it for me. Thanks!

souenzzo18:01:30

I never see no one using pathom like this. But I'm sure that it's possible.

Daniel Hines18:01:02

I want to show the capabilities of pathom to co-workers, but they aren’t ready for Clojure yet 😀

👍 10
mss19:01:34

hey all, trying to get a simple mutation up and running and my symbols generated by the defmutation macro don’t seem to be getting resolved by the connect plugin registrar. code looks like the following:

(pc/defmutation test-mutation [env params]
  {::pc/sym    'test-mutation
   ::pc/params [:test-tempid]
   ::pc/output [:test-id]}
  (let [test-id (.toString (java.util.UUID/randomUUID))]
    (println "IN MUTATION")
    {:test-id test-id}))

(defn make-parser []
  (p/parser
    {::p/env {::p/reader               [p/map-reader
                                        pc/parallel-reader
                                        pc/open-ident-reader
                                        p/env-placeholder-reader]
              ::p/placeholder-prefixes #{">"}}
             ::p/mutate pc/mutate
             ::p/plugins [(pc/connect-plugin {::pc/register [test-mutation]})
                          p/error-handler-plugin
                          p/request-cache-plugin
                          p/trace-plugin]}))
and calling
((make-parser) {} `[(test-mutation {:test-tempid "12345678"})])
=> Mutation not found

mss19:01:25

any idea why that might be?

mss19:01:35

figured it out. didn’t realized that adding the ::pc/sym was adding an ns onto the mutation sym

Daniel Hines20:01:36

The current namespace, right?

Daniel Hines20:01:55

(i.e namespace in which test-mutation was defined)

mss20:01:08

yep exactly

mss20:01:06

unfortunately when defining the mutation in the data format like so:

(def my-mutations
  [{::pc/sym 'test/test-mutation
    ::pc/params [:test-tempid]
    ::pc/output [:test-id]
    ::pc/mutation (fn [env params]
                    (let [test-id (.toString (java.util.UUID/randomUUID))]
                      (println "IN MUTATION")
                      {:test-id test-id}))}])
and running a parse like:
(my-p {}
      `[(test/test-mutation {:test-tempid "12345678"})])
I’m getting an error " Mutation not found - {:mutation test/test-mutation}"

mss20:01:29

seems like there’s some disconnect between the way the macro does symbol resolution for mutations and the data literal format

mss20:01:33

weird because the output of the mutation data literal looks like:

#:com.wsscode.pathom.connect{:sym test/test-mutation, :params [:test-tempid], :output [:test-id] ...}

mss20:01:24

unfortunately when defining the mutation in the data format like so:

(def my-mutations
  [{::pc/sym 'test/test-mutation
    ::pc/params [:test-tempid]
    ::pc/output [:test-id]
    ::pc/mutation (fn [env params]
                    (let [test-id (.toString (java.util.UUID/randomUUID))]
                      (println "IN MUTATION")
                      {:test-id test-id}))}])
and running a parse like:
(my-p {}
      `[(test/test-mutation {:test-tempid "12345678"})])
I’m getting an error "Mutation not found - {:mutation test/test-mutation}"

wilkerlucio12:01:08

still having the issue mms? I wonder if the test might be expanding to somethign else