Fork me on GitHub
#fulcro
<
2021-06-20
>
wilkerlucio15:06:50

hello, I'm playing with the new Fulcro raw things, one thing I notice is that (rc/component-instance? (rc/nc [:foo])) returns false because hte result of rc/nc doens't contain fulcro$isComponent true, should it be there?

tony.kay17:06:34

actually no. nc is a component class, not an instance

tony.kay17:06:01

however, your question caused me to find a bug 😄

wilkerlucio00:06:45

hehe, having some fun with this, prob gonna do a post in the next week 🙂

tony.kay01:06:25

good to hear. Let me know any other thought

tony.kay17:06:23

Fulcro 3.5.0-RC2 is on clojars. Fixes a bug in nc where nested queries were not generated correctly.

Timofey Sitnikov20:06:31

I am working with Fulcro Template and on the server, there is a https://github.com/fulcrologic/fulcro-template/blob/a169b0ab50c0b390ac5efe24e307d371ec2f2bd3/src/main/app/model/session.clj#L32 , How can I execute it in REPL? I know that on the client side I can simply (comp/transact! SPA [(login {:username "john" :password "mysecurepassword"})])). How can I do that on the server side. It looks like on the client side the SPA contains the env, what do I use in place of SPA on the server side.

tony.kay01:06:21

It's no different. You still create a Fulcro app for using transact

tony.kay01:06:30

everything is CLJC

tony.kay01:06:56

so, if you're doing server-side rendering you can start the app headless, run your mutations, and then pull the state from the atom and send that to the client.

tony.kay01:06:38

If you mean you want to run the client mutation on the server for something else, what is that something else? Or do you mean you need to run a server-side mutation? If that's what you mean, and you're using pathom, you call the parser instead of transact.

Timofey Sitnikov02:06:17

@U0CKQ19AQ My question is probably a bit more elementary. I cannot figure out in Fulcro Template, if I try to run components/transact! what do I use for the app-or-comp argument as in the line below? https://github.com/fulcrologic/fulcro/blob/5277886b86ef3502342e9e1ff07dbedfe3793bdc/src/main/com/fulcrologic/fulcro/components.cljc#L792

tony.kay02:06:58

A Fulcro app

tony.kay02:06:18

you need to be more explicit about why you want to call transact on the server side

tony.kay02:06:40

If you mean you just want to cause that mutation to run AS IF you'd called it on the client, then you need to invoke your middleware parser on the transaction

tony.kay02:06:10

If that's what you want, then after starting the server, you can run:

Timofey Sitnikov02:06:14

For development in REPL, I would like to develop a server side mutation, make sure the output is what I expect it to be. So if I try to run a mutation in Fulcro Template on the client side, I do this:

(comp/transact! SPA [(login {:username "john" :password "mysecurepassword"})]))
On the client side, the app-ro-comp is defined here: https://github.com/fulcrologic/fulcro-template/blob/a169b0ab50c0b390ac5efe24e307d371ec2f2bd3/src/main/app/application.cljs#L13 It is the SPA variable, What do I use on the server side instead of SPA?

tony.kay02:06:35

(app.server-components.pathom/parser {} '[(app.model.session/login {...})])

tony.kay02:06:12

transact! does not run the server side stuff. The middleware receives it as a EDN and runs the parser

tony.kay02:06:20

so, calling the parser is probably what you're wanting?

tony.kay02:06:37

if so, define your own dev helper that just runs some transaction on the parser like above

Timofey Sitnikov02:06:06

Ahh, OK, yes I think I understand. Will try it.

tony.kay02:06:50

The map, of course, is the env that resolvers/mutations on server side get as env

tony.kay02:06:53

server mutations and resolvers in pathom 2.x are just maps, and one of the keys is the actual resolver fn, which you could also just directly call

tony.kay02:06:55

What I usually do is define the functionality in a regular function that can be easily unit tested, and then call that function from the resolver. That way you have an easier way to work with it outside of parsing.

❤️ 3
Timofey Sitnikov02:06:42

OK, this helps, I was wondering why the functionality was broken out, specially in Fulcro RAD Demo, seemed like extra files, but now I understand.

Björn Ebbinghaus14:06:07

(specification "Moderator priviliges"
  (let [parser (pathom/build-parser {} *conn*)
        parser-with-alex-session (partial parser {:ring/request {:session {:id #uuid"000aa0e2-e4d6-463d-ae7c-46765e13a31b"}}})]
    (behavior "Only a moderator can"
      (behavior "add new moderators"
        (assertions
          (parser-with-alex-session
            [`(process.mutations/add-moderator
                {::process/slug "test-decision"
                 ::user/email "Marc"})])
          =check=>
          (_/embeds?*
            {`process.mutations/add-moderator
             {:com.fulcrologic.rad.pathom/errors
              {:message "Need moderation role for this operation"}}}))))))

❤️ 3
3
Timofey Sitnikov11:06:26

It will take a few days to chew thorough this, but looks interesting. I am just starting to get into testing.