This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-28
Channels
- # announcements (10)
- # aws (1)
- # babashka (12)
- # babashka-sci-dev (6)
- # beginners (46)
- # biff (11)
- # calva (38)
- # clerk (4)
- # clj-kondo (50)
- # cljs-dev (8)
- # cljtogether (1)
- # clojure (82)
- # clojure-doc (1)
- # clojure-europe (35)
- # clojure-nl (1)
- # clojure-norway (46)
- # clojure-spec (3)
- # clojure-uk (1)
- # clojurescript (37)
- # conjure (10)
- # cursive (1)
- # datalevin (2)
- # datomic (3)
- # fulcro (13)
- # honeysql (36)
- # hyperfiddle (73)
- # malli (15)
- # membrane (16)
- # off-topic (28)
- # pathom (6)
- # polylith (2)
- # reagent (14)
- # releases (2)
- # rum (5)
- # shadow-cljs (50)
- # sql (6)
- # tools-build (10)
- # xtdb (6)
#clojure-spec
<
2023-02-28Hey 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.
👍 1
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 {}))
❤️ 1