30 lines
1.2 KiB
Clojure
30 lines
1.2 KiB
Clojure
(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]
|
|
[buddy.auth :refer [throw-unauthorized]]
|
|
[clojure.edn :as edn]
|
|
[compojure.core :refer [GET PUT context defroutes
|
|
wrap-routes]]))
|
|
|
|
|
|
(defroutes routes
|
|
(wrap-routes
|
|
(context "/graphql" []
|
|
(GET "/" {:keys [query-params] :as r}
|
|
(when (= "none" (:role (:identity r)))
|
|
(throw-unauthorized))
|
|
|
|
(try
|
|
(let [variables (some-> (query-params "variables")
|
|
edn/read-string)]
|
|
{:status 200
|
|
:body (pr-str (ql/query (:identity r) (query-params "query") variables ))
|
|
:headers {"Content-Type" "application/edn"}})
|
|
(catch Exception e
|
|
{:status 400
|
|
:body (pr-str {:data (merge {:message (.getMessage e)} (ex-data e))})
|
|
:headers {"Content-Type" "application/edn"}}))))
|
|
wrap-secure))
|