walmartlabs / lacinia

GraphQL implementation in pure Clojure
http://lacinia.readthedocs.io/en/latest/
Other
1.82k stars 162 forks source link

Providing a scalar value to an argument of type non-null list ends up with the scalar values wrapped as lists #431

Closed duddlf23 closed 1 year ago

duddlf23 commented 2 years ago

A bug occurs when dynamically inserting scalar variables into arguments of non-null list type.

;; example
(let [schema (schema/compile {:queries
                              {:echo
                               {:type :String
                                :args {:input {:type '(non-null (list (non-null Int)))}}
                                :resolve (fn [_ args _]
                                           (str "Echo: " (:input args)))}}})]
  (execute schema "query($n1 : Int!, $n2 : Int!) { echo(input: [$n1, $n2]) }" {:n1 1 :n2 2} nil))

;; => {:data {:echo "Echo: [[1] [2]]"}} (unexpected, but current results)
;; => {:data {:echo "Echo: [1 2]"}} (expected)

This is caused by one less stripping of the argument-definition in the process-dynamic-argument method (when dispatch value is :array). In the case of (non-null (list T)) argument type, there is one more level of :kind :non-null in argument-definition, so it has to be stripped twice.

I modified the process-dynamic-argument method so that the correct value is provided to the argument of non-null list type and added tests.

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.