Fork me on GitHub
#pathom
<
2022-08-04
>
sheluchin12:08:54

Is it okay to nest mutations? I'm presuming no, but thought I'd ask anyhow.

souenzzo12:08:12

pathom engine should be able to process.

souenzzo12:08:38

but i don't think that it make sense for EQL's. I would classify as a "undefined behavior"

sheluchin12:08:46

Is it bad form, even if technically possible? Ah, got it. Thought so. So if you want to run a bunch of mutations in series you just make a regular function that just calls p.eql/process on different mutation vectors or just use one vector with multiple mutations if there is no logic to perform between mutations, right?

souenzzo12:08:04

something like [(batch-mutation {:mutations [(create-user {}) (login-user {})]})] ?

sheluchin12:08:02

I was thinking either:

(p.eql/process env [(create-user {}) (login-user {})])
or
(p.eql/process env [(create-user {})])
;; use result from first mutation somehow
(p.eql/process env [(login-user {})])

souenzzo12:08:54

I would do a single [(create-user-and-login {})] mutation

sheluchin12:08:41

Why? Then you lose the ability to use those components separately.

souenzzo12:08:11

you can keep the 3 operations

sheluchin12:08:53

If you do that you duplicate the logic from create-user and login-user, no?

souenzzo12:08:00

you can reuse at funciton level. What the frontend will do if [(create-user) (login)] fail? it will test to see if it failed at create-user or at login ? then decide if will repeat both of just one?

souenzzo12:08:10

create-user-and-login can rollback the user creation if the login fail.

sheluchin12:08:46

I see your point. Hmm, defmutation is just a wrapper around defresolver, right? In that case, I guess mutations can be called as regular functions the same way resolvers can? https://pathom3.wsscode.com/docs/resolvers/#invoking-resolvers

souenzzo12:08:31

being on the server, you can even do things like this:

(defmutation create-user-and-login [ctx params]
  (let []
    (sql/with-rollback
      (p.eql/process ctx `[(create-user ~params)])
      (p.eql/process ctx `[(login ~params)]))))
But I agree with you, that calling the mutation directly should be better, to avoid huge stacktraces.

gratitude-thank-you 1
sheluchin12:08:33

Yes, I guess if you use the mutation as a function you skip Pathom's tree traversal and accompanying trace in case of an error. Good point.

wilkerlucio14:08:46

one thing to consider if you call the mutation directly is that you also dont get the mutation join processing (if you have a query to run over the mutation response)

sheluchin14:08:10

Thanks @U066U8JQJ, I hadn't considered that. Seems like a fair tradeoff to make in some cases. Good set of options here.

wilkerlucio14:08:33

yeah, calling the mutation directly is really just like calling a regular fn, with a fixed interface (`env params`)

wilkerlucio14:08:46

its a convenience, and if your usage makes sense, go for it 🙂