Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (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
- '{:objects
- {: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}}}}
- :queries
- {: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})
- schema/compile))
- ;;query
- { game(name: "game1") {
- key
- created
- subgame {
- name
- }
- }
- }
- ;; output
- {:data #ordered/map ([:game #ordered/map
- ([:key "gamey-1"]
- [:created 2017]
- [:subgame (#ordered/map
- ([:name "foo game 1"])
- #ordered/map
- ([:name "bar game 2"]))])])}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement