Skip to content

Instantly share code, notes, and snippets.

@rodolfo42
Last active July 13, 2022 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodolfo42/12b02412058d3f57827a105133779da9 to your computer and use it in GitHub Desktop.
Save rodolfo42/12b02412058d3f57827a105133779da9 to your computer and use it in GitHub Desktop.
Generate EQL query from sample data (with Pathom)
{:deps {com.wsscode/pathom3 {:mvn/version "2022.07.08-alpha"}}}
(require '[com.wsscode.pathom3.format.shape-descriptor :as shape-descriptor])
(binding [*print-namespace-maps* false]
(let [data (clojure.edn/read-string (slurp "example.edn")) ;; replace if your data structure is elsewhere
shape (shape-descriptor/data->shape-descriptor data)]
(prn (clojure.walk/postwalk
(fn [x]
(if (map? x)
(->> x
(filter #(= 0 (count (val %))))
(mapv first)
(concat (mapv (fn [[k v]] {k v}) (remove #(= 0 (count (val %))) x)))
vec)
x))
shape))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment