-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In case of priority draw, pick the node with the most number of input…
…s already available
- Loading branch information
1 parent
46b3b0a
commit 0931f97
Showing
4 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
(ns com.wsscode.pathom3.connect.runner.helpers | ||
(:require | ||
[check.core :refer [#_ :clj-kondo/ignore => check]] | ||
[clojure.spec.alpha :as s] | ||
[clojure.test :refer [testing]] | ||
[com.wsscode.pathom3.connect.runner :as pcr] | ||
[com.wsscode.pathom3.connect.runner.async :as pcra] | ||
[com.wsscode.pathom3.connect.runner.parallel :as pcrc] | ||
[com.wsscode.pathom3.entity-tree :as p.ent] | ||
[com.wsscode.pathom3.format.eql :as pf.eql] | ||
[edn-query-language.core :as eql] | ||
[matcher-combinators.test] | ||
[promesa.core :as p]) | ||
#?(:cljs | ||
(:require-macros | ||
[com.wsscode.pathom3.connect.runner.helpers]))) | ||
|
||
(defn match-keys? [ks] | ||
(fn [m] | ||
(reduce | ||
(fn [_ k] | ||
(if-let [v (find m k)] | ||
(if (s/valid? k (val v)) | ||
true | ||
(reduced false)) | ||
(reduced false))) | ||
true | ||
ks))) | ||
|
||
(defn run-graph | ||
([{::keys [map-select?] :as env} tree query] | ||
(let [ast (eql/query->ast query) | ||
res (pcr/run-graph! env ast (p.ent/create-entity tree))] | ||
(if map-select? | ||
(pf.eql/map-select env res query) | ||
res))) | ||
([env tree query _] (run-graph env tree query))) | ||
|
||
(defn run-graph-async | ||
([env tree query] | ||
(let [ast (eql/query->ast query)] | ||
(pcra/run-graph! env ast (p.ent/create-entity tree)))) | ||
([env tree query _expected] | ||
(run-graph-async env tree query))) | ||
|
||
(defn run-graph-parallel [env tree query] | ||
(let [ast (eql/query->ast query)] | ||
(p/timeout | ||
(pcrc/run-graph! env ast (p.ent/create-entity tree)) | ||
3000))) | ||
|
||
(def all-runners [run-graph #?@(:clj [run-graph-async run-graph-parallel])]) | ||
|
||
#?(:clj | ||
(defmacro check-serial [env entity tx expected] | ||
`(check | ||
(run-graph ~env ~entity ~tx) | ||
~'=> ~expected)) | ||
|
||
:cljs | ||
(defn check-serial [env entity tx expected] | ||
(check | ||
(run-graph env entity tx) | ||
=> expected))) | ||
|
||
#?(:clj | ||
(defmacro check-parallel [env entity tx expected] | ||
`(check | ||
@(run-graph-parallel ~env ~entity ~tx) | ||
~'=> ~expected)) | ||
|
||
:cljs | ||
(defn check-parallel [env entity tx expected] | ||
(check | ||
@(run-graph-parallel env entity tx) | ||
=> expected))) | ||
|
||
#?(:clj | ||
(defmacro check-all-runners [env entity tx expected] | ||
`(doseq [runner# all-runners] | ||
(testing (str runner#) | ||
(check | ||
(let [res# (runner# ~env ~entity ~tx)] | ||
(if (p/promise? res#) | ||
@res# res#)) | ||
~'=> ~expected)))) | ||
|
||
:cljs | ||
(defn check-all-runners [env entity tx expected] | ||
(doseq [runner all-runners] | ||
(testing (str runner) | ||
(check | ||
(let [res (runner env entity tx)] | ||
(if (p/promise? res) | ||
@res res)) | ||
=> expected))))) |
31 changes: 31 additions & 0 deletions
31
test/com/wsscode/pathom3/connect/runner/path_selection.cljc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns com.wsscode.pathom3.connect.runner.path-selection | ||
(:require | ||
[clojure.test :refer [deftest]] | ||
[com.wsscode.pathom3.connect.indexes :as pci] | ||
[com.wsscode.pathom3.connect.operation :as pco] | ||
[com.wsscode.pathom3.connect.runner.helpers :as rr :refer [check-all-runners]])) | ||
|
||
(deftest run-graph-input-size-sort | ||
(let [env (pci/register | ||
[(pco/resolver 'resolve-full-name-by-first-name | ||
{::pco/input [:person/first-name] | ||
::pco/output [:person/full-name]} | ||
(fn [_ {:person/keys [first-name]}] | ||
{:person/full-name first-name})) | ||
|
||
(pco/resolver 'resolve-full-name-with-first-and-last-name | ||
{::pco/input [:person/first-name :person/last-name] | ||
::pco/output [:person/full-name]} | ||
(fn [_ {:person/keys [first-name last-name]}] | ||
{:person/full-name (str first-name " " last-name)}))])] | ||
(check-all-runners | ||
env | ||
{:person/first-name "Björn", :person/last-name "Ebbinghaus"} | ||
[:person/full-name] | ||
{:person/full-name "Björn Ebbinghaus"}) | ||
|
||
(check-all-runners | ||
env | ||
{:person/first-name "Björn"} | ||
[:person/full-name] | ||
{:person/full-name "Björn"}))) |