Fork me on GitHub
#pathom
<
2019-02-17
>
currentoor02:02:12

anyone using pathom with nodeJS?

wilkerlucio02:02:54

@currentoor should work same as running in the browser, are finding issues to setup?

currentoor02:02:18

no just wondering if there was an example already written somewhere

currentoor02:02:28

shouldn’t be too hard to figure out

wilkerlucio02:02:45

yeah, you can hook on web framework like express

wilkerlucio02:02:21

if you go for it, remember to return promise channels on the resolvers that do async calls (like http requests)

wilkerlucio02:02:40

pathom can leverage that on the coordination side 😉

currentoor02:02:56

sounds good simple_smile

currentoor02:02:27

as part of our product we need on-site controllers to interact with equipment like bar code scanners and printers

currentoor02:02:47

so i’m writing those as node servers on small linux devices

currentoor19:02:23

I’m having troubled connecting pathom in-browser mutations to my fulcro application

currentoor19:02:06

that’s a gist of how i set it up

currentoor19:02:47

but when i trigger that remote mutation, like so in the Fulcro Inspect Query tab

[{(ucv.ui.receipt/print-receipt
   {:remote :rest,
    :order/id #uuid "4eb5af84-1611-4d79-8c3b-4acf919e1e82"}) 
  [*]}]

currentoor19:02:57

but when i look at the indexes (shown in the gist) i see that this mutation is indeed in there

currentoor20:02:06

In the js console i see this error PathomRemote error: Error: Assert failed: Parse mutation attempted but no :mutate function supplied

souenzzo21:02:01

@currentoor you need to provide ::p/mutate pc/mutate-async or something like https://wilkerlucio.github.io/pathom/#_mutations_setup

☝️ 5
currentoor23:02:47

@souenzzo thanks, i did that and it works from the repl

currentoor23:02:22

(pc/defresolver print-receipt [{:keys [app-atom ast]} {:keys [firm order]}]
  {#_#_::pc/params [:firm :order]
   ::pc/output [:receipt-printer/success]}
  (util/spy firm order)
  (go-catch
    (let [controller-api ""
          response       (async/<! (http/post controller-api
                                     {:body              (transit-clj->str
                                                           {:firm firm :order order})
                                      :with-credentials? false}))]
      (util/spy :pp (transit-str->clj (:body response))))))

currentoor23:02:39

my parser now looks like this

(defn rest-parser
  "Create a REST parser. Make sure you've required all nses that define rest resolvers. The given app-atom will be available
  to all resolvers in `env` as `:app-atom`."
  [app-atom]
  (p/parallel-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-async
     ::p/plugins [(p/env-plugin {:app-atom app-atom})
                  (pc/connect-plugin {::pc/register (vec (vals @pathom-registry))})
                  p/error-handler-plugin
                  p/request-cache-plugin
                  (p/post-process-parser-plugin p/elide-not-found)]}))

currentoor23:02:07

and this works when i evaluate it in the repl

(comment
  (go-catch
    (util/spy (async/<! ((rest-parser) {}
                          '[(ucv.ui.receipt/print-receipt {})])))))

currentoor23:02:28

but for some reason triggering it from fulcro does doesn’t work

currentoor23:02:57

however, if i only change pc/defresolver to pc/defmutation then it works as expected