Fork me on GitHub
#pathom
<
2020-05-24
>
markaddleman15:05:54

I'm having trouble with query parameters. My query is

'[{([:a "value"] {:with "params"})
                [:b :c]}]
Which, I believe matches the syntax for ident joins described at https://edn-query-language.org/eql/1.0.0/specification.html#_parameters The ast does not include the parameter map

markaddleman15:05:02

The ast for query

'[{[:a "value"]
              [(:b {:with "params"}) :c]}]
includes parameters but I don't think this syntax matches the spec. From what I understand, I also don't think this query makes sense

markaddleman15:05:14

i'm using pathom 2.3.0-alpha8

danvingo16:05:17

you can see how your queries get parsed with eql lib:

(eql/query->ast
    '[{([:a "value"] {:with "params"})
       [:b :c]}]
    )
=>
{:type :root,
 :children [{:type :join,
             :dispatch-key :a,
             :key [:a "value"],
             :params {:with "params"},
             :meta {:line 2, :column 8},
             :query [:b :c],
             :children [{:type :prop, :dispatch-key :b, :key :b} {:type :prop, :dispatch-key :c, :key :c}]}]}

markaddleman16:05:32

[{([:a "value"] {:with "params"})
                [:b :c]}]

markaddleman16:05:49

The resolver does not receive the params for that ^^ query

markaddleman16:05:08

That query's ast is

{:type :prop, :dispatch-key :b, :key :b}

danvingo16:05:00

ok I see. It will be hard to debug without your resolver code and maybe an example of invoking the parser and logging what the resolver's input and (:ast env) are

markaddleman16:05:35

Here's a repro case:

(pc/defresolver param-resolver [env _]
  {::pc/input  #{:a}
   ::pc/output [:b :c]}
  (clojure.pprint/pprint (:ast env))
  {:b 1, :c 2})

(def parser
  (p/parser
    {::p/env     {::p/reader               [p/map-reader
                                            pc/reader2
                                            pc/open-ident-reader
                                            p/env-placeholder-reader]
                  ::p/placeholder-prefixes #{">"}}
     ::p/mutate  pc/mutate-async
     ::p/plugins [(pc/connect-plugin {::pc/register [param-resolver]}) ; setup connect and use our resolvers
                  p/error-handler-plugin
                  p/trace-plugin]}))

(parser {} '[{([:a "value"] {:with "params"})
              [:b :c]}])

markaddleman16:05:57

I'm sure there's a pathom plugin to log the ast parsing but my pathom foo isn't up to it 🙂

danvingo17:05:55

ok I tried it out and I'm not seeing the params coming through to the resolver either. They are in the transaction though, before being processed by the resolver. I'm not sure why that is, but to get this working you can use the plugin in fulcro-rad to pass params as a top level key :query-params in the env: https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/pathom.clj#L108 Then pull them off any resolver using (:query-params env)

markaddleman17:05:44

Ok, so I'm a pathom newbie and I'm not using fulcro. From my understanding, I don't think the plugin from fulcro-rad has any dependency on fulcro - so that's good. Does it the ordering of the rad plugin matter relative to the connect plugin?

danvingo17:05:17

np, you can just copy paste it 🙂

danvingo17:05:03

i'm not sure about ordering with plugins, but i have it after the connect plugin