 
 (declare check-selection-set)
 
+(defn- check-argument [a {:keys [name value] :as arg}]
+  ;; (println "ARG:" arg)
+  (case (:tag value)
+    :variable-reference (update a :var-use conj name)
+    a))
+                       
+(defn- check-arguments [a {argdecls :arguments :as fdecl} {args :arguments :as f}]
+  (if (and (nil? argdecls) (nil? args))
+    a ;; common case
+    (reduce check-argument a args)))
+
 (defn- check-field [tdef field-map a f]
   (case (:tag f)
     :selection-field
     (if-let [fdecl (field-map (:name f))]
-      (let [[errors f] (check-selection-set (base-type (:type fdecl)) a (assoc f :resolved-type (:type fdecl)))]
+      (let [[errors f] (check-selection-set (base-type (:type fdecl)) (check-arguments a fdecl f) (assoc f :resolved-type (:type fdecl)))]
         (-> (assoc a :errors errors)
             (update :vfields conj f)))
       (if (:alias f)

          a (reduce (partial check-field tdef field-map) (assoc a :vfields []) sset)]
      [(:errors a) (assoc def :selection-set (:vfields a))])
    [(:errors a) def]))

(defn- check-definition [a def]
  (case (:tag def)

    (if (contains? (:def-map a) (:name def))
      ;; 5.1.1.1 operation name uniqueness
      (update a :errors err (:name def) "operation with name '%s' is already declared" (:name def))
      (let [[errors def] (check-selection-set (get-root (:schema a) def) (map-var-decls a def) def)]
        (-> (assoc a :errors errors)
            (update :def-map assoc (:name def) def)
            (update :query conj def))))
