Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uuid serialization #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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