 
 (test/defspec generator-makes-valid-queries {:max-size 12 :num-tests 50} (valid-queries-props))
 
+(comment
+  (tc/quick-check 50 (valid-queries-props) :max-size 12))
+
 (defn normalize-mutation-error [x]
   (walk/prewalk
     (fn [x]

           (<!! (async-parser (assoc env ::p/reader [p/map-reader pc/all-async-readers]
                                         ::pc/resolver-dispatch pct/async-resolve-fn) query)))))))

(defn connect-smart-read-props [env]
  (let [props (gen/generate (gen/vector-distinct gen/keyword-ns {:min-elements 8
                                                                 :max-elements 50})
                4)]

                                           ::s.query/gen-query)
                                         (gen/fmap p/remove-query-wildcard))]
                      {:index index :query query})]
      (let [plugins         [p/error-handler-plugin]
            parser          (p/parser {::p/plugins plugins})
            async-parser    (p/async-parser {::p/plugins plugins})
            parallel-parser (p/parallel-parser {::p/plugins plugins})

            env             (assoc env ::p/reader [p/map-reader pc/all-readers]
                                       ::pc/indexes index
                                       ::pc/resolver-dispatch pct/resolve-fn)]
        (= (parser (assoc env ::p/reader [p/map-reader pc/all-readers2]) query)

           (<!! (async-parser (assoc env ::p/reader [p/map-reader pc/all-async-readers2]
                                         ::pc/resolver-dispatch pct/async-resolve-fn) query))

           (<!! (parallel-parser (assoc env ::p/reader [p/map-reader pc/all-parallel-readers]
                                            ::pc/resolver-dispatch pct/async-resolve-fn) query)))))))

#_(test/defspec connect-read-planned {:max-size 10 :num-tests 100} (connect-read-planned-props pct/parser-env))

(comment
  (tc/quick-check 100 (connect-read-planned-props pct/parser-env) :max-size 10))

(comment
  (let [props     (gen/generate (gen/vector-distinct gen/keyword-ns {:min-elements 8
                                                                     :max-elements 100})
                    4)
        query-gen (s.query/make-gen {::s.query/gen-property
                                     (fn [_] (gen/elements props))

                                     ::s.query/gen-params
                                     (fn [_] (gen/map gen/keyword gen/simple-type-printable {:max-elements 3}))}
                    ::s.query/gen-query)
        queries   (take 20 (gen/sample-seq query-gen 16))]
    (def queries queries))

  (let [env          pct/parser-env
        plugins      [pp/profile-plugin]
        parser       (p/parser {::p/plugins plugins
                                :mutate     pt/mutate-fn})

        async-parser (p/async-parser {::p/plugins plugins
                                      :mutate     pt/mutate-fn})
        {:keys [async-reader] :as env} env]

    (doseq [query queries]
      (parser env query))

    #_(criterium/with-progress-reporting
        (criterium/bench
          (doseq [query queries]
            #_(parser env query)
            ((comp <!! async-parser) (assoc env ::p/reader async-reader) query)))))

  (time
    (clojure.test/test-vars [#'profile-speed]))

  (criterium/with-progress-reporting
    (criterium/bench
      (clojure.test/test-vars [#'profile-speed]))))

(comment
  (tc/quick-check 100 (connect-read-props-planned pct/parser-env) :max-size 10))

(comment

  (gen/sample
    (s.query/make-gen (pcg/gen-connect-query {::pc/indexes indexes})
      ::s.query/gen-query))
