Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
namenu authored Feb 3, 2024
2 parents deeabef + f698166 commit d1c1999
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
14 changes: 7 additions & 7 deletions docs/_examples/tutorial/schema-6.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns clojure-game-geek.schema
(ns my.clojure-game-geek.schema
"Contains custom resolvers and a function to provide the full schema."
(:require
[clojure.java.io :as io]
Expand All @@ -22,8 +22,8 @@
(defn rate-game
[db]
(fn [_ args _]
(let [{game-id :game_id
member-id :member_id
(let [{game-id :gameId
member-id :memberId
rating :rating} args
game (db/find-game-by-id db game-id)
member (db/find-member-by-id db member-id)]
Expand Down Expand Up @@ -79,11 +79,11 @@
(defn resolver-map
[component]
(let [db (:db component)]
{:query/game-by-id (game-by-id db)
:query/member-by-id (member-by-id db)
:mutation/rate-game (rate-game db)
{:Query/gameById (game-by-id db)
:Query/memberById (member-by-id db)
:Mutation/rateGame (rate-game db)
:BoardGame/designers (board-game-designers db)
:BoardGame/rating-summary (rating-summary db)
:BoardGame/ratingSummary (rating-summary db)
:GameRating/game (game-rating->game db)
:Designer/games (designer-games db)
:Member/ratings (member-ratings db)}))
Expand Down
2 changes: 1 addition & 1 deletion docs/_examples/tutorial/user-1.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns user
(:require
[clojure-game-geek.schema :as s]
[my.clojure-game-geek.schema :as s]
[com.walmartlabs.lacinia :as lacinia]))

(def schema (s/load-schema))
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/init-schema.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ In the next chapter, we'll build on this modest start, introducing more schema t


.. [#internal] Internally, `everything` is converted to keywords, so if you prefer
to use symbols everywhere, nothing will break. Conversion to keyboards is one part of the schema compilation
to use symbols everywhere, nothing will break. Conversion to keywords is one part of the schema compilation
process.
.. [#spec] Because the input schema format is so complex, it is `always` validated
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/member-ratings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ We need the server started after the component refactoring::

First, select the rating summary data for a game::

(q "{ gameById(icd: \"1237\") { name ratingSummary { count average }}}")
(q "{ gameById(id: \"1237\") { name ratingSummary { count average }}}")
=> {:data {:gameById {:name "7 Wonders: Duel", :ratingSummary {:count 3, :average 4.333333333333333}}}}


Expand Down
6 changes: 2 additions & 4 deletions src/com/walmartlabs/lacinia/executor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(:require
[com.walmartlabs.lacinia.internal-utils
:refer [cond-let q to-message
deep-merge deep-merge-value keepv get-nested]]
deep-merge keepv get-nested]]
[flatland.ordered.map :refer [ordered-map]]
[com.walmartlabs.lacinia.select-utils :as su]
[com.walmartlabs.lacinia.resolve-utils :refer [transform-result aggregate-results]]
Expand Down Expand Up @@ -188,7 +188,7 @@
left-value

(map? left-alias-value)
(update left-value alias deep-merge-value value)
(update left-value alias deep-merge value)

:else
(assoc left-value alias value)))
Expand Down Expand Up @@ -618,5 +618,3 @@
(let [{:keys [root selections]} parsed-query]
{constants/parsed-query-key parsed-query
constants/selection-key (->RootSelections root selections)}))


16 changes: 5 additions & 11 deletions src/com/walmartlabs/lacinia/internal_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -407,27 +407,21 @@
nil
coll))

(declare deep-merge)

(defn deep-merge-value
(defn deep-merge
"Merges two maps together. Later map override earlier.
If a key is sequential, then each element in the list is merged."
[left right]
(cond
(and (map? left) (map? right))
(deep-merge left right)
(merge-with deep-merge left right)

(and (sequential? left) (sequential? right))
(mapv deep-merge left right)

(or (map? right) (sequential? right))
(or (map? right) (sequential? right))
(throw (ex-info "unable to deep merge"
{:left left
:right right}))

:else
right))

(defn deep-merge
"Merges two maps together. Later map override earlier.
If a key is sequential, then each element in the list is merged."
[left-value right-value]
(merge-with deep-merge-value left-value right-value))
15 changes: 15 additions & 0 deletions test/com/walmartlabs/lacinia/merge_selections_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,18 @@ query ($who : String) {
}
}
}"))))

(deftest merge-list-in-fragment
(is (= {:data {:luke {:name "Luke Skywalker"
:appears_in [:NEWHOPE :EMPIRE :JEDI]}}}
(q "
{
luke: human(id: \"1000\") {
name
appears_in
...props
}
}
fragment props on human {
appears_in
}"))))

0 comments on commit d1c1999

Please sign in to comment.