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

Custom scalar :parse is never called #34

Closed
ura1a opened this issue Apr 5, 2017 · 2 comments · Fixed by #36
Closed

Custom scalar :parse is never called #34

ura1a opened this issue Apr 5, 2017 · 2 comments · Fixed by #36
Assignees

Comments

@ura1a
Copy link

ura1a commented Apr 5, 2017

When defining a custom scalar that will be sent as an argument, the :parse function is never called, but :serialize is. Example below will return with an error, but wouldn't if the parsing had been called:

(require
  '[clojure.spec :as s]
  '[com.walmartlabs.lacinia :as g]
  '[com.walmartlabs.lacinia.schema :as schema])

(import
  java.text.SimpleDateFormat
  java.util.Date)

(def date-formatter
  "Used by custom scalar :Date."
  (SimpleDateFormat. "yyyy-MM-dd"))

(defn parse-fn [input]
  (prn "PARSE NEVER CALLED!")
  (.parse date-formatter input))

(defn serialize-fn [output]
  (prn "SERIALIZE CALLED AND WILL THROW BECAUSE NEVER PARSED!")
  (.format date-formatter output))

(def schema
  (schema/compile
    {:scalars {
               :Date {:parse (s/conformer parse-fn)
                      :serialize (s/conformer serialize-fn)}}

     :queries {
               :today {:type :Date
                       :args {:asOf {:type :Date}}
                       :resolve (fn [ctx args v] (:asOf args))}}}))

(g/execute schema "query($asOf: Date!){today(asOf: $asOf)}" {:asOf "2017-04-05"} nil)
@annapawlicka annapawlicka self-assigned this Apr 6, 2017
@annapawlicka
Copy link
Contributor

I'm looking into this

@hlship
Copy link
Member

hlship commented Apr 6, 2017

Which version of the library does this affect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants