graphql

v 2020-09-02T15:53:43.002Z

Hello GraphQL/Lacinia developers, whats the best approach to coerce inputs for graphql endpoint. I need to coerce string to uuid. so that datomic can understand it. Currently I wrote his wrapper, which I wrap for each handler where id is used. But this feels hacky. Any tips

(defn uuid-wrapper [handler]
  (fn [context {:keys [id] :as args} entity]
    (if id
      (if (uuid? (u/str->uuid id))
        (let [args (assoc args :id (u/str->uuid id))]
          (handler context args entity))
        nil)
      (handler context args entity))))

hlship 2020-09-02T16:06:59.002500Z

You could define a UUID scalar type which could convert input strings to UUIDs and vice-versa.

v 2020-09-02T16:15:11.003300Z

Not sure how I can do that. Can you please provide an example 🙂

v 2020-09-02T16:27:42.003500Z

Nevermind, found the doc https://lacinia.readthedocs.io/en/latest/custom-scalars.html

hlship 2020-09-02T22:39:43.003900Z

Boy, this federation stuff is a little brain bending.