Skip to content

Commit

Permalink
Merge branch 'ys/fix-analyzing-order'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed Apr 20, 2017
2 parents 5a31497 + b695096 commit 3f4729d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/alumbra/analyzer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [alumbra.analyzer
[directives :as directives]
[enums :as enums]
[implementations :as implementations]
[kinds :as kinds]
[scalars :as scalars]
[schema-root :as schema-root]
Expand Down Expand Up @@ -29,6 +30,7 @@
(types/analyze schema)
(unions/analyze schema)
(kinds/aggregate)
(implementations/aggregate)
(valid-fragment-spreads/aggregate))
schema))

Expand Down
15 changes: 15 additions & 0 deletions src/alumbra/analyzer/implementations.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns alumbra.analyzer.implementations)

(defn aggregate
[{:keys [interfaces types] :as schema}]
(reduce
(fn [schema {:keys [type-name implements]}]
(reduce
(fn [schema interface-name]
(cond-> schema
(contains? interfaces interface-name)
(update-in [:interfaces interface-name :implemented-by]
conj
type-name)))
schema implements))
schema (vals types)))
7 changes: 1 addition & 6 deletions src/alumbra/analyzer/types.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@
(update-in
[:types implementing-type-name :implements]
conj
type-name)
(contains? interfaces type-name)
(update-in
[:interfaces type-name :implemented-by]
conj
implementing-type-name)))
type-name)))
data implements))

;; ## Types
Expand Down
14 changes: 14 additions & 0 deletions test/alumbra/analyzer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@
(-> (get-in schema [:types "QueryRoot" :fields]) keys set)))
(is (= "QueryRoot"
(get-in schema [:schema-root :schema-root-types "query"])))))

(deftest t-analyzer-interface-implementations
(let [declaration "interface SomeInterface { x: Int }"
implementation "type SomeType implements SomeInterface { x: Int }"
declaration-first (analyze [declaration implementation])
implementation-first (analyze [implementation declaration])
implemented-by #(get-in % [:interfaces "SomeInterface" :implemented-by])
implements #(get-in % [:types "SomeType" :implements])]
(is (= (implemented-by declaration-first)
(implemented-by implementation-first)
#{"SomeType"}))
(is (= (implements declaration-first)
(implements implementation-first)
#{"SomeInterface"}))))

0 comments on commit 3f4729d

Please sign in to comment.