Fork me on GitHub
#pathom
<
2019-07-31
>
tony.kay00:07:36

@wilkerlucio I was working with @dansudol on getting unions working with connect…it looks like pathom is seeing union queries as recursion limits instead of unions.

tony.kay00:07:08

whenever you get time, perhaps you could look…we’ll try to narrow it down further

wilkerlucio11:07:15

@tony.kay did you figure it out?

daniel.spaniel11:07:17

we never did Wilker, we were hoping you had an idea

wilkerlucio12:07:56

sure, can you send a minimal case of what you are trying so I can reproduce here?

daniel.spaniel13:07:02

its basically where you have an entity like company which has company/id and this company entity ( using datomic ) has a bunch of attributes, and lets say one of them is company/thing

daniel.spaniel13:07:57

let's say company/thing holds pointer to different types of entities like pots or pans

daniel.spaniel13:07:20

so if i wanted to query for companies and their thing i would say

daniel.spaniel13:07:24

{:company/id [:company/thing {:thing/pot [:color :name] :thing/pan [:size :name]}]}

daniel.spaniel13:07:13

because i want to get maybe a thing/pot ( with its attributes ) or thing/pan with different ones from the company/thing reference

daniel.spaniel13:07:13

with fulcro we found that we could compose this query , but pathom did not want to parse it

wilkerlucio13:07:47

@dansudol thanks, but I mean some full example trying to use with pathom and the results your are seeing

wilkerlucio13:07:28

I ask because I do use the union feature on a daily basis, so I wonder what you guys may be doing different

daniel.spaniel14:07:40

I not sure how to show more @wilkerlucio because the query we were doing was just exactly like I put above, and we never even got to the resolver stage, pathom just said "no thanks pops I not even looking at that query" with an exception with the "recursion limits" message

daniel.spaniel14:07:36

if what I posted above is not proper union query then let me know, or maybe you have something going on in your parser ? that is different than mine .. maybe our parser setup needs some special sauce ?

daniel.spaniel14:07:35

i can screen share if it is easier to see the full picture because i know just sending a query is kinda lame ( but not sure how else to show it)

wilkerlucio14:07:08

I mean na example creating a parser, the resolvers and triggering a query, so I can run it and see the same thing you are seeing

wilkerlucio14:07:26

a minimal reproduction also helps to drill down the potential problem

wilkerlucio14:07:55

let me write one real quick here

daniel.spaniel14:07:28

in our case it is easy because the resolvers never were touched .. the parser refused to run the query

wilkerlucio14:07:54

the query you sent me is the exact query you are issuing?

daniel.spaniel14:07:18

