retro / graphql-builder

GraphQL client library for Clojure and ClojureScript
MIT License
184 stars 15 forks source link

Missing arg enum with boolean false #13

Closed ntestoc3 closed 4 years ago

ntestoc3 commented 4 years ago

When the arg value is false, the constructed query string loses the false value.

The following example code:

((get-in (graphql/query-map
          (parse "query Foo {
  productList(someArg: moo, otherArg: false) {
    name
  }
}"))
         [:query :foo] ))
;; => {:graphql
;;     {:operationName "Foo",
;;      :query
;;      "query Foo {\n  productList(someArg: moo, otherArg: ) {\n    name\n  }\n}",
;;      :variables {}},
;;     :unpack #function[clojure.core/identity]}
ntestoc3 commented 4 years ago

Modifying the graphql-builder.generators.shared/argument-value function can solve this problem:

(with-redefs-fn {#'graphql-builder.generators.shared/argument-value
                 (fn [argument config]
                   (let [value (:value argument)
                         variable-name (:variable-name argument)]
                     (cond
                       (not (nil? value)) (graphql-builder.generators.shared/argument-value-value argument)
                       (not (nil? variable-name)) (str "$" (graphql-builder.generators.shared/add-var-prefix (:prefix config) variable-name)))))
                 }
  #((get-in (graphql/query-map
             (parse "query Foo {
  productList(someArg: moo, otherArg: false) {
    name
  }
}"))
            [:query :foo] )))
;; => {:graphql
;;     {:operationName "Foo",
;;      :query
;;      "query Foo {\n  productList(someArg: moo, otherArg: false) {\n    name\n  }\n}",
;;      :variables {}},
;;     :unpack #function[clojure.core/identity]}
retro commented 4 years ago

@ntestoc3 Thank you for reporting this. It's fixed in 17cec0f37f5f3f203a13cff186748ba2a178e204 and new version (0.1.10) is pushed to Clojars