Last active
May 12, 2021 14:49
-
-
Save jmayaalv/b8cb9b8a6e465ef591773daab0829534 to your computer and use it in GitHub Desktop.
batch reosolvers bug?
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
(def db {:a {1 {:a/id 1 :a/code "a-1"} | |
2 {:a/id 2 :a/code "a-2"}} | |
:f {1 {:f/id 1 :f/code "f-1"} | |
2 {:f/id 2 :f/code "f-2"}} | |
:b {1 [{:f/id 1}]} | |
:c {1 [{:f/id 2}]}}) | |
(pco/defresolver a [input] | |
{::pco/input [:a/id] | |
::pco/output [:a/id :a/code] | |
::pco/batch? true} | |
(mapv #(get-in db [:a (:a/id %)]) input)) | |
(pco/defresolver f [input] | |
{::pco/input [:f/id] | |
::pco/output [:f/id :f/code]} | |
(get-in db [:f (:f/id input)])) | |
;; this is the batched version of the resolver above | |
(pco/defresolver f' [input] | |
{::pco/input [:f/id] | |
::pco/output [:f/id :f/code] | |
::pco/batch? true} | |
(mapv #(get-in db [:f (:f/id %)]) input)) | |
(pco/defresolver b [input] | |
{::pco/input [:a/id] | |
::pco/output [{:a/b [:f/id]}] | |
::pco/batch? true} | |
(mapv (fn [{:a/keys [id]}] | |
{:a/b (get-in db [:b id])}) input)) | |
(pco/defresolver c [input] | |
{::pco/input [:a/id] | |
::pco/output [{:a/c [:f/id]}] | |
::pco/batch? true} | |
(mapv (fn [{:a/keys [id]}] | |
{:a/c (get-in db [:c id])}) input)) | |
;; non batched f resolver | |
(p.eql/process (pci/register [a f b c]) | |
[{[:a/id 1] [:a/code {:a/b [:f/id :f/code]} {:a/c [:f/id :f/code]}]}]) | |
;; => output: | |
;; {[:a/id 1] | |
;; {:a/code "a-1" | |
;; :a/b [{:f/id 1 :f/code "f-1"}] | |
;; :a/c [{:f/id 2 :f/code "f-2"}]}} | |
;; batched f resolver | |
(p.eql/process (pci/register [a f' b c]) | |
[{[:a/id 1] [:a/code {:a/b [:f/id :f/code]} {:a/c [:f/id :f/code]}]}]) | |
;; => output: | |
;; {[:a/id 1] | |
;; {:a/code "a-1" | |
;; :a/b [{:f/id 1 :f/code "f-1"}] | |
;; :a/c [{:f/id 2}]}} ;; notice the missing :f/code here | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment