Fork me on GitHub
#pathom
<
2020-08-15
>
Frank Henard20:08:04

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?

souenzzo21:08:50

@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

Frank Henard21:08:48

@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

souenzzo21:08:37

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.

lgessler21:08:04

@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?

souenzzo21:08:51

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

lgessler21:08:14

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?

souenzzo21:08:00

I do UI-related work

lgessler21:08:05

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?

lgessler21:08:16

declaring a fulcro mutation, i mean

souenzzo21:08:05

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

souenzzo21:08:25

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

souenzzo21:08:40

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

lgessler21:08:40

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?

lgessler21:08:50

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

souenzzo21:08:05

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

Frank Henard21:08:50

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])

souenzzo21:08:16

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

Frank Henard21:08:26

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}"

souenzzo21:08:05

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

👍 3
Frank Henard21:08:31

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]}))

Frank Henard21:08:48

double earmuffs are just pointing it out

souenzzo21:08:21

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

souenzzo21:08:45

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

Frank Henard21:08:15

That did it, thanks!

👍 3