Support queries with no arguments

Issue Open
Pull requests: 0
Contributors: 0
Level: Intermediate
  • Clojure
Issue Open
Pull requests: 0
Contributors: 0
Level: Intermediate
  • Clojure

On GitHub

spec -> lacinia schema
More info >

Issue posted by: 

Daniel Janus

Description

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:

  • Defining ::no-args as (s/cat) or nil? makes the schema fail to compile with an AssertionError.
  • Defining ::no-args as (s/nilable (s/keys)) makes the schema fail to compile with an NPE.
  • Attaching query as (leona/attach-query (s/nilable ::no-args) ::my-query my-query-resolver) makes the schema fail to compile with an NPE.
  • Defining ::no-args on a two-step basis, as in: (s/def ::no-args-internal (s/keys)) (s/def ::no-args (s/nilable ::no-args-internal)), makes Leona miscompile the schema, resulting in Call to #'com.walmartlabs.lacinia.schema/compile did not conform to spec.
  • enhancement
  • help wanted

Use Open Source Issues to hire or get hired

Other Issues from this company

View all
/
/
    /
    /

      On GitHub

      spec -> lacinia schema
      More info >

      Issue posted by: 

      Daniel Janus

      Use Open Source Issues to hire or get hired

      Support queries with no arguments
      View on GitHub