Last active
July 13, 2022 19:30
-
-
Save rodolfo42/12b02412058d3f57827a105133779da9 to your computer and use it in GitHub Desktop.
Generate EQL query from sample data (with Pathom)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:deps {com.wsscode/pathom3 {:mvn/version "2022.07.08-alpha"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
https://cljdoc.org/d/com.wsscode/pathom3/2022.07.08-alpha/api/com.wsscode.pathom3.format.eql#data-%3Equery