(ns auto-ap.routes.graphql
  (:require [auto-ap.db.companies :as companies]
            [auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
            [auto-ap.entities.companies :as entity]
            [auto-ap.graphql :as ql]
            [clojure.edn :as edn]
            [compojure.core :refer [GET PUT context defroutes
                                    wrap-routes]]))


(defroutes routes
  (wrap-routes
   (context "/graphql" []
            (GET "/" {:keys [query-params]}
                 (let [variables (some-> (query-params "variables")
                                         edn/read-string)]
                   (println variables)
                   {:status 200
                    :body (pr-str (ql/query (query-params "query") variables))
                    :headers {"Content-Type" "application/edn"}})))
   wrap-secure))
