This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-28
Channels
- # announcements (11)
- # aws (1)
- # babashka (12)
- # babashka-sci-dev (6)
- # beginners (46)
- # biff (15)
- # calva (57)
- # clerk (6)
- # clj-kondo (50)
- # clj-together (1)
- # cljs-dev (14)
- # clojure (89)
- # clojure-doc (1)
- # clojure-europe (36)
- # clojure-nl (1)
- # clojure-norway (50)
- # clojure-spec (4)
- # clojure-uk (1)
- # clojurescript (56)
- # conjure (10)
- # cursive (1)
- # datalevin (2)
- # datomic (3)
- # fulcro (15)
- # honeysql (36)
- # hyperfiddle (74)
- # malli (19)
- # membrane (16)
- # off-topic (33)
- # pathom (6)
- # polylith (2)
- # reagent (14)
- # releases (2)
- # rum (5)
- # shadow-cljs (51)
- # sql (6)
- # tools-build (10)
- # xtdb (6)
Hey team! I am making a graphql-like query language, that looks something like this:
{"users" {"$" {"where" {"bookshelves.books.title" "The Count of Monte Cristo"}}
"bookshelves" {}}
"books" {}}
Here, I have forms
, which have an option-map
, and further children.
What I would want here is a combination of keys
(to say what $
should be), and map-of
, to describe that it can have children.
I wasn't sure how to do this, so the best approach I could think of, was to massage the data into a kind of vector, like:
[["users", {"where" {"bookshelves.books.title" "The Count of Monte Cristo"}}, ["bookshelves", {}, []]],
["books", {}, []]]
So then I could type this vec, like so:
(s/def ::where (s/map-of string? ::triple-model/value))
(s/def ::option-map (s/keys :opt-un [::where]))
(s/def ::form (s/cat
:k string?
:option-map ::option-map
:children (s/coll-of ::inner-form)))
(s/def ::forms (s/coll-of ::form))
Is this the idiomatic way to do things with spec, or would you do it differently?> I wasn't sure how to do this, so the best approach I could think of, was to massage the data into a kind of vector, like: I'm not totally sure I understand what you're trying to do, but massaging data before validation sounds like an anti-pattern.
👍 2
maybe something like:
(s/def ::options (s/keys))
(s/def ::form
(s/coll-of
(s/or
:options (s/tuple #{"$"}
::options)
:sub-form (s/tuple string? ::form))
:into {}))
❤️ 2