Reputation: 1033
I want to define scalar type such as Token
if I define Token in following format it fails to compile
:scalars
{:Token }
According to https://lacinia.readthedocs.io/en/latest/custom-scalars.html , I need to give parse and seririase functions
So I have modified code below,
:scalars
{:Token
{:parse #(str %)
:serialize #(str %)
}
}
Now I am getting error as " No dispatch macro for: ("
How I can define scalar type token as "scalar Token"?
Upvotes: 1
Views: 315
Reputation: 31
As per this PR :parse and :serialize are no longer clojure.spec conformers. They are simple functions now (version 0.37.0-alpha-1)
Upvotes: 1
Reputation: 1033
Thanks @madstap for answer,in the comment code is not properly highlighted.
In transforms I found that it needs to return spec, following code worked
(def token-parser
(s/conformer
(fn [^String v]
(str v))))
(def token-serializer
(s/conformer
(fn [^String v]
(str v))))
(util/attach-scalar-transformers
{:token-parser token-parser
:token-serializer token-serializer
})
Upvotes: 1
Reputation: 1552
Like nha says in the comments, you can't have function literals in edn files. If you move this to a .clj file it'll work.
If you do want to keep the schema as an .edn file though, there's the function com.walmartlabs.lacinia.util/attach-scalar-transformers
for that.
schema.edn
:
{,,,
:scalars
{:Token {:parse :token-parser
:serialize :token-serializer}}}
schema.clj
(ns foo.schema
(:require
[??? :refer [slurp-edn]]
[com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia.util :as util]))
(def transforms
{:token-parser #(,,,)
:token-serializer #(,,,)})
(defn schema []
(-> (slurp-edn "schema.edn")
(util/attach-scalar-transformers transforms)
;; ... attach resolvers, compile schema, etc
))
Upvotes: 1