-
-
Save myguidingstar/53f2b552e2a5dca664b5df0d4780f8c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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]}]}])) |
Author
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.
Author
the code use [com.wsscode/pathom "2.3.0-alpha5"], btw
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
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 isnil