Skip to content

Commit

Permalink
Check for data upon navigation to detect nested requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkerlucio committed Feb 7, 2021
1 parent 791a3bc commit d9a950c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/com/wsscode/pathom3/connect/planner.cljc
Expand Up @@ -1327,7 +1327,9 @@
(sub-required-input-reachable?* env sub available))

; there is no node from the graph, but still gonna look in current data
(sub-required-input-reachable?* env sub available-sub-data))))
(if (contains? available-data attr)
(sub-required-input-reachable?* env sub available-sub-data)
false))))

(defn required-input-reachable?
"After running a sub graph for dependencies, the planner checks if all required inputs
Expand Down
7 changes: 7 additions & 0 deletions src/main/com/wsscode/pathom3/connect/runner.cljc
Expand Up @@ -364,6 +364,11 @@
::node-resolver-input input-data
::env env}})

(defn valid-response? [x]
(or (map? x)
(nil? x)
(refs/kw-identical? x ::node-error)))

(defn invoke-resolver-from-node
"Evaluates a resolver using node information.
Expand Down Expand Up @@ -409,6 +414,8 @@
(mark-resolver-error-with-plugins env node e)
::node-error))
finish (time/now-ms)]
(if-not (valid-response? result)
(l/warn ::invalid-resolver-response {::pco/op-name op-name :response result}))
(merge-node-stats! env node
(cond-> {::resolver-run-finish-ms finish}
(not (::batch-hold result))
Expand Down
26 changes: 26 additions & 0 deletions test/com/wsscode/pathom3/connect/planner_test.cljc
Expand Up @@ -2431,6 +2431,32 @@
{:users 2, :scores-sum 1},
:com.wsscode.pathom3.connect.planner/root 2})))

(testing "self output reference in input"
(is (= (compute-run-graph
(-> {::eql/query [:b]
::resolvers '[{::pco/op-name x
::pco/input [{:a [:b]}]
::pco/output [:b]}]}))
'#:com.wsscode.pathom3.connect.planner{:nodes {},
:index-ast {:b {:type :prop,
:dispatch-key :b,
:key :b}},
:unreachable-resolvers #{x},
:unreachable-paths {:a {:b {}}, :b {}}}))

(is (= (compute-run-graph
(-> {::eql/query [:b]
::pcp/available-data {:a {}}
::resolvers '[{::pco/op-name x
::pco/input [{:a [:b]}]
::pco/output [:b]}]}))
'#:com.wsscode.pathom3.connect.planner{:nodes {},
:index-ast {:b {:type :prop,
:dispatch-key :b,
:key :b}},
:unreachable-resolvers #{x},
:unreachable-paths {:a {:b {}}, :b {}}})))

(testing "multiple distinct nested details"
(is (= (compute-run-graph
(-> {::eql/query [:scores-sum :age-sum]
Expand Down

0 comments on commit d9a950c

Please sign in to comment.