 (defn get-selection-object-name
   [selection]
   {:post [(not (nil? %))]}
-  (println selection)
-  (:name (second (second selection))))
+  (println "get-selection-object-name: " selection)
+  (let [name (:name (second (second selection)))]
+    (println "get-selection-object-name: name: " name)
+    name))
 
 (defn get-selection-name
   [selection]
   (println "get-selection-name: " selection)
-  (:name (second (second selection))))
+  (let [name (:name (second (second selection)))]
+    (println "get-selection-name: name: " name)
+    name))
 
 (defn get-selection-type [selection]
   (first (second selection)))

(defn get-field-type-from-object-type
  "FIXME"
  [object-type field-selection]
  (let [object-name (get-selection-object-name field-selection)
        type-info (type-system-lookup object-type object-name)]
    (:type type-info)))

(defn resolve-field-on-object
  "FIXME"

  [object-type selection-set visited-fragments]
  (reduce collect-selection [] selection-set))

(comment ; Type kind
  :SCALAR
  :OBJECT
  :INTERFACE
  :UNION
  :ENUM
  :INPUT_OBJECT
  :LIST
  :NOT_NULL)

(def type-map
  {:UserType {:name "User"
              :kind :OBJECT
              :fields {:id {:type :GraphQLString}
                       :name {:type :GraphQLString}}
              :args {}
              :resolve-fn (fn [object] {:id "test"})}})

(def schema
  {:query {:name "Query"
           :kind :OBJECT
           :fields {:user {:type :UserType}}
           :args {:id :GraphQLString}}})

(defn type-system-lookup
  [object-type object-name]
  (case object-type
    :root (case object-name
            "user" {:name "User"
                    :kind :OBJECT
                    :fields {:id {:type :GraphQLString}
                             :name {:type :GraphQLString}}
                    :args {}
                    :resolve-fn (fn [object] {:id "test"})}
            (throw (ex-info (format "Unknown object name: %s." object-name) {})))
    (throw (ex-info (format "Unknown object type: %s." object-type) {}))))
