Fork me on GitHub
#graphql
<
2017-11-30
>
stijn11:11:49

i'm using lacinia with integrant instead of component

andrewtropin12:11:02

We use mount 🙂

timgilbert20:11:58

Say, people who are using lacinia with datomic: how do you handle namespaced keywords in your schemas?

timgilbert20:11:33

Have seen this, but I'm looking for what people have actually tried: https://github.com/walmartlabs/lacinia/issues/15

stijn20:11:33

@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

timgilbert21:12:49

Hey, thanks again @stijn. This approach works incredibly well with the entity API!

stijn20:11:16

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

stijn20:11:23

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

stijn20:11:33

(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)))))

stijn20:11:34

(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)))

stijn20:11:39

something like that

timgilbert21:11:17

Interesting! Thanks @stijn

hlship23:11:07

I finally got around to documenting field resolver factories: http://lacinia.readthedocs.io/en/latest/resolve/attach.html#resolver-factories

hlship23:11:42

This is an occasionally used but handy way to create customized field resolvers directly inside the schema.