Skip to content

Instantly share code, notes, and snippets.

@myguidingstar
Last active March 27, 2020 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myguidingstar/53f2b552e2a5dca664b5df0d4780f8c7 to your computer and use it in GitHub Desktop.
Save myguidingstar/53f2b552e2a5dca664b5df0d4780f8c7 to your computer and use it in GitHub Desktop.
(defn compute-indexes [resolver-sym inputs-outputs]
(reduce (fn [acc x] (pc/add acc resolver-sym x))
{}
inputs-outputs))
(require '[com.wsscode.pathom.connect.planner :as pcp])
(let [the-empty-item nil
the-parser
(p/parser
{::p/env {::p/reader [p/map-reader
pc/reader3
pc/open-ident-reader
p/env-placeholder-reader]
:o :ro
::p/placeholder-prefixes #{">"}}
::p/mutate pc/mutate
::p/plugins [(pc/connect-plugin {::pc/register []})
{::p/intercept-output (fn [env v] v)
::p/wrap-parser2
(fn [parser {::p/keys [plugins]}]
(let [resolver `my-resolver
indexes (compute-indexes `my-resolver
(let [y-out [:y/m :y/n]
x-out [:x/id :x/t :x/u]
x-out-full (conj x-out {:x/y y-out})]
[{::pc/input #{}
::pc/output [{:a/x x-out-full}]}
{::pc/input #{:x/y}
::pc/output y-out}
{::pc/input #{:x/id}
::pc/output x-out-full}]))
my-resolve (fn [env _]
(if (contains? (-> env ::pcp/node ::pcp/input)
:x/id)
#:x{:x/y [the-empty-item
#:y{:m 7 :n 8}]}
{:a/x #:x{:id 0 :t 1 :u 2}}))
all-indexes
(merge
(select-keys indexes [::pc/index-oir ::pc/index-io ::pc/idents])
{::pc/index-resolvers
{resolver {::pc/sym resolver
::pc/cache? false
::pc/dynamic-resolver? true
;; ::pc/provides my-provides
::pc/output []
::pc/resolve my-resolve}}
::pc/autocomplete-ignore
#{}})
idx-atoms (keep ::pc/indexes plugins)]
(doseq [idx* idx-atoms]
(swap! idx* pc/merge-indexes all-indexes))
(fn [{::keys [] :as env} tx]
(parser env tx))))}
p/error-handler-plugin
p/trace-plugin]})]
(the-parser {}
[{:a/x [:x/id :x/t {:>/go [:x/u]} {:x/y [:y/m :y/n]}]}]))
@myguidingstar
Copy link
Author

the above returns #:a{:x {:x/id 0, :x/t 1, :>/go #:x{:u 2}, :x/y []}}. Notice :x/y []. The whole sequence become empty because the first item is nil

@myguidingstar
Copy link
Author

also, if I change the-empty-item from nil to {}, the result is #:a{:x {:x/id 0, :x/t 1, :>/go #:x{:u 2}, :x/y [#:y{:m :com.wsscode.pathom.core/not-found, :n :com.wsscode.pathom.core/not-found} #:y{:m 7, :n 8}]}}. I don't really like those not-founds here and prefer an empty map instead.

@myguidingstar
Copy link
Author

the code use [com.wsscode/pathom "2.3.0-alpha5"], btw

@wilkerlucio
Copy link

just in case, can you please try on the latest SHA on the query-planner branch? I've been doing some fixes this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment