WorksHub / leona

spec -> lacinia schema
Eclipse Public License 1.0
36 stars 17 forks source link

Support queries with no arguments #12

Closed nathell closed 5 years ago

nathell commented 5 years ago

Currently, doing:

(s/def ::no-args (s/keys))
(s/def ::result string?)
(s/def ::my-query (s/keys :req-un [::result]))

(defn my-query-resolver [ctx args value] 
  {:result "hello"})

(def schema
  (-> (leona/create)
      (leona/attach-query ::no-args ::my-query my-query-resolver)
      (leona/compile)))

produces a schema that compiles successfully. However, trying to query it:

(leona/execute schema "{ my_query { result } }")

bombs out with a spec failure: The query input didn't conform to the internal spec: ::no-args. This is because Lacinia passes nil arguments to niladic query resolvers, and nil obviously doesn't validate against ::no-args.

Some attempted workarounds that kaboom in all sorts of interesting ways:

devurandom commented 5 years ago

Did you try using (s/nilable map?)? That should have similar semantics to (s/nilable (s/keys)), as the latter does not make any assertion on keys not listed, i.e. it also refers to a map with arbitrary keys.