(defn get-parser []
  (let [real-parser (p/parallel-parser
                      {::p/mutate  pc/mutate-async
                       ::p/env     {::p/reader               [p/map-reader
                                                              pc/parallel-reader
                                                              pc/open-ident-reader
                                                              p/env-placeholder-reader]
                                    ::p/placeholder-prefixes #{">"}}
                       ::p/plugins [(pc/connect-plugin {::pc/register (vec (vals @pathom-registry))})
                                    (p/env-wrap-plugin
                                      (fn [{:keys [conn] :as env}]
                                        (cond-> (merge env {:config config})
                                          (not conn) (assoc :conn (get-conn)))))
                                    (preprocess-parser-plugin log-requests)
                                    (p/post-process-parser-plugin p/elide-not-found)
                                    p/request-cache-plugin
                                    p/error-handler-plugin
                                    p/trace-plugin]})
        ;; NOTE: Add -Dtrace to the server JVM to enable Fulcro Inspect query performance traces to the network tab!
        trace?      (not (nil? (System/getProperty "trace")))]
    (fn wrapped-parser [env tx]
      (async/<!! (real-parser env (if trace?
                                    (conj tx :com.wsscode.pathom/trace)
                                    tx))))))

(defstate parser :start (get-parser))

daniel.spaniel14:07:23

that is our parser setup

daniel.spaniel14:07:30

and we actualy tried something exactly like that ( that same form ) and what was nice ( so to speak ) was that we could do any union looking query ( even if the attributes were non existent like

daniel.spaniel14:07:05

{:company/id [:company/thing {:noodle [:w :blah] :rice [:a :b]}]}

daniel.spaniel14:07:31

if we ran anything that looked like union .. pathom would not parse it

wilkerlucio14:07:32

because a map is not a valid query

wilkerlucio14:07:36

queries must be vectors

wilkerlucio14:07:55

this can't be your root

daniel.spaniel14:07:19

so how does union work then because fulcro sets up a union query to look like that ( according to Tony ) and our exeriments yesterday

wilkerlucio14:07:31

that can be a join of something, but can't be the root

wilkerlucio14:07:52

eg: [{[:some/join 123] {:branch/a [...] :branch/b [...]}}]

daniel.spaniel14:07:21

sure sure .. you mean i should have typed

daniel.spaniel14:07:31

[{:company/id [:company/thing {:noodle [:w :blah] :rice [:a :b]}]}]

wilkerlucio14:07:54

that's wrong too

daniel.spaniel14:07:00

aaah .. yeah .. i see what you mean

daniel.spaniel14:07:29

but your assuming we know the join id ( which we don't )

wilkerlucio14:07:42

doesn't need to be an ident join

wilkerlucio14:07:43

but must be a join

wilkerlucio14:07:54

[{:named-join {:branch/a [...] :branch/b [...]}}]

daniel.spaniel14:07:06

right .. exactly

daniel.spaniel14:07:24

{:company/id [:company/thing {:noodle [:w :blah] :rice [:a :b]}]}

daniel.spaniel14:07:34

this is what we were doing minus the []

daniel.spaniel14:07:38

[{:company/id [:company/thing {:noodle [:w :blah] :rice [:a :b]}]}]

wilkerlucio14:07:42

I just got this example working here:

daniel.spaniel14:07:43

but assume the vector was there

wilkerlucio14:07:43

(quick-parser {::pc/register [(pc/resolver 'thing
                                  {::pc/output [{:get-thing [:a/id :b/id]}]}
                                  (fn [_ _]
                                    {:get-thing {:a/id "A"}}))

                                (pc/resolver 'a
                                  {::pc/output [:a/name]}
                                  (fn [_ _]
                                    {:a/name "A name"}))

                                (pc/resolver 'b
                                  {::pc/output [:b/name]}
                                  (fn [_ _]
                                    {:b/name "B name"}))]}
    '[{:get-thing
       {:a/id [:a/name]
        :b/id [:b/name]}}])

wilkerlucio14:07:02

quick parser is just a helper I use for testing, it generates a basic parser and run it

wilkerlucio14:07:06

in case you need for details:

wilkerlucio14:07:07

(defn quick-parser [{::p/keys  [env]
                        ::pc/keys [register]} query]
     (let [parser (p/parallel-parser {::p/env     (merge {::p/reader               [p/map-reader
                                                                                    pc/parallel-reader
                                                                                    pc/open-ident-reader
                                                                                    p/env-placeholder-reader]
                                                          ::p/placeholder-prefixes #{">"}}
                                                         env)
                                      ::p/mutate  pc/mutate-async
                                      ::p/plugins [(pc/connect-plugin {::pc/register register})
                                                   p/error-handler-plugin
                                                   p/request-cache-plugin
                                                   p/trace-plugin]})]
       (async/<!! (parser {} query))))

daniel.spaniel14:07:33

man .. this is neat parser trick

daniel.spaniel14:07:00

this is neat o .. i will try and let you know

wilkerlucio14:07:02

(noticed I changed the get-thing resolver across the runs to demonstrate the branch selection)

wilkerlucio14:07:10

what you find new there?

daniel.spaniel14:07:44

maybe you declared resolver like

{:get-thing [:a/id :b/id]}

daniel.spaniel14:07:07

so maybe pathom was able to recognize ?

wilkerlucio14:07:10

yeah, you need that, otherwise pathom can't know what to do (or how to auto-complete)

wilkerlucio14:07:45

there are other ways do it, its valid to also do in a flat way

daniel.spaniel14:07:54

i think we were missing that .. 80% sure

daniel.spaniel14:07:57

for that

::pc/output [{:get-thing [:a/id :b/id]}]

wilkerlucio14:07:31

cool, I hope that can make things move for you

wilkerlucio14:07:37

if not, lets keep on it 🙂

daniel.spaniel14:07:46

should i list all the attributes besides id ? like [:a/id :a/name :a/blah :b/id. .etc ]

daniel.spaniel14:07:01

for sure thanks W .. i will run this and check it

wilkerlucio14:07:22

list all the things you intend to return from this resolver

tony.kay15:07:04

The problem was with the output spec. I assumed it should look like a union, but your example cleared it up: a vector of possible IDs instead of a union query in ::pc/output

tony.kay15:07:23

makes sense, I just assumed the EQL notation was what was always used in output

wilkerlucio15:07:35

yeah, that's a good point to clarify in the docs, and we can probably support the union syntax as well, a simple impl could flat it out at definition time

wilkerlucio15:07:00

I'm taking notes on things I want to improve on the new docs (that are in progress as of now), that's surely a good one to add