Fork me on GitHub
#graphql
<
2020-09-02
>
Vishal Gautam15:09:43

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

hlship16:09:59

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

Vishal Gautam16:09:11

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

hlship22:09:43

Boy, this federation stuff is a little brain bending.