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?@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
@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
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.
@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?
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 ruleoh 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?
I do UI-related work
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?
declaring a fulcro mutation, i mean
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
It can also generate some cool analytics data: "90% of our users use add-comment-inline
, and just 10% add-comment-menu
"
As we have pc/alias
for resolvers, we can do for mutations (not sure if it exists ATM, but it CAN exists)
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
?
i think you're saying it'd be named something different but would still trigger the same remote somehow?
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
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])
Where you are looking to check if it's "registered" @ballpark?
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}"
You need to use ::pc/sym 'cledgers-fulcro.mutations-client/add-transaction
.
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]}))
double earmuffs are just pointing it out
and be sure to reload the namespaces/the http server (if needed)
But basead on what you send, the mutation names do not match.
That did it, thanks!