             [com.wsscode.pathom.test-helpers :as th]
             [com.wsscode.pathom.misc :as p.misc]
             [clojure.core.async :as async :refer [go]]))
+
+(defn index-query? [tx]
+  (try
+    (= (first (ffirst tx)) ::pc/indexes)
+    (catch #?(:clj Throwable :cljs :default) _ false)))
 
 (defn run-parser [{::keys [resolvers query entity foreign error-stack? plugins]}]
   (let [foreign-calls (atom {})


      (testing "fatal error on remote parser"
        (is (= (run-parser
                 {::foreign [{::foreign-id 'remote
                              ::resolvers  [(pc/resolver 'a
                                              {::pc/output [:critical-error]}
                                              (fn [_ _] {:critical-error 4}))]}]
                  ::query   [:critical-error]})
               {:critical-error                 :com.wsscode.pathom.core/reader-error,
                :com.wsscode.pathom.core/errors {[:critical-error] "class clojure.lang.ExceptionInfo: Parser Error - {:foo \"bar\"}"}}))))

    (testing "nested queries"
      (is (= (run-parser

                                                             {::p/wrap-parser
                                                              (fn [parser]
                                                                (fn [env tx]
                                                                  (if (and fatal-error? (not (index-query? tx)))
                                                                    (throw (ex-info "Parser Error" {:foo "bar"})))
                                                                  (swap! foreign-calls update source-id p.misc/vconj tx)
                                                                  (parser env tx)))}))}
