Skip to content

Commit

Permalink
build/validate-schema 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
namenu committed May 20, 2024
1 parent 172f006 commit 18e9682
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
com.kohlschutter.junixsocket/junixsocket-native-common {:mvn/version "2.9.1"}
fipp/fipp {:mvn/version "0.6.26"}
meander/epsilon {:mvn/version "0.0.650"}
org.clj-commons/pretty {:mvn/version "2.6.0"}
org.clojure/data.json {:mvn/version "2.5.0"}
org.clojure/tools.logging {:mvn/version "1.3.0"}}
:aliases {:cli {:extra-deps {org.clojure/tools.cli {:mvn/version "1.1.230"}}}
Expand Down
18 changes: 15 additions & 3 deletions src/tools/graphql/api.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(ns tools.graphql.api
(:require [clojure.edn :as edn]
(:require [clj-commons.ansi :refer [pcompose]]
[clojure.edn :as edn]
[clojure.java.io :as io]
[tools.graphql.sdl :as sdl]
[tools.graphql.stitch.impl :as stitch]
[tools.graphql.stitch.watch :as stitch.watch])
[tools.graphql.stitch.core :as stitch]
[tools.graphql.stitch.watch :as stitch.watch]
[tools.graphql.validators :as validators])
(:import (java.io PushbackReader Writer)))

(defn- is-path-under-dir? [file-path dir-path]
Expand Down Expand Up @@ -94,3 +96,13 @@
(->> (scan-vars input-path)
(map (comp symbol namespace))
(distinct)))

(defn validate
[& {:keys [input-path]}]
(let [schema (stitch/read-edn (io/file input-path))]
(doseq [t (validators/unreachable-types schema)]
(pcompose [:red "Unreachable type"] " " (name t)))
(doseq [f (validators/unreachable-input-types schema)]
(pcompose [:red "Unreachable input"] " " (name f)))
(doseq [i (validators/unreachable-interfaces schema)]
(pcompose [:red "Unreachable interface"] " " (name i)))))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns tools.graphql.stitch.impl
(ns tools.graphql.stitch.core
"Lacinia 의 스키마를 분할하여 관리할 수 있도록 도와주는 API
특정 경로 하위에 있는 모든 .edn 파일을 읽어서 스키마를 합친 뒤, output 에 해당하는 최종 스키마 파일을 생성합니다.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/graphql/stitch/watch.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns tools.graphql.stitch.watch
(:require [clojure.java.io :as io]
[tools.graphql.stitch.impl :as stitch]
[tools.graphql.stitch.core :as stitch]
[tools.graphql.stitch.watchman :as watchman]))

(def path->schema (atom {}))
Expand Down
9 changes: 5 additions & 4 deletions src/tools/graphql/validators.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns tools.graphql.validators
(:require [clojure.string :as str]
[clojure.tools.logging :as log]
[meander.epsilon :as m]))

(defn graphql-type?
Expand Down Expand Up @@ -54,7 +55,7 @@
{:schema {:unions {?union {:members (m/$ ?t)}}}
:type ?t}
?union)))]
(println "types:" (sort types))
(log/debug "types:" (sort types))
(filter unreachable? types)))

(defn unreachable-input-types [schema]
Expand All @@ -70,7 +71,7 @@
{:schema {:input-objects {?type {:fields {?field {:type (m/$ ?t)}}}}}
:type ?t}
?type)))]
(println "input-types:" (sort types))
(log/debug "input-types:" (sort types))
(filter unreachable? types)))

(defn unreachable-interfaces [schema]
Expand All @@ -83,12 +84,12 @@
{:schema {(m/or :objects :interfaces) {?type {:implements (m/$ ?ifc)}}}
:interface ?ifc}
?type)))]
(println "interfaces:" (sort ifcs))
(log/debug "interfaces:" (sort ifcs))
(filter unreachable? ifcs)))

(comment

(require '[tools.graphql.stitch.impl :refer [read-edn]]
(require '[tools.graphql.stitch.core :refer [read-edn]]
'[clojure.java.io :as io])
(def schema (read-edn (io/file "../../bases/core-api/resources/superschema.edn")))
(def schema (read-edn (io/file (io/resource "unreachable.edn"))))
Expand Down

0 comments on commit 18e9682

Please sign in to comment.