Description command-resolve-json-spec - like command-resolve-spec but use "string" keys instead of Keywords
Querying(internal execution) controlled by QueryExpression - custom DSL, what visually mention the EQL.
QueryExpression syntax example ["a0" ["b0" {"b0props" {}}] {"c0" ["a1" "b1" {"c1" ["a2" "b2"]}]} {["d0" {"d0props" {}}] ["a1" "b1"]}]
Example (defmethod commando.commands.builtin/command-mutation "generate-password" [_ _] {"random-string" (apply str (repeatedly 20 #(rand-nth "abcdefghijklmnopqrstuvwxyz0123456789")))})
(defmethod command-resolve "query-passport" [_ {:strs [first-name last-name QueryExpression]}] ;; Mocking SQL operation to db (when (and (= first-name "Adam") (= last-name "Nowak")) (->query-run {"number" "FA939393" "issued" "10-04-2020"} QueryExpression)))
(defmethod command-resolve "query-user" [_ {:strs [QueryExpression]}] (-> {"first-name" "Adam" "last-name" "Nowak" "info" {"age" 25 "weight" 70 "height" 188} "passport" (resolve-instruction-qe "- no passport - " {"commando-resolve" "query-passport" "first-name" "Adam" "last-name" "Nowak"}) "password" (resolve-instruction "- no password - " {"commando-mutation" "generate-password"})} (->query-run QueryExpression)))
;; Let try to use it! (:instruction (commando.core/execute [commands-builtin/command-mutation-json-spec command-resolve-json-spec] {"commando-resolve" "query-user" "QueryExpression" ["first-name" {"info" ["age" "weight"]}]})) => {"first-name" "Adam", "info" {"age" 25, "weight" 70}}
;; do the same but with different QueryExpression
{"commando-resolve" "query-user" "QueryExpression" ["first-name" {"password" []}]} => {"first-name" "Adam", "password" {"random-string" "zz0fydanqzwd2cjyu7yc"}}
{"commando-resolve" "query-user" "QueryExpression" ["first-name" {"passport" ["number"]}]} => {"first-name" "Adam", "passport" {}}
{"commando-resolve" "query-user" "QueryExpression" ["first-name" "UNEXISTING"]} => {"first-name" "Adam", "UNEXISTING" {:status :failed, :errors [{:message "Commando. Graph Query. QueryExpression attribute 'UNEXISTING' is unreachable"}]}}
Parts
commando.commands.query-dsl/resolve-instruction-qe run internal call of commando/execute.
commando.commands.query-dsl/->query-run trim query data according to passed QueryExpression
commando.commands.query-dsl/command-resolve multimethod to declare resolvers.
See Also
commando.core/execute
commando.commands.query-dsl/command-mutation-spec
commando.commands.builtin/command-mutation-spec
Description
command-resolve-json-spec - like command-resolve-spec but
use "string" keys instead of Keywords
Querying(internal execution) controlled by QueryExpression - custom
DSL, what visually mention the EQL.
QueryExpression syntax example
["a0"
["b0" {"b0props" {}}]
{"c0"
["a1"
"b1"
{"c1"
["a2"
"b2"]}]}
{["d0" {"d0props" {}}]
["a1"
"b1"]}]
Example
(defmethod commando.commands.builtin/command-mutation "generate-password" [_ _]
{"random-string" (apply str (repeatedly 20 #(rand-nth "abcdefghijklmnopqrstuvwxyz0123456789")))})
(defmethod command-resolve "query-passport" [_ {:strs [first-name last-name QueryExpression]}]
;; Mocking SQL operation to db
(when (and
(= first-name "Adam")
(= last-name "Nowak"))
(->query-run
{"number" "FA939393"
"issued" "10-04-2020"}
QueryExpression)))
(defmethod command-resolve "query-user" [_ {:strs [QueryExpression]}]
(-> {"first-name" "Adam"
"last-name" "Nowak"
"info" {"age" 25 "weight" 70 "height" 188}
"passport" (resolve-instruction-qe
"- no passport - "
{"commando-resolve" "query-passport"
"first-name" "Adam"
"last-name" "Nowak"})
"password" (resolve-instruction
"- no password - "
{"commando-mutation" "generate-password"})}
(->query-run QueryExpression)))
;; Let try to use it!
(:instruction
(commando.core/execute
[commands-builtin/command-mutation-json-spec
command-resolve-json-spec]
{"commando-resolve" "query-user"
"QueryExpression"
["first-name"
{"info"
["age"
"weight"]}]}))
=> {"first-name" "Adam",
"info" {"age" 25, "weight" 70}}
;; do the same but with different QueryExpression
{"commando-resolve" "query-user"
"QueryExpression"
["first-name"
{"password" []}]}
=> {"first-name" "Adam",
"password" {"random-string" "zz0fydanqzwd2cjyu7yc"}}
{"commando-resolve" "query-user"
"QueryExpression"
["first-name"
{"passport"
["number"]}]}
=> {"first-name" "Adam", "passport" {}}
{"commando-resolve" "query-user"
"QueryExpression"
["first-name"
"UNEXISTING"]}
=> {"first-name" "Adam",
"UNEXISTING" {:status :failed,
:errors [{:message "Commando. Graph Query. QueryExpression attribute 'UNEXISTING' is unreachable"}]}}
Parts
`commando.commands.query-dsl/resolve-instruction-qe` run internal call of `commando/execute`.
`commando.commands.query-dsl/->query-run` trim query data according to passed QueryExpression
`commando.commands.query-dsl/command-resolve` multimethod to declare resolvers.
See Also
`commando.core/execute`
`commando.commands.query-dsl/command-mutation-spec`
`commando.commands.builtin/command-mutation-spec`Description
command-resolve-spec - behave like command-mutation-spec
but allow invoking commando/execute internally inside the
evaluation step, what make it usefull for querying data.
Querying(internal execution) controlled by QueryExpression - custom DSL, what visually mention the EQL.
QueryExpression Syntax Example [:a0 [:b0 {:b0props {}}] {:c0 [:a1 :b1 {:c1 [:a2 :b2]}]} {[:d0 {:d0props {}}] [:a1 :b1]}]
Example (defmethod commando.commands.builtin/command-mutation :generate-password [_ _] {:random-string (apply str (repeatedly 20 #(rand-nth "abcdefghijklmnopqrstuvwxyz0123456789")))})
(defmethod command-resolve :query-passport [_ {:keys [first-name last-name QueryExpression]}] ;; Mocking SQL operation to db (when (and (= first-name "Adam") (= last-name "Nowak")) (->query-run {:number "FA939393" :issued "10-04-2020"} QueryExpression)))
(defmethod command-resolve :query-user [_ {:keys [QueryExpression]}] (-> {:first-name "Adam" :last-name "Nowak" :info {:age 25 :weight 70 :height 188} :passport (resolve-instruction-qe "- no passport - " {:commando/resolve :query-passport :first-name "Adam" :last-name "Nowak"}) :password (resolve-instruction "- no password - " {:commando/mutation :generate-password})} (->query-run QueryExpression)))
;; Let try to use it! (:instruction (commando.core/execute [commands-builtin/command-mutation-spec command-resolve-spec] {:commando/resolve :query-user :QueryExpression [:first-name {:info [:age :weight]}]})) => {:first-name "Adam" :info {:age 25, :weight 70}}
;; do the same but with different QueryExpression
[:first-name :password] => {:first-name "Adam", :password "- no password - "}
[:first-name {:password []}] => {:first-name "Adam", :password {:random-string "lexccpux2pzdupzwx79o"}}
[:first-name {:passport [:number]}] => {:first-name "Adam", :password {:number "FA939393"}}
[:first-name :UNEXISTING] => {:first-name "Adam", :UNEXISTING {:status :failed, :errors [{:message "Commando. Graph Query. QueryExpression attribute ':UNEXISTING' is unreachable"}]}}
Parts
commando.commands.query-dsl/resolve-instruction-qe run internal call of commando/execute.
commando.commands.query-dsl/->query-run trim query data according to passed QueryExpression
commando.commands.query-dsl/command-resolve multimethod to declare resolvers.
See Also
commando.core/execute
commando.commands.query-dsl/command-mutation-spec
commando.commands.builtin/command-mutation-spec
Description
command-resolve-spec - behave like command-mutation-spec
but allow invoking `commando/execute` internally inside the
evaluation step, what make it usefull for querying data.
Querying(internal execution) controlled by QueryExpression - custom
DSL, what visually mention the EQL.
QueryExpression Syntax Example
[:a0
[:b0 {:b0props {}}]
{:c0
[:a1
:b1
{:c1
[:a2
:b2]}]}
{[:d0 {:d0props {}}]
[:a1
:b1]}]
Example
(defmethod commando.commands.builtin/command-mutation :generate-password [_ _]
{:random-string (apply str (repeatedly 20 #(rand-nth "abcdefghijklmnopqrstuvwxyz0123456789")))})
(defmethod command-resolve :query-passport [_ {:keys [first-name last-name QueryExpression]}]
;; Mocking SQL operation to db
(when (and
(= first-name "Adam")
(= last-name "Nowak"))
(->query-run
{:number "FA939393"
:issued "10-04-2020"}
QueryExpression)))
(defmethod command-resolve :query-user [_ {:keys [QueryExpression]}]
(-> {:first-name "Adam"
:last-name "Nowak"
:info {:age 25 :weight 70 :height 188}
:passport (resolve-instruction-qe
"- no passport - "
{:commando/resolve :query-passport
:first-name "Adam"
:last-name "Nowak"})
:password (resolve-instruction
"- no password - "
{:commando/mutation :generate-password})}
(->query-run QueryExpression)))
;; Let try to use it!
(:instruction
(commando.core/execute
[commands-builtin/command-mutation-spec
command-resolve-spec]
{:commando/resolve :query-user
:QueryExpression
[:first-name
{:info
[:age
:weight]}]}))
=> {:first-name "Adam"
:info {:age 25, :weight 70}}
;; do the same but with different QueryExpression
[:first-name
:password]
=> {:first-name "Adam", :password "- no password - "}
[:first-name
{:password []}]
=> {:first-name "Adam", :password {:random-string "lexccpux2pzdupzwx79o"}}
[:first-name
{:passport
[:number]}]
=> {:first-name "Adam", :password {:number "FA939393"}}
[:first-name
:UNEXISTING]
=> {:first-name "Adam",
:UNEXISTING {:status :failed, :errors [{:message "Commando. Graph Query. QueryExpression attribute ':UNEXISTING' is unreachable"}]}}
Parts
`commando.commands.query-dsl/resolve-instruction-qe` run internal call of `commando/execute`.
`commando.commands.query-dsl/->query-run` trim query data according to passed QueryExpression
`commando.commands.query-dsl/command-resolve` multimethod to declare resolvers.
See Also
`commando.core/execute`
`commando.commands.query-dsl/command-mutation-spec`
`commando.commands.builtin/command-mutation-spec`(resolve-fn default-value fn-resolver)Take a default-value and fn-resolver - simple function that
can optionally accept KeyProperties(passed data from QueryExpression syntax) map
and return the data that can be queried by QueryExpression syntax
by commando registry. Return Resolver object that will be processed
by ->query-run.
Example (resolve-fn [] (fn [{:keys [x]}] (vec (for [i (range (or x 5))] {:value i}))))
See Also
commando.commands.query-dsl/->query-run
commando.commands.query-dsl/->resolve-instruction-qe
- the same but for Instruction with :commando/resolve command
on the top-level.
commando.commands.query-dsl/->resolve-instruction
- the same but for any Instruction can execute your registry.
Take a default-value and fn-resolver - simple function that
can optionally accept KeyProperties(passed data from QueryExpression syntax) map
and return the data that can be queried by QueryExpression syntax
by commando registry. Return Resolver object that will be processed
by `->query-run`.
Example
(resolve-fn
[]
(fn [{:keys [x]}]
(vec (for [i (range (or x 5))]
{:value i}))))
See Also
`commando.commands.query-dsl/->query-run`
`commando.commands.query-dsl/->resolve-instruction-qe`
- the same but for Instruction with `:commando/resolve` command
on the top-level.
`commando.commands.query-dsl/->resolve-instruction`
- the same but for any Instruction can execute your registry.(resolve-instruction default-value Instruction)Take a default-value and Instruction that can be executed by commando
registry. Return Resolver object that will be processed by ->query-run.
Example (resolve-instruction 0 {:vector1 [1 2 3] :vector2 [3 2 1] :result {:commando/fn (fn [& [v1 v2]] (reduce + (map * v1 v2))) :args [{:commando/from [:vector1]} {:commando/from [:vector2]}]}})
See Also
commando.commands.query-dsl/->query-run
commando.commands.query-dsl/->resolve-instruction-qe
- the same but for Instruction with :commando/resolve command
on the top-level.
commando.commands.query-dsl/->resolve-fn
- the same but for simple function resolving
Take a default-value and Instruction that can be executed by commando
registry. Return Resolver object that will be processed by `->query-run`.
Example
(resolve-instruction
0
{:vector1 [1 2 3]
:vector2 [3 2 1]
:result {:commando/fn (fn [& [v1 v2]] (reduce + (map * v1 v2)))
:args [{:commando/from [:vector1]}
{:commando/from [:vector2]}]}})
See Also
`commando.commands.query-dsl/->query-run`
`commando.commands.query-dsl/->resolve-instruction-qe`
- the same but for Instruction with `:commando/resolve` command
on the top-level.
`commando.commands.query-dsl/->resolve-fn`
- the same but for simple function resolving(resolve-instruction-qe default-value InstructionWithQueryExpression)Take a default-value and Instruction with :commando/resolve command
on the top-level, and return Resolver object that will be processed
by ->query-run
Example (resolve-instruction-qe [] {:commando/resolve :cars-by-model :model "Citroen"}
See Also
commando.commands.query-dsl/->query-run
commando.commands.query-dsl/->resolve-instruction
- the same but for any Instruction can execute your registry.
commando.commands.query-dsl/->resolve-fn
- the same but for simple function resolving
Take a default-value and Instruction with `:commando/resolve` command
on the top-level, and return Resolver object that will be processed
by `->query-run`
Example
(resolve-instruction-qe
[]
{:commando/resolve :cars-by-model
:model "Citroen"}
See Also
`commando.commands.query-dsl/->query-run`
`commando.commands.query-dsl/->resolve-instruction`
- the same but for any Instruction can execute your registry.
`commando.commands.query-dsl/->resolve-fn`
- the same but for simple function resolving(resolver? obj)Check is the obj a commando.commands.query_dsl/Resolver instance
Check is the obj a `commando.commands.query_dsl/Resolver` instance
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |