File tree Expand file tree Collapse file tree 2 files changed +29
-15
lines changed
src/com/walmartlabs/lacinia
test/com/walmartlabs/lacinia Expand file tree Collapse file tree 2 files changed +29
-15
lines changed Original file line number Diff line number Diff line change 314314
315315(defn ^:private fold-queries
316316 [{:keys [queries] :as schema}]
317- (cond
318- (map? queries) (update-in schema [:objects :Query :fields ] merge queries)
319- :else schema))
317+ (let [query (get-in schema [:roots :query ] :Query )]
318+ (cond
319+ (map? queries) (update-in schema [:objects query :fields ] merge queries)
320+ :else schema)))
320321
321322(defn ^:private fold-mutations
322323 [{:keys [mutations] :as schema}]
323- (cond
324- (map? mutations) (update-in schema [:objects :Mutation :fields ] merge mutations)
325- :else schema))
324+ (let [mutation (get-in schema [:roots :mutation ] :Mutation )]
325+ (cond
326+ (map? mutations) (update-in schema [:objects mutation :fields ] merge mutations)
327+ :else schema)))
326328
327329(defn ^:private fold-subscriptions
328330 [{:keys [subscriptions] :as schema}]
329- (cond
330- (map? subscriptions) (update-in schema [:objects :Subscription :fields ] merge subscriptions)
331- :else schema))
331+ (let [subscription (get-in schema [:roots :subscription ] :Subscription )]
332+ (cond
333+ (map? subscriptions) (update-in schema [:objects subscription :fields ] merge subscriptions)
334+ :else schema)))
332335
333336(defn generate-sdl
334337 " Translate the edn lacinia schema to the SDL schema."
355358 :directive-defs (edn-directive-defs->sdl-directives val)
356359 :roots (edn-roots->sdl-schema val)
357360 " " )))
358- (join " \n\n " )))
361+ (join " \n\n " )
362+ clojure.string/trim))
359363
360364(defn inject-federation
361365 " Called after SDL parsing to extend the input schema
Original file line number Diff line number Diff line change @@ -269,15 +269,15 @@ query($reps : [_Any!]!) {
269269 (is (= #{" Stuff" } union-names)))))
270270
271271(deftest edn-schema->sdl-schema
272- (let [sample-schema '{:roots {:query :query
273- :mutation :mutation }
272+ (let [sample-edn-1 '{:roots {:query :MyQuery
273+ :mutation :Mutation }
274274 :interfaces
275275 {:Node
276276 {:fields
277277 {:id
278278 {:type (non-null ID)}}}}
279279 :objects
280- {:Query
280+ {:MyQuery
281281 {:fields
282282 {:todo
283283 {:type :Todo
@@ -332,8 +332,18 @@ query($reps : [_Any!]!) {
332332 :resolvable
333333 {:type Boolean :default-value true }}}
334334 :external
335- {:locations #{:field-definition }}}}]
336- (is (= (-> sample-schema generate-sdl parse-schema) sample-schema))))
335+ {:locations #{:field-definition }}}}
336+ sample-edn-2 '{:queries
337+ {:node
338+ {:description " node query"
339+ :type Node
340+ :args {:id {:type (non-null ID)}}}}
341+ :roots
342+ {:query :CustomQuery }}
343+ sample-sdl-2 " schema {\n query: CustomQuery\n }\n\n type CustomQuery{\n \"\"\"\n node query\n \"\"\"\n node(id: ID!): Node\n }" ]
344+
345+ (is (= (-> sample-edn-1 generate-sdl parse-schema) sample-edn-1))
346+ (is (= (generate-sdl sample-edn-2) sample-sdl-2))))
337347
338348(deftest only-edn-schama-essential
339349 (let [edn (-> " dev-resources/edn-federation.edn" slurp read-string)
You can’t perform that action at this time.
0 commit comments