 
 (defn make-node-with-node-type
   [node children]
-  (assert (:node-type node) "node-type should not be null for make-node-with-node-type!")
-  (let [node-type (:node-type node)
+  (assert (:graphql-clj/node-type node) "node-type should not be null for make-node-with-node-type!")
+  (let [node-type (:graphql-clj/node-type node)
         make-node-fn (get node-type->make-node-fn node-type)]
     (if make-node-fn
       (make-node-fn node children)
       (println "error: make-node-fn not found!" node-type))))
 
 (defn branch? [node]
-  (println "branch?" (keys node) "node-type:" (:node-type node))
+  (println "branch?" (keys node) "node-type:" (:graphql-clj/node-type node))
   (cond
-    (:operation-definitions node) true
-    (:type-system-definitions node) true
-    (:node-type node) (node-branch? node)
+    (:graphql-clj/operation-definitions node) true
+    (:graphql-clj/type-system-definitions node) true
+    (:graphql-clj/node-type node) (node-branch? node)
     :default (do
                (println "error: don't know how to create branch for node:" node)
                false)))

  (z/zipper branch? children make-node-fn document))

(zv/defvisitor type-field-visitor :pre [n s]
  (if (= :type-field (:node-type n))
    {:node (assoc n :changed "visited")
     :state s}))


;; Zipper

(def ^:private node-type->children-fn
  {:graphql-clj/type-definition :graphql-clj/type-fields
   :graphql-clj/field :graphql-clj/selection-set
   :graphql-clj/operation-definition :graphql-clj/selection-set
   :graphql-clj/operations-definitions :graphql-clj/operation-definition
   :graphql-clj/interface-definition :graphql-clj/fields
   :graphql-clj/input-definition :graphql-clj/fields
   :graphql-clj/statement-root :graphql-clj/children
   :graphql-clj/fragment-definition :graphql-clj/selection-set
   :graphql-clj/inline-fragment :graphql-clj/selection-set})

(def ^:private node-type->make-node-fn
  (let [assoc-field-fn (fn [k]
                         (fn [node children]
                           (println "update node:" node)
                           (assoc node k children :changed "visited")))]
    {:graphql-clj/type-definition (assoc-field-fn :graphql-clj/type-fields)
     :graphql-clj/field (assoc-field-fn :graphql-clj/selection-set)
     :graphql-clj/operation-definition (assoc-field-fn :graphql-clj/selection-set)
     :graphql-clj/operations-definitions (assoc-field-fn :graphql-clj/operation-definition)
     :graphql-clj/interface-definition (assoc-field-fn :graphql-clj/fields)
     :graphql-clj/input-definition (assoc-field-fn :graphql-clj/fields)
     :graphql-clj/statement-root (assoc-field-fn :graphql-clj/children)
     :graphql-clj/fragment-definition (assoc-field-fn :graphql-clj/selection-set)
     :graphql-clj/inline-fragment (assoc-field-fn :graphql-clj/selection-set)}))

(defn node-branch? [node]
  (assert (:graphql-clj/node-type node) "node-type should not be null for checking 'node-branch?'.")
  (let [node-type (:graphql-clj/node-type node)]
    (println "node-branch?:" (contains? (set (keys node-type->children-fn)) node-type))
    (if (contains? (set (keys node-type->children-fn)) node-type)
      true
      (println "error: node has no branch." node-type))))

(defn node->children
  [node]
  (assert (:graphql-clj/node-type node) "node-type should not be null for node->children!")
  (let [node-type (:graphql-clj/node-type node)
        children-fn (get node-type->children-fn node-type)]
    (if children-fn
      (children-fn node)
