Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(def my-games {
"game1" {:key "gamey-1" :name "hello-game" :created 2017 :sub-game ["foo1" "bar2"]}
"game2" {:key "gamey-2" :name "goodbye-game" :created 2019 :sub-game ["bar3" "baz8"]}
(def my-sub-games {
"foo1" {:name "foo game 1"}
"bar2" {:name "bar game 2"}
"bar3" {:name "bar game 3"}
"baz8" {:name "baz game 8"}
(def testy-schema
{:Sub-Games {:description "a sub game check of nested resolvers"
:fields {:name {:type (non-null String)}}}
:Game {:description "A game object"
:fields {:key {:type (non-null String)
:description "Unique identifier for this game"}
:created {:type Int}
:name {:type (non-null String)}
:subgame {:type (list :Sub-Games)
:resolve :sub-game-resolver}}}}
{:game {:type :Game
:description "Retrieve a single Game by its name"
:args {:name {:type (non-null String)
:description "Unique name for game."}}
:resolve :game-resolver}}})
(defn game-resolver-func [app-context-map field-args outer-field-resolved-val]
;; in this case outer-field-resolved-val is nil
(get my-games (:name field-args)))
(defn sub-game-resolver-func [app-context-map field-args outer-field-resolved-val]
;; here outer-field-resolved-val is the map returned from game-resolve-func
(map #(get my-sub-games %) (:sub-game cont-field-resolved-val)))
(defn compiled-schema
(-> testy-schema
(attach-resolvers {:game-resolver game-resolver-func
:sub-game-resolver sub-game-resolver-func})
{ game(name: "game1") {
subgame {
;; output
{:data #ordered/map ([:game #ordered/map
([:key "gamey-1"]
[:created 2017]
[:subgame (#ordered/map
([:name "foo game 1"])
([:name "bar game 2"]))])])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment