This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-07
Channels
- # announcements (5)
- # asami (17)
- # aws (11)
- # babashka (67)
- # beginners (90)
- # calva (13)
- # cider (17)
- # circleci (6)
- # clj-kondo (3)
- # clojure (53)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-germany (3)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (15)
- # clojure-uk (8)
- # clojurescript (41)
- # cursive (7)
- # data-science (6)
- # datomic (8)
- # emacs (10)
- # exercism (1)
- # figwheel-main (2)
- # fulcro (5)
- # graalvm-mobile (97)
- # graphql (1)
- # hyperfiddle (7)
- # inf-clojure (6)
- # interop (4)
- # introduce-yourself (5)
- # jobs (3)
- # kaocha (3)
- # malli (8)
- # meander (8)
- # music (3)
- # nrepl (7)
- # observability (1)
- # off-topic (45)
- # overtone (2)
- # polylith (63)
- # portal (2)
- # re-frame (26)
- # reveal (8)
- # ring (3)
- # shadow-cljs (56)
- # tools-build (5)
- # vim (11)
- # xtdb (8)
In Lacinia, I have a query with an argument of type List without Non-Null type modifier. If I provide argument value null using a query variable I'll get nil from the resolver's argument map as I would have expected. However, if I provide null directly as a query argument value it seems to be coerced to an empty list. For example:
(require '[com.walmartlabs.lacinia.schema :as schema])
(require '[com.walmartlabs.lacinia :as lacinia])
(let [s (schema/compile {:queries {:testQuery {:type '(list Int)
:args {:testArg {:type '(list Int)}}
:resolve (fn [ctx args v]
(println "testArg =" (:testArg args))
(:testArg args))}}})
with-variable "query ($testArg:[Int]) {
testQuery(testArg: $testArg)
}"
without-variable "query {
testQuery(testArg: null)
}"
]
(println "with-variable =" (lacinia/execute s with-variable {:testArg nil} nil))
(println "without-variable =" (lacinia/execute s without-variable nil nil)))
Which prints:
testArg = nil
with-variable = {:data #ordered/map ([:testQuery nil])}
testArg = []
without-variable = {:data #ordered/map ([:testQuery []])}
I'm a bit confused, I would have expected nil from the resolver's argument map in the latter case also. There seems to be tests for both behaviors e.g. former https://github.com/walmartlabs/lacinia/blob/8842b48569c8139c593ecc0136a9d80f353dd975/test/com/walmartlabs/lacinia/custom_scalars_test.clj#L369 and latter https://github.com/walmartlabs/lacinia/blob/8842b48569c8139c593ecc0136a9d80f353dd975/test/com/walmartlabs/lacinia_test.clj#L622.