Closed aew closed 7 years ago
I prefer keyword keys in map as well. However there it is no common naming convention between GraphQL and Clojure.
GraphQL uses UpperCamelCase for Type and lowerCamelCase for field and argument.
I like to use :dash-separated-lowercase-word as keyword in Clojure.
Don't know what is the good way to convert them back and forth. So I left it open.
I am fine to switch over to use keyword and make it consistent in graphql-clj.
I discovered this as well, for the life of me I could not understand why my GraphQL queries were not working with query variables. It looks like compojure
would parse the request query variables into keyword keys.
In the CIDER repl I found could get the expected query result using string keywords, for example,
bk1.core> (bk1.graphql/execute q {:id 1})
"Warning: the result of graphql-clj.validator/validate-statement should be passed to execute instead of a statement string"
{:data {"account" nil}}
bk1.core> (bk1.graphql/execute q {"id" 1})
"Warning: the result of graphql-clj.validator/validate-statement should be passed to execute instead of a statement string"
{:data {"account" {"id" 1, "name" "Test One"}}}
bk1.core>
So in the ring handler I used clojure.walk/stringify-keys
on the variables from the request.
(defroutes routes
(POST "/graphql" [schema query variables :as request]
(response/response
(try
(graphql/execute query (clojure.walk/stringify-keys variables))
(catch Throwable e
(println e))))))
Thanks @carld. Added clojure.walk/stringify-keys in executor, so it will accept keyword key as variable name.
In Clojure, keyword keys would be more idiomatic than string keys in a map. graphql-clj seems to prefer string keys, and keyword keys on not consistently supported.