Skip to content

Commit

Permalink
Fix uuid serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Oct 8, 2018
1 parent 0335a25 commit 5da25f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/venia/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/venia/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}}"]
Expand Down

0 comments on commit 5da25f3

Please sign in to comment.