This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-30
Channels
- # beginners (126)
- # boot (2)
- # cider (6)
- # cljs-dev (46)
- # cljsjs (8)
- # clojure (122)
- # clojure-greece (57)
- # clojure-italy (6)
- # clojure-poland (3)
- # clojure-russia (2)
- # clojure-serbia (5)
- # clojure-spec (26)
- # clojure-uk (99)
- # clojurescript (39)
- # cursive (15)
- # datascript (7)
- # datomic (21)
- # dirac (7)
- # duct (1)
- # emacs (19)
- # fulcro (58)
- # garden (4)
- # graphql (15)
- # hoplon (2)
- # immutant (1)
- # instaparse (3)
- # jobs (5)
- # juxt (15)
- # klipse (4)
- # leiningen (2)
- # lumo (52)
- # off-topic (8)
- # om (27)
- # onyx (22)
- # other-languages (3)
- # portkey (2)
- # protorepl (2)
- # re-frame (7)
- # reagent (7)
- # ring (11)
- # rum (7)
- # shadow-cljs (114)
- # spacemacs (20)
- # specter (16)
- # test-check (5)
- # timbre (1)
- # unrepl (43)
- # yada (17)
We use mount 🙂
Say, people who are using lacinia with datomic: how do you handle namespaced keywords in your schemas?
Have seen this, but I'm looking for what people have actually tried: https://github.com/walmartlabs/lacinia/issues/15
@timgilbert: we strip the namespaces on the way out and we determine the namespace in the default resolver by looking at the 3rd argument that's passed in and ask datomic which attribute is unique (which for us always has the form :entity-name/id) and add the namespace of that attribute to the keyword being requested by the resolver
Hey, thanks again @stijn. This approach works incredibly well with the entity API!
in the rare cases that this doesn't work (e.g. reverse refs) we use a custom resolver where we pass the keyword as an argument
this is obviously not safe in every case (you can have name clashes), but we have been developing the datomic schema together with the graphql schema, so that works
(defn default-resolver
[field-name]
^ResolverResult (fn [{:keys [::auth/db]} args v]
(resolve/resolve-as
(if (instance? Entity v)
(get v (keyword->namespaced db v field-name))
(get v field-name)))))
(defn find-object-type
[db v]
(some->> v
(keys)
(filter #(= :db.unique/identity (:db/unique (d/entity db %))))
(first)
(namespace)))
(defn keyword->namespaced
[db v field-name]
(keyword (find-object-type db v) (name field-name)))
Interesting! Thanks @stijn
I finally got around to documenting field resolver factories: http://lacinia.readthedocs.io/en/latest/resolve/attach.html#resolver-factories
This is an occasionally used but handy way to create customized field resolvers directly inside the schema.
Hey, thanks again @stijn. This approach works incredibly well with the entity API!