diff --git a/src/alumbra/canonical/literal_value.clj b/src/alumbra/canonical/literal_value.clj index bced96d..257f815 100644 --- a/src/alumbra/canonical/literal_value.clj +++ b/src/alumbra/canonical/literal_value.clj @@ -20,13 +20,13 @@ (throw (IllegalArgumentException. (format - "null value not allowed for expected type '%s'." + "Null value not allowed for expected type '%s'." (type-shorthand t#))))) (when-not ~predicate (throw (IllegalArgumentException. (format - "value does not match expected type '%s': %s" + "Value does not match expected type '%s': %s" (type-shorthand t#) v#))))))) diff --git a/src/alumbra/canonical/variables.clj b/src/alumbra/canonical/variables.clj index 0a0fa67..2b0ebf8 100644 --- a/src/alumbra/canonical/variables.clj +++ b/src/alumbra/canonical/variables.clj @@ -9,19 +9,26 @@ {:keys [alumbra/variable-name alumbra/default-value alumbra/type]}] - (let [v (get variables variable-name ::none) - type (as-type-description type)] - (if (= v ::none) - (if default-value - (resolve-value opts type default-value) - ::none) - (resolve-literal-value opts type v)))) + (try + (let [v (get variables variable-name ::none) + type (as-type-description type)] + (if (= v ::none) + (if default-value + (resolve-value opts type default-value) + (resolve-literal-value opts type nil)) + (resolve-literal-value opts type v))) + (catch IllegalArgumentException t + (throw + (IllegalArgumentException. + (format "Variable '$%s': %s" + variable-name + (.getMessage t)) + t))))) (defn resolve-variables [opts {:keys [alumbra/variables]}] (->> (for [{:keys [alumbra/variable-name] :as variable} variables - :let [variable-value (resolve-variable opts variable)] - :when (not= variable-value ::none)] + :let [variable-value (resolve-variable opts variable)]] [variable-name variable-value]) (into {}) (assoc opts :variables))) diff --git a/test/alumbra/canonicalizer_test.clj b/test/alumbra/canonicalizer_test.clj index 39b4ca5..c279315 100644 --- a/test/alumbra/canonicalizer_test.clj +++ b/test/alumbra/canonicalizer_test.clj @@ -134,11 +134,11 @@ (let [query "query ($q: CatQuery!) { randomCat(q: $q) { name } }"] (is (thrown-with-msg? IllegalArgumentException - #"null value not allowed" + #"Null value not allowed" (canonicalize query {}))) (is (thrown-with-msg? IllegalArgumentException - #"null value not allowed" + #"Null value not allowed" (canonicalize query {"q" nil}))))))) (deftest t-variable-type-mismatch @@ -178,7 +178,7 @@ (testing "nullability mismatch." (is (thrown-with-msg? IllegalArgumentException - #"null value not allowed for expected type 'CatQuery!'" + #"Null value not allowed for expected type 'CatQuery!'" (canonicalize "query ($q: CatQuery!) { randomCat(q: $q) { name }