diff --git a/src/venia/core.cljc b/src/venia/core.cljc index b313b19..e69b022 100644 --- a/src/venia/core.cljc +++ b/src/venia/core.cljc @@ -49,7 +49,7 @@ (->> (for [[type value] fields] (condp = type :venia/field (name value) - :venia/nested-field (str (name (:venia/nested-field-root value)) "{" (fields->str (:venia/nested-field-children value)) "}"))) + :venia/nested-field (str (name (:venia/nested-field-root value)) (when (:args value) (str "(" (arguments->str (:args value)) ")")) "{" (fields->str (:venia/nested-field-children value)) "}"))) (interpose ",") (apply str))) @@ -119,4 +119,4 @@ [data] (->> (map ->query-str (spec/query->spec data)) (interpose " ") - (apply str))) \ No newline at end of file + (apply str))) diff --git a/src/venia/spec.cljc b/src/venia/spec.cljc index 0f608ba..39ea53d 100644 --- a/src/venia/spec.cljc +++ b/src/venia/spec.cljc @@ -5,7 +5,7 @@ (s/def :venia/query-name keyword?) (s/def :venia/fields (s/coll-of (s/or :venia/field keyword? - :venia/nested-field (s/cat :venia/nested-field-root keyword? :venia/nested-field-children :venia/fields)))) + :venia/nested-field (s/cat :venia/nested-field-root keyword? :args (s/? :venia/args) :venia/nested-field-children :venia/fields)))) (s/def :venia/args (s/keys :opt [:venia/alias])) (s/def :venia/query (s/cat :query :venia/query-name :args (s/? :venia/args) :fields :venia/fields)) (s/def :venia/query-with-fragment (s/cat :query :venia/query-name :args (s/? :venia/args) :fragment-name keyword?)) @@ -33,4 +33,4 @@ (if (invalid? conformed) (ex/throw-ex {:venia/ex-type :venia/spec-validation :venia/ex-explain (s/explain :venia/query-def query)}) - conformed))) \ No newline at end of file + conformed))) diff --git a/test/venia/core_test.cljc b/test/venia/core_test.cljc index 9daa7e1..18de8e8 100644 --- a/test/venia/core_test.cljc +++ b/test/venia/core_test.cljc @@ -33,6 +33,11 @@ query-str "{employee(id:1,active:true){name,address,friends{name,email}}}"] (is (= query-str (v/graphql-query data))))) + (testing "Should create a valid graphql string using params on nested fields." + (let [data [[[:employee {:id 1 :active true} [:name :address [:friends {:id 1} [:name :email]]]]]] + query-str "{employee(id:1,active:true){name,address,friends(id:1){name,email}}}"] + (is (= query-str (v/graphql-query data))))) + (testing "Invalid query, should throw exception" (is (thrown? #?(:clj Exception :cljs js/Error) (v/graphql-query []))))