Created
July 5, 2024 03:04
-
-
Save CalebMacdonaldBlack/16eaac6a0133b0ee16a5643e9995a83a to your computer and use it in GitHub Desktop.
This file contains 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
(ns io.erical.sandbox.pathom.bshep | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container0" :things "thing0"] | |
[:db/add "thing0" :title "Thing 0"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container0" :containers "container2"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container1" :things "thing1"] | |
[:db/add "container1" :things "thing2"] | |
[:db/add "thing1" :title "Thing 1"] | |
[:db/add "thing2" :title "Thing 2"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container2" :things "thing3"] | |
[:db/add "container2" :things "thing4"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "thing3" :title "Thing 3"] | |
[:db/add "thing4" :title "Thing 4"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container3" :things "thing5"] | |
[:db/add "container3" :things "thing6"] | |
[:db/add "thing5" :title "Thing 5"] | |
[:db/add "thing6" :title "Thing 6"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}]} | |
;::pco/batch? true} | |
(fn [{:keys [db]} input] | |
(prn 'id>containers | |
(debug-eid->tempid input)) | |
;(get input :title)) | |
;(mapv (comp (set/map-invert tempids) :db/id) items)) | |
;(prn | |
; (into [] | |
; (comp | |
; (map :db/id) | |
; (map (partial d/pull db [:containers :title])) | |
; (map #(update % :containers | |
; (fn [c] | |
; (if (empty? c) ::pco/unknown-value c))))) | |
; items)) | |
(d/pull db [{:containers [:db/id]}] | |
(get input :db/id)))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details | |
(mapv (comp (set/map-invert tempids) :db/id) items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-containers | |
{::pco/input [:db/id :title (pco/? :flat-containers) {:containers '...}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [{:keys [db]} input] | |
(prn '>flat-containers | |
(:title input) | |
{:flat-containers | |
(loop [results [] | |
[head & rest] [input]] | |
(if (nil? head) | |
results | |
(let [containers (get head :containers []) | |
id (get head :db/id)] | |
(recur | |
(conj results {:db/id id}) | |
(into containers rest)))))}) | |
{:flat-containers | |
(loop [results [] | |
[head & rest] [input]] | |
(if (nil? head) | |
results | |
(let [containers (get head :containers []) | |
id (get head :db/id)] | |
(recur | |
(conj results {:db/id id}) | |
(into containers rest)))))}))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
;(is (= {:containers [{:title "Container 1"} | |
; {:title "Container 2"}]} | |
; (p.eql/process env root-container [:title :db/id {:containers '...}]))) | |
;(is (= {} | |
; (p.eql/process env root-container [(pco/? :flat-containers)]))) | |
;(is (= {} | |
; (p.eql/process env root-container [:flat-containers]))) | |
(is (= {} | |
(p.eql/process | |
env | |
root-container | |
[(pco/? {:flat-containers [:title]})]))))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep2 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container0" :things "thing0"] | |
[:db/add "thing0" :title "Thing 0"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container0" :containers "container2"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container1" :things "thing1"] | |
[:db/add "container1" :things "thing2"] | |
[:db/add "thing1" :title "Thing 1"] | |
[:db/add "thing2" :title "Thing 2"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container2" :things "thing3"] | |
[:db/add "container2" :things "thing4"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "thing3" :title "Thing 3"] | |
[:db/add "thing4" :title "Thing 4"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container3" :things "thing5"] | |
[:db/add "container3" :things "thing6"] | |
[:db/add "thing5" :title "Thing 5"] | |
[:db/add "thing6" :title "Thing 6"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
#_(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}]} | |
;::pco/batch? true} | |
(fn [{:keys [db]} input] | |
(prn 'id>containers | |
(debug-eid->tempid input)) | |
;(get input :title)) | |
;(mapv (comp (set/map-invert tempids) :db/id) items)) | |
;(prn | |
; (into [] | |
; (comp | |
; (map :db/id) | |
; (map (partial d/pull db [:containers :title])) | |
; (map #(update % :containers | |
; (fn [c] | |
; (if (empty? c) ::pco/unknown-value c))))) | |
; items)) | |
(d/pull db [{:containers [:db/id]}] | |
(get input :db/id)))) | |
#_(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details | |
(mapv (comp (set/map-invert tempids) :db/id) items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-containers2 | |
{::pco/input [{:containers [:db/id]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(prn '>flat-containers2 | |
{:flat-containers | |
(mapv #(select-keys % [:db/id]) | |
(get input :containers))}) | |
{:flat-containers | |
(mapv #(select-keys % [:db/id]) | |
(get input :containers))})) | |
(pco/resolver '>flat-containers3 | |
{::pco/input [{:containers [{:flat-containers [:db/id]}]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(prn '>flat-containers3 | |
{:flat-containers | |
(into [] | |
(mapcat :flat-containers) | |
(get input :containers))}) | |
{:flat-containers | |
(into [] | |
(mapcat :flat-containers) | |
(get input :containers))})) | |
(pco/resolver '>flat-containers4 | |
{::pco/input [{:containers [{:flat-containers [:db/id]}]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(prn '>flat-containers4 | |
{:flat-containers | |
(into [] | |
(mapcat :flat-containers) | |
(get input :containers))}) | |
{:flat-containers | |
(into [] | |
(mapcat :flat-containers) | |
(get input :containers))})) | |
#_(pco/resolver '>flat-containers | |
{::pco/input [:db/id :title {:containers '...}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [{:keys [db]} input] | |
(prn '>flat-containers | |
(:title input) | |
{:flat-containers | |
(loop [results [] | |
[head & rest] [input]] | |
(if (nil? head) | |
results | |
(let [containers (get head :containers []) | |
id (get head :db/id)] | |
(recur | |
(conj results {:db/id id}) | |
(into containers rest)))))}) | |
{:flat-containers | |
(loop [results [] | |
[head & rest] [input]] | |
(if (nil? head) | |
results | |
(let [containers (get head :containers []) | |
id (get head :db/id)] | |
(recur | |
(conj results {:db/id id}) | |
(into containers rest)))))}))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
;(is (= {:containers [{:title "Container 1"} | |
; {:title "Container 2"}]} | |
; (p.eql/process env root-container [:title :db/id {:containers '...}]))) | |
;(is (= {} | |
; (p.eql/process env root-container [(pco/? :flat-containers)]))) | |
;(is (= {} | |
; (p.eql/process env root-container [:flat-containers]))) | |
(is (= {} | |
(p.eql/process | |
env | |
{:containers [ | |
{:db/id 1 | |
:title "Container 1"} | |
{:containers [{:db/id 3 | |
:title "Container 3"}] | |
:db/id 2 | |
:title "Container 2"}] | |
:db/id 0 | |
:title "Container 0"} | |
[(pco/? :flat-containers)]))) | |
(is (= {} | |
(let [input {:containers [{:flat-containers [{:db/id 1}]} | |
{:flat-containers [{:db/id 2}]}]}] | |
{:flat-containers | |
(into [] | |
(mapcat :flat-containers) | |
(get input :containers))}))))) | |
; | |
;(is (= {} | |
; (p.eql/process | |
; env | |
; root-container | |
; [(pco/? {:flat-containers [:title]})]))))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep3 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.rpl.specter :as sp] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container1" :containers "container2"] | |
[:db/add "container2" :containers "container3"]] | |
;[:db/add "container0" :things "thing0"] | |
;[:db/add "thing0" :title "Thing 0"] | |
;[:db/add "container0" :containers "container2"]] | |
;[:db/add "container1" :title "Container 1"]] | |
;[:db/add "container1" :things "thing1"] | |
;[:db/add "container1" :things "thing2"] | |
; | |
;[:db/add "thing1" :title "Thing 1"] | |
;[:db/add "thing2" :title "Thing 2"] | |
; | |
;[:db/add "container2" :title "Container 2"] | |
;[:db/add "container2" :things "thing3"] | |
;[:db/add "container2" :things "thing4"] | |
;[:db/add "container2" :containers "container3"] | |
; | |
;[:db/add "thing3" :title "Thing 3"] | |
;[:db/add "thing4" :title "Thing 4"] | |
; | |
;[:db/add "container3" :title "Container 3"] | |
;[:db/add "container3" :things "thing5"] | |
;[:db/add "container3" :things "thing6"] | |
; | |
;[:db/add "thing5" :title "Thing 5"] | |
;[:db/add "thing6" :title "Thing 6"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}]} | |
;::pco/batch? true} | |
(fn [{:keys [db]} input] | |
(prn 'id>containers | |
(debug-eid->tempid input)) | |
;(get input :title)) | |
;(mapv (comp (set/map-invert tempids) :db/id) items)) | |
;(prn | |
; (into [] | |
; (comp | |
; (map :db/id) | |
; (map (partial d/pull db [:containers :title])) | |
; (map #(update % :containers | |
; (fn [c] | |
; (if (empty? c) ::pco/unknown-value c))))) | |
; items)) | |
(d/pull db [{:containers [:db/id]}] | |
(get input :db/id)))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details | |
(mapv (comp (set/map-invert tempids) :db/id) items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-containers | |
{::pco/input [:db/id :title {:containers '...}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(let [output {:flat-containers | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
input)}] | |
(prn '>flat-containers | |
{:input input | |
:output output}) | |
output)))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
;(is (= {:containers [{:title "Container 1"} | |
; {:title "Container 2"}]} | |
; (p.eql/process env root-container [:title :db/id {:containers '...}]))) | |
;(is (= {} | |
; (p.eql/process env root-container [(pco/? :flat-containers)]))) | |
;(is (= {} | |
; (p.eql/process env root-container [:flat-containers]))) | |
(is (= {:flat-containers [{:title "Container 0"} | |
{:title "Container 1"} | |
{:title "Container 2"} | |
{:title "Container 3"}]} | |
(p.eql/process | |
env | |
root-container | |
;[{:flat-containers [:title]}] | |
[(pco/? {:flat-containers [:title]})]))))) | |
(deftest sdf-test | |
(is (= {} | |
(let [input {}] | |
(sp/select | |
[:containers | |
sp/ALL | |
:containers | |
sp/ALL | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]}))))) | |
(deftest sdf2-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]})))) | |
(deftest sdf3-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]}]})))) | |
(deftest sdf4-test | |
(is (= [{:db/id 0} | |
{:db/id 1} | |
{:db/id 2} | |
{:db/id 3} | |
{:db/id 4} | |
{:db/id 5} | |
{:db/id 6}] | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]} | |
{:db/id 6}]})))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep4 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.rpl.specter :as sp] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container4" :title "Container 4"] | |
[:db/add "container5" :title "Container 5"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container1" :containers "container2"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "container3" :containers "container4"] | |
[:db/add "container4" :containers "container5"]] | |
;[:db/add "container0" :things "thing0"] | |
;[:db/add "thing0" :title "Thing 0"] | |
;[:db/add "container0" :containers "container2"]] | |
;[:db/add "container1" :title "Container 1"]] | |
;[:db/add "container1" :things "thing1"] | |
;[:db/add "container1" :things "thing2"] | |
; | |
;[:db/add "thing1" :title "Thing 1"] | |
;[:db/add "thing2" :title "Thing 2"] | |
; | |
;[:db/add "container2" :title "Container 2"] | |
;[:db/add "container2" :things "thing3"] | |
;[:db/add "container2" :things "thing4"] | |
;[:db/add "container2" :containers "container3"] | |
; | |
;[:db/add "thing3" :title "Thing 3"] | |
;[:db/add "thing4" :title "Thing 4"] | |
; | |
;[:db/add "container3" :title "Container 3"] | |
;[:db/add "container3" :things "thing5"] | |
;[:db/add "container3" :things "thing6"] | |
; | |
;[:db/add "thing5" :title "Thing 5"] | |
;[:db/add "thing6" :title "Thing 6"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}] | |
::pco/batch? true} | |
(fn [{:keys [db]} inputs] | |
(prn 'id>containers | |
(mapv debug-eid->tempid inputs)) | |
(let [outputs | |
(vec | |
(sp/select | |
[sp/ALL | |
:db/id | |
(sp/view (partial d/pull db [{:containers [:db/id]}])) | |
(sp/if-path nil? | |
(sp/view (constantly {:containers ::pco/unknown-value})) | |
sp/STAY)] | |
inputs))] | |
(prn | |
{:inputs inputs :outputs outputs}) | |
outputs))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details | |
(mapv (comp (set/map-invert tempids) :db/id) items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>root? | |
{::pco/input [:db/id] | |
::pco/output [:root?]} | |
(fn [_env input] | |
{:root? (or (= (:db/id input) 1) | |
::pco/unknown-value)})) | |
(pco/resolver '>flat-containers | |
{::pco/input [:db/id :title :root? {:containers [:db/id :title {:containers}]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(let [ | |
;output {:flat-containers | |
; (sp/select | |
; [(sp/recursive-path [] p | |
; (sp/stay-then-continue :containers sp/ALL p)) | |
; (sp/submap [:db/id])] | |
; input)} | |
output {:flat-containers | |
(sp/select | |
[:containers | |
sp/ALL | |
(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
input)}] | |
(prn '>flat-containers | |
{:input input | |
:output output}) | |
output)))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
;(is (= {:containers [{:title "Container 1"} | |
; {:title "Container 2"}]} | |
; (p.eql/process env root-container [:title :db/id {:containers '...}]))) | |
;(is (= {} | |
; (p.eql/process env root-container [(pco/? :flat-containers)]))) | |
;(is (= {} | |
; (p.eql/process env root-container [:flat-containers]))) | |
(is (= {:flat-containers [{:title "Container 0"} | |
{:title "Container 1"} | |
{:title "Container 2"} | |
{:title "Container 3"} | |
{:title "Container 4"} | |
{:title "Container 5"}]} | |
(p.eql/process | |
env | |
root-container | |
[:root? {:flat-containers [:db/id :title]}]))))) | |
(deftest sdf-test | |
(is (= {} | |
(let [input {}] | |
(sp/select | |
[:containers | |
sp/ALL | |
:containers | |
sp/ALL | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]}))))) | |
(deftest sdf2-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]})))) | |
(deftest sdf3-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]}]})))) | |
(deftest sdf4-test | |
(is (= [{:db/id 0} | |
{:db/id 1} | |
{:db/id 2} | |
{:db/id 3} | |
{:db/id 4} | |
{:db/id 5} | |
{:db/id 6}] | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]} | |
{:db/id 6}]})))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep5 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.rpl.specter :as sp] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container4" :title "Container 4"] | |
[:db/add "container5" :title "Container 5"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container1" :containers "container2"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "container2" :containers "container4"] | |
[:db/add "container2" :containers "container5"]] | |
;[:db/add "container0" :things "thing0"] | |
;[:db/add "thing0" :title "Thing 0"] | |
;[:db/add "container0" :containers "container2"]] | |
;[:db/add "container1" :title "Container 1"]] | |
;[:db/add "container1" :things "thing1"] | |
;[:db/add "container1" :things "thing2"] | |
; | |
;[:db/add "thing1" :title "Thing 1"] | |
;[:db/add "thing2" :title "Thing 2"] | |
; | |
;[:db/add "container2" :title "Container 2"] | |
;[:db/add "container2" :things "thing3"] | |
;[:db/add "container2" :things "thing4"] | |
;[:db/add "container2" :containers "container3"] | |
; | |
;[:db/add "thing3" :title "Thing 3"] | |
;[:db/add "thing4" :title "Thing 4"] | |
; | |
;[:db/add "container3" :title "Container 3"] | |
;[:db/add "container3" :things "thing5"] | |
;[:db/add "container3" :things "thing6"] | |
; | |
;[:db/add "thing5" :title "Thing 5"] | |
;[:db/add "thing6" :title "Thing 6"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}] | |
::pco/batch? true} | |
(fn [{:keys [db]} inputs] | |
(prn 'id>containers | |
(mapv debug-eid->tempid inputs)) | |
(let [outputs | |
(vec | |
(sp/select | |
[sp/ALL | |
:db/id | |
(sp/view (partial d/pull db [{:containers [:db/id]}])) | |
(sp/if-path nil? | |
(sp/view (constantly {:containers ::pco/unknown-value})) | |
sp/STAY)] | |
inputs))] | |
(prn | |
{:inputs inputs :outputs outputs}) | |
outputs))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details | |
(mapv (comp (set/map-invert tempids) :db/id) items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-containers2 | |
{::pco/input [:db/id (pco/? {:containers [:db/id]})] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env {:keys [db/id containers]}] | |
(prn '>flat-containers2) | |
{:flat-containers | |
(into [{:db/id id}] containers)})) | |
(pco/resolver '>flat-containers3 | |
{::pco/input [:db/id {:containers [{:flat-containers [:db/id]}]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env {:keys [db/id containers]}] | |
(prn '>flat-containers3) | |
{:flat-containers | |
(into [{:db/id id}] (mapcat :flat-containers containers))})) | |
#_(pco/resolver '>flat-containers | |
{::pco/input [:db/id :title {:containers [:db/id :title]}] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [_env input] | |
(let [ | |
;output {:flat-containers | |
; (sp/select | |
; [(sp/recursive-path [] p | |
; (sp/stay-then-continue :containers sp/ALL p)) | |
; (sp/submap [:db/id])] | |
; input)} | |
output {:flat-containers | |
(sp/select | |
[:containers | |
sp/ALL | |
(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
input)}] | |
(prn '>flat-containers | |
{:input input | |
:output output}) | |
output)))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
;(is (= {:containers [{:title "Container 1"} | |
; {:title "Container 2"}]} | |
; (p.eql/process env root-container [:title :db/id {:containers '...}]))) | |
;(is (= {} | |
; (p.eql/process env root-container [(pco/? :flat-containers)]))) | |
;(is (= {} | |
; (p.eql/process env root-container [:flat-containers]))) | |
(is (= {:flat-containers [{:title "Container 0"} | |
{:title "Container 1"} | |
{:title "Container 2"} | |
{:title "Container 3"} | |
{:title "Container 4"} | |
{:title "Container 5"}]} | |
(p.eql/process | |
env | |
root-container | |
[{:flat-containers [:title]}]))))) | |
(deftest sdf-test | |
(is (= {} | |
(let [input {}] | |
(sp/select | |
[:containers | |
sp/ALL | |
:containers | |
sp/ALL | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]}))))) | |
(deftest sdf2-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers []}]}]})))) | |
(deftest sdf3-test | |
(is (= {} | |
(sp/select | |
[(sp/recursive-path [] p | |
[:containers | |
sp/ALL | |
(sp/multi-path | |
(sp/submap [:db/id]) | |
p)])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]}]})))) | |
(deftest sdf4-test | |
(is (= [{:db/id 0} | |
{:db/id 1} | |
{:db/id 2} | |
{:db/id 3} | |
{:db/id 4} | |
{:db/id 5} | |
{:db/id 6}] | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
{:db/id 0 | |
:containers | |
[{:db/id 1 | |
:containers [{:db/id 2 | |
:containers []}]} | |
{:db/id 3 | |
:containers [{:db/id 4 | |
:containers [{:db/id 5 | |
:containers []}]}]} | |
{:db/id 6}]})))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep6 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.rpl.specter :as sp] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container4" :title "Container 4"] | |
[:db/add "container5" :title "Container 5"] | |
[:db/add "thing1" :title "Thing 1"] | |
[:db/add "thing2" :title "Thing 2"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container1" :containers "container2"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "container2" :containers "container4"] | |
[:db/add "container2" :containers "container5"] | |
[:db/add "container1" :things "thing1"] | |
[:db/add "container2" :things "thing2"] | |
[:db/add "container3" :things "thing2"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>containers | |
{::pco/input [:db/id] | |
::pco/output [{:containers [:db/id]}] | |
::pco/batch? true} | |
(fn [{:keys [db]} inputs] | |
(prn 'id>containers | |
(mapv debug-eid->tempid inputs)) | |
(let [outputs | |
(vec | |
(sp/select | |
[sp/ALL | |
:db/id | |
(sp/view (partial d/pull db [{:containers [:db/id]}])) | |
(sp/if-path nil? | |
(sp/view (constantly {:containers ::pco/unknown-value})) | |
sp/STAY)] | |
inputs))] | |
outputs))) | |
(pco/resolver 'id>things | |
{::pco/input [:db/id] | |
::pco/output [{:things [:db/id]}] | |
::pco/batch? true} | |
(fn [{:keys [db]} inputs] | |
(prn 'id>things (mapv debug-eid->tempid inputs)) | |
(let [outputs | |
(vec | |
(sp/select | |
[sp/ALL | |
:db/id | |
(sp/view (partial d/pull db [{:things [:db/id]}])) | |
(sp/if-path nil? | |
(sp/view (constantly {:things ::pco/unknown-value})) | |
sp/STAY)] | |
inputs))] | |
outputs))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details (mapv debug-eid->tempid items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-containers2 | |
{::pco/input [:db/id (pco/? {:containers [:db/id]})] | |
::pco/output [{:flat-containers [:db/id]}] | |
::pco/batch? true} | |
(fn [_env inputs] | |
(prn '>flat-containers2 | |
(mapv debug-eid->tempid inputs)) | |
(mapv (fn [{:keys [db/id containers]}] | |
{:flat-containers | |
(into [{:db/id id}] containers)}) | |
inputs))) | |
(pco/resolver '>flat-containers3 | |
{::pco/input [:db/id {:containers [{:flat-containers [:db/id]}]}] | |
::pco/output [{:flat-containers [:db/id]}] | |
::pco/batch? true} | |
(fn [_env inputs] | |
(prn '>flat-containers3 | |
(mapv debug-eid->tempid inputs)) | |
(mapv (fn [{:keys [db/id containers]}] | |
{:flat-containers | |
(into [{:db/id id}] (mapcat :flat-containers containers))}) | |
inputs))) | |
(pco/resolver '>flat-things | |
{::pco/input [:db/id {:flat-containers [(pco/? {:things [:db/id]})]}] | |
::pco/output [{:flat-things [:db/id]}] | |
::pco/batch? true} | |
(fn [_env inputs] | |
(prn '>flat-things | |
(mapv debug-eid->tempid inputs)) | |
(map | |
(fn [{:keys [flat-containers]}] | |
{:flat-things | |
(into [] | |
(comp | |
(mapcat :things) | |
(dedupe)) | |
flat-containers)}) | |
inputs)))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
(is (= {:flat-containers | |
[{:title "Container 0"} | |
{:title "Container 1"} | |
{:title "Container 2"} | |
{:title "Container 3"} | |
{:title "Container 4"} | |
{:title "Container 5"}] | |
:flat-things | |
[{:title "Thing 1"} | |
{:title "Thing 2"}]} | |
(p.eql/process | |
env | |
root-container | |
[{:flat-containers [:title]} | |
{:flat-things [:title]}]))))) |
This file contains 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
(ns io.erical.sandbox.pathom.bshep7 | |
(:require | |
[clojure.set :as set] | |
[clojure.test :refer :all] | |
[com.rpl.specter :as sp] | |
[com.wsscode.pathom3.connect.indexes :as pci] | |
[com.wsscode.pathom3.connect.operation :as pco] | |
[com.wsscode.pathom3.interface.eql :as p.eql] | |
[datascript.core :as d])) | |
(deftest example1 | |
(let [schema {:things {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many} | |
:containers {:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many}} | |
tx-data [ | |
[:db/add "container0" :title "Container 0"] | |
[:db/add "container1" :title "Container 1"] | |
[:db/add "container2" :title "Container 2"] | |
[:db/add "container3" :title "Container 3"] | |
[:db/add "container4" :title "Container 4"] | |
[:db/add "container5" :title "Container 5"] | |
[:db/add "thing1" :title "Thing 1"] | |
[:db/add "thing2" :title "Thing 2"] | |
[:db/add "container0" :containers "container1"] | |
[:db/add "container1" :containers "container2"] | |
[:db/add "container2" :containers "container3"] | |
[:db/add "container2" :containers "container4"] | |
[:db/add "container2" :containers "container5"] | |
[:db/add "container1" :things "thing1"] | |
[:db/add "container2" :things "thing2"] | |
[:db/add "container3" :things "thing2"]] | |
{:keys [db-after tempids]} (-> (d/empty-db schema) | |
(d/with tx-data)) | |
root-container {:db/id (get tempids "container0")} | |
debug-eid->tempid (comp (set/map-invert tempids) :db/id) | |
resolvers [ | |
(pco/resolver 'id>flat-containers4 | |
{::pco/input [:db/id] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [{:keys [db]} input] | |
(prn 'id>flat-containers | |
(debug-eid->tempid input)) | |
{:flat-containers | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
(d/pull | |
db | |
[:db/id {:containers '...}] | |
(get input :db/id)))})) | |
(pco/resolver 'id>things | |
{::pco/input [:db/id] | |
::pco/output [{:things [:db/id]}] | |
::pco/batch? true} | |
(fn [{:keys [db]} inputs] | |
(prn 'id>things (mapv debug-eid->tempid inputs)) | |
(let [outputs | |
(vec | |
(sp/select | |
[sp/ALL | |
:db/id | |
(sp/view (partial d/pull db [{:things [:db/id]}])) | |
(sp/if-path nil? | |
(sp/view (constantly {:things ::pco/unknown-value})) | |
sp/STAY)] | |
inputs))] | |
outputs))) | |
(pco/resolver 'id>details | |
{::pco/input [:db/id] | |
::pco/output [:title] | |
::pco/batch? true} | |
(fn [{:keys [db]} items] | |
(prn 'id>details (mapv debug-eid->tempid items)) | |
(into [] | |
(comp | |
(map :db/id) | |
(map (partial d/pull db [:title]))) | |
items))) | |
(pco/resolver '>flat-things | |
{::pco/input [:db/id {:flat-containers [(pco/? {:things [:db/id]})]}] | |
::pco/output [{:flat-things [:db/id]}] | |
::pco/batch? true} | |
(fn [_env inputs] | |
(prn '>flat-things | |
(mapv debug-eid->tempid inputs)) | |
(map | |
(fn [{:keys [flat-containers]}] | |
{:flat-things | |
(into [] | |
(comp | |
(mapcat :things) | |
(dedupe)) | |
flat-containers)}) | |
inputs)))] | |
env (-> {:db db-after} | |
(pci/register resolvers))] | |
(is (= {:flat-containers | |
[{:title "Container 0"} | |
{:title "Container 1"} | |
{:title "Container 2"} | |
{:title "Container 3"} | |
{:title "Container 4"} | |
{:title "Container 5"}] | |
:flat-things | |
[{:title "Thing 1"} | |
{:title "Thing 2"}]} | |
(p.eql/process | |
env | |
root-container | |
[{:flat-containers [:title]} | |
{:flat-things [:title]}]))))) | |
(pco/resolver 'id>flat-containers4 | |
{::pco/input [:db/id] | |
::pco/output [{:flat-containers [:db/id]}]} | |
(fn [{:keys [db]} input] | |
(prn 'id>flat-containers | |
(debug-eid->tempid input)) | |
{:flat-containers | |
(sp/select | |
[(sp/recursive-path [] p | |
(sp/stay-then-continue :containers sp/ALL p)) | |
(sp/submap [:db/id])] | |
(d/pull | |
db | |
[:db/id {:containers '...}] | |
(get input :db/id)))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment