Fork me on GitHub
#pathom
<
2019-04-04
>
thheller11:04:47

are there any utilities to create and run transactions directly against the pathom parser (without fulcro or so, directly from background tasks? I still absolutely hate the use of lists and symbols in transactions 😞

thheller11:04:15

(defn create-request
  [{::env/keys [graph] :as ctx}]
  (let [tx-id
        `m/create

        query
        `[(~tx-id {})]

        order-id
        (-> (graph ctx query)
            (get tx-id)
            (get ::m/order-id))]

    ;; use order-id ...
    ))

thheller11:04:29

there has to be something better than this?

thheller11:04:02

I can easily abstract that myself and call something like (transact! env 'm/create {]) but was just wondering if there is something like that maybe?

wilkerlucio11:04:35

@thheller nothing from standard lib, mainly because was never a use case for me, so better to create your own wrapper since you want a concise way to call it 👍

thheller11:04:32

do you only use the graph API from fulcro? I sort of started using it everything and except for the somewhat clunky API I really like that

wilkerlucio12:04:17

@thheller what you mean use the graph api from fulcro?

thheller12:04:53

I mean fulcro like frontend that handles the db normalization

wilkerlucio12:04:09

ah, just read the only, currently yeah, but I keep feeling like it would be useful in more contexts

thheller12:04:18

vs. a script of sorts that just one query without any db normalization or so

wilkerlucio12:04:24

I was thinking making very trivial ways to create/run parsers

wilkerlucio12:04:55

you mean cluncky to call the parser?

thheller12:04:32

no calling the parser is easy. clunky in that I have to unwrap the results and stuff

thheller12:04:50

but its easy enough to handle this with simple helper fns

wilkerlucio12:04:33

for the parallel we need to do the channel read, for the sync one are you having to do some post processing too?

thheller12:04:31

not post processing, extracting the data (eg. get the tx-id in the example)

thheller12:04:56

its all fine

wilkerlucio12:04:22

cool, just out of curiosity, in which contexts are you using tha parser, like replacing regular logic in the program?

thheller12:04:31

mostly using the parser to answer UI queries/mutations

thheller12:04:40

but also for background tasks on the server directly

thheller12:04:40

I used to do straight db interop on the server but trying to do everything through the parser so its easier to trigger and monitor

wilkerlucio12:04:44

makes sense, for those usages I do the same, any operations are first implemented in the parser and then used from it.

wilkerlucio12:04:08

but I keep seeing these same patterns in my regular logic, I have some data, it maybe need a few steps to get the data I need, and I keep writing in the regular clojure style, which means I have to remember all the steps

wilkerlucio12:04:00

so I wonder what would look like if the parser was a more integral part of my code, delegating all the data transitions to it

thheller12:04:50

yeah treating the parser sort of like a REPL endpoint

thheller12:04:29

I never tried this but is it possible to call transactions in some context?

thheller12:04:30

[{[:foo/ident 123]
  [(foo/do-something {})]}]

thheller12:04:05

instead of [(foo/do-something {:id 123})] and having the tx load the ident?

wilkerlucio13:04:03

its technically valid, but I never tried doing it, I saw people doing similar things in GraphQL, I think its an interesting way to do things, could even operate on lists

wilkerlucio13:04:26

something like:

[{:customer/all-tags [(customer.tag/delete)]}]

wilkerlucio13:04:25

@thheller I did a quick run just for fun, it works already (kind of) 🙂

wilkerlucio13:04:44

(pc/defresolver people-resolver [env _]
  {::pc/output [{:people [:person/name]}]}
  {:people [{:person/name "Tom"}
            {:person/name "Tal"}
            {:person/name "Lita"}]})

(pc/defmutation do-something [env input]
  {}
  (println "DO SOMETHING" input (p/entity env))
  {})

wilkerlucio13:04:54

(parser {} [{:people [:person/name `(do-something)]}])

DO SOMETHING {} #:person{:name Tom}
DO SOMETHING {} #:person{:name Tal}
DO SOMETHING {} #:person{:name Lita}
=>
{:people [{:person/name "Tom", com.wsscode.pathom.playground/do-something {}}
          {:person/name "Tal", com.wsscode.pathom.playground/do-something {}}
          {:person/name "Lita", com.wsscode.pathom.playground/do-something {}}]}

👍 8
wilkerlucio13:04:38

there is no auto-link between the mutation params and input, you need to grab it from the entity, but that can be easely automated