From 21ee44b3d8addcdb9a2b4d9e96c7610b6b2eb8b8 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Mon, 8 Oct 2018 17:20:38 +0300 Subject: [PATCH] Fix uuid serialization https://github.com/Vincit/venia/pull/39 --- src/venia/core.cljc | 7 ++++++- test/venia/core_test.cljc | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/venia/core.cljc b/src/venia/core.cljc index 9d0bb92..76969c1 100644 --- a/src/venia/core.cljc +++ b/src/venia/core.cljc @@ -2,7 +2,8 @@ (:require [venia.spec :as spec] [clojure.string :as str]) #?(:clj - (:import (clojure.lang IPersistentMap Keyword IPersistentCollection)))) + (:import (clojure.lang IPersistentMap Keyword IPersistentCollection) + (java.util UUID)))) (defprotocol ArgumentFormatter "Protocol responsible for query arguments' formatting to string. @@ -30,6 +31,8 @@ (arg->str [arg] "null") String (arg->str [arg] (str "\"" arg "\"")) + UUID + (arg->str [arg] (str "\"" arg "\"")) IPersistentMap (arg->str [arg] (str "{" (arguments->str arg) "}")) IPersistentCollection @@ -44,6 +47,8 @@ (arg->str [arg] "null") string (arg->str [arg] (str "\"" arg "\"")) + UUID + (arg->str [arg] (str "\"" arg "\"")) PersistentArrayMap (arg->str [arg] (str "{" (arguments->str arg) "}")) PersistentHashMap diff --git a/test/venia/core_test.cljc b/test/venia/core_test.cljc index 5e3dda7..cbd8ba1 100644 --- a/test/venia/core_test.cljc +++ b/test/venia/core_test.cljc @@ -98,6 +98,12 @@ query-str "{employee(id:1,active:true){name,address,friends(id:1){name,email}}}"] (is (= query-str (v/graphql-query data))))) + (testing "Should serialize uuids to strings" + (let [data {:venia/queries [[:employee {:id #uuid "db60501e-26c0-43d0-a4d8-21bd401acf6b"} + [:name]]]} + query-str "{employee(id:\"db60501e-26c0-43d0-a4d8-21bd401acf6b\"){name}}"] + (is (= query-str (v/graphql-query data))))) + (testing "Should create a valid graphql string using params on fields." (let [data {:venia/queries [[:employee [[:name {:isEmpty false}] :address [:friends [:name [:email {:isValid true}]]]]]]} query-str "{employee{name(isEmpty:false),address,friends{name,email(isValid:true)}}}"]