Fork me on GitHub
#graphql
<
2017-10-06
>
eoliphant14:10:57

Hi, I’m trying to add some custom scalars

eoliphant14:10:49

via attach-scalar-transformers per the docs. I’m trying somethign like the following:

:scalars
 {:Date
  {:parse     :date-parse
   :serialize :date-serialize}
but it’s blowing up on the spec validation :clojure.spec.alpha/problems ({:path [:args :schema :scalars 1 :parse], :pred clojure.spec.alpha/spec?, :val :date-parse, ..... Which seems to indicate that the map value should itself be a spec?

eoliphant14:10:54

yes with the exception that my schema is in an EDN file, so trying to follow the guidance under Attaching Scalar Transformers

eoliphant14:10:27

I assumed it would be similar to attaching resolvers

eoliphant14:10:55

The api doc isn’t clearing it up either

eoliphant14:10:47

> In the initial schema, use a keyword for the :parse and :serialize keys, then provide a corresponding value in transform-m.

eoliphant15:10:24

I tried the same pattern

(-> (io/resource "edn/grant-infra-schema.edn")
      slurp
      edn/read-string
      (attach-resolvers {:resolve-persons res/resolve-persons
                         :resolve-person-field res/resolve-person-field
                         :resolve-create-person! res/resolve-create-person!})
      (attach-scalar-transformers {:date-parse types/parse-date
                                   :date-serialize types/serialize-date
                                   :uuid-parse types/parse-uuid
                                   :uuid-serialize types/serialize-uuid})
      schema/compile))

eoliphant15:10:31

will check those out

sashton15:10:33

does types/parse-date return a spec conformer?

eoliphant15:10:13

sort of forgot to do that

eoliphant15:10:35

I did it inline like the docs at first but forgot to do it in the standalone code

eoliphant15:10:54

thanks for your help got it all working 🙂

eoliphant15:10:45

I have another quick question. I’m creating a mutation, i’d like to create a ‘person’ Since I already have person defined as an object, I’d like to pass one an argument but something like this:

:mutations
{:createPerson {:type :person
:args {:arg {:type :person}}
:resolve :resolve-create-person!}}
fails where a quick change to a native scalar type is fine
:mutations
 {:createPerson {:type    :person
                 :args    {:arg {:type String}}
                 :resolve :resolve-create-person!}}

eoliphant15:10:03

nvm, just discovered input objects