pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
ballpark 2020-08-15T20:27:04.019Z

Hello, I'm trying to hook up mutations on the server side, and it's not working. Here's my parser setup for server side:

(pathom-connect/connect-plugin
 {::pathom-connect/register
  [cledgers-fulcro.resolvers/resolvers
   cledgers-fulcro.mutations-server/mutations]})
In the browser, in Developer Tools/Network, on the request, in preview I'm getting:
["^ ", "~$cledgers-fulcro.mutations-client/add-transaction",…]
0: "^ "
1: "~$cledgers-fulcro.mutations-client/add-transaction"
2: ["^ ", "~:com.wsscode.pathom.core/reader-error",…]
0: "^ "
1: "~:com.wsscode.pathom.core/reader-error"
2: "class clojure.lang.ExceptionInfo: Mutation not found - {:mutation cledgers-fulcro.mutations-client/add-transaction}"
As you can see, the mutations namespace on client-side (cljs) is cledgers-fulcro.mutations-client and on server-side (clj) it's cledgers-fulcro.mutations-server. Is it ok to have them named differently?

souenzzo 2020-08-15T21:08:50.020400Z

@ballpark cledgers-fulcro.mutations-client/add-transaction is a pc/defmutation ? I usually use different namespaces for client and server mutations. My client mutations I keep next to defsc's

ballpark 2020-08-15T21:14:48.022200Z

@souenzzo, Thanks for looking at this! No cledgers-fulcro.mutations-client/add-transaction is a com.fulcrologic.fulcro.mutations/defmutation cledgers-fulcro.mutations-server/add-transaction is a com.wsscode.pathom.connect/defmutation

souenzzo 2020-08-15T21:17:37.024700Z

i usually do something like my-app.entity/operation << clj only, pc/defmutation here my-app.client/ui* << cljs ony, fm/defmutation referencing the full-symbol * my code organization of UI's usually a mess. I'm still working on it.

lgessler 2020-08-15T21:28:04.026Z

@souenzzo how do you handle full-stack mutations? sounds like you're saying you transform the ast in the client mutations (remote ...) section to point at the pc mutation?

souenzzo 2020-08-15T21:31:51.028600Z

No no. Mutations don't need to live in the symbol's namespace You can use app.entity/operation << mutation name app/server.clj << server

(pc/defmutation ...
  {::pc/sym 'app.entity/operation}
  ...)
app/client.cljs << client
(fm/defmutation app.entity/operation
  ...)
I use like that. Sometimes the server part matches the symbol name with the current namespace. But it's not a rule

lgessler 2020-08-15T21:39:14.029600Z

oh interesting... but then in your client-side mutation, do you also do UI-related work in there or do you keep that in a separate mutation?

souenzzo 2020-08-15T21:40:00.030300Z

I do UI-related work

lgessler 2020-08-15T21:40:05.030500Z

i guess i'm anticipating that if you ever want to carry out app.entity/operation in two different UI components i'm not sure if doing that more than once would be ok?

lgessler 2020-08-15T21:40:16.030700Z

declaring a fulcro mutation, i mean

souenzzo 2020-08-15T21:42:05.032Z

I already "duplicate" a mutation, op-a op-b because in client are 2 distinct operations but in server, both do the same thing. It's not common

souenzzo 2020-08-15T21:43:25.033300Z

It can also generate some cool analytics data: "90% of our users use add-comment-inline, and just 10% add-comment-menu"

souenzzo 2020-08-15T21:44:40.033800Z

As we have pc/alias for resolvers, we can do for mutations (not sure if it exists ATM, but it CAN exists)

lgessler 2020-08-15T21:46:40.035300Z

hm ok, so if we had another place in the client app/client/my-widget.cljs what would the mutation look like if we wanted it to also trigger a remote app.entity/operation?

lgessler 2020-08-15T21:46:50.035600Z

i think you're saying it'd be named something different but would still trigger the same remote somehow?

souenzzo 2020-08-15T21:49:05.037800Z

My "mindset" is: the client send what it needs, server do what need to be done. When I'm developing the frontend, I don't care if the attribute/mutation exisist, i just "request" it. Then I go to backend and implement what the client needs It let frontend simpler and keep all complexity on backend

ballpark 2020-08-15T21:49:50.038600Z

Here's my mutations-server. I added ::pathom-connect/sym 'cledgers-fulcro.mutatinos-server/add-transaction, but it still doesn't appear to be registered.

(ns cledgers-fulcro.mutations-server
  (:require [clojure.pprint :as pp]
            [com.wsscode.pathom.connect :as pathom-connect]))

(pathom-connect/defmutation add-transaction [env params]
     {::pathom-connect/sym 'cledgers-fulcro.mutations-server/add-transaction}
     (let [_ (pp/pprint {:mutations-server {:env env
                                            :params params}})]
       {:cledgers-fulcro.entities.transaction/id 99}))

(def mutations [add-transaction])

souenzzo 2020-08-15T21:51:16.039300Z

Where you are looking to check if it's "registered" @ballpark?

ballpark 2020-08-15T21:52:26.040300Z

It's not hitting the pprint, I'm still getting this response

["^ ", "~$cledgers-fulcro.mutations-client/add-transaction",…]
0: "^ "
1: "~$cledgers-fulcro.mutations-client/add-transaction"
2: ["^ ", "~:com.wsscode.pathom.core/reader-error",…]
0: "^ "
1: "~:com.wsscode.pathom.core/reader-error"
2: "class clojure.lang.ExceptionInfo: Mutation not found - {:mutation cledgers-fulcro.mutations-client/add-transaction}"

souenzzo 2020-08-15T21:53:05.041Z

You need to use ::pc/sym 'cledgers-fulcro.mutations-client/add-transaction.

👍 1
ballpark 2020-08-15T21:53:31.041300Z

Here's where I'm "registering" 🙂 it:

(def pathom-parser
  (pathom/parser {::pathom/env {::pathom/reader [pathom/map-reader
                                                 pathom-connect/reader2
                                                 pathom-connect/ident-reader
                                                 pathom-connect/index-reader]
                                ::pathom-connect/mutation-join-globals [:tempids]}
                  ::pathom/mutate pathom-connect/mutate
                  ::pathom/plugins [(pathom-connect/connect-plugin
                                     {::pathom-connect/register
                                      [cledgers-fulcro.resolvers/resolvers
                                       **cledgers-fulcro.mutations-server/mutations**]})
                                    pathom/error-handler-plugin]}))

ballpark 2020-08-15T21:53:48.041700Z

double earmuffs are just pointing it out

souenzzo 2020-08-15T21:54:21.042100Z

and be sure to reload the namespaces/the http server (if needed)

souenzzo 2020-08-15T21:54:45.042500Z

But basead on what you send, the mutation names do not match.

ballpark 2020-08-15T21:56:15.042700Z

That did it, thanks!

👍 1