Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use error formatting fn in query error coercion #79

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
org.slf4j/slf4j-api {:mvn/version "2.0.9"}
metosin/reitit {:mvn/version "0.6.0"}
metosin/muuntaja {:mvn/version "0.6.8"}
metosin/malli {:mvn/version "0.13.0"}
metosin/malli {:git/url "https://github.com/metosin/malli.git"
:git/sha "5211aca498ff7b022c36de4ca713990f5e731a9c" }
ring-cors/ring-cors {:mvn/version "0.1.13"}
com.fluree/db {:git/url "https://github.com/fluree/db.git"
:git/sha "a9cbf41c355ac7415239fa37e6eb3790faad15b0"}}
:git/sha "b3392d5fa9e1e0fff3da435f29f20b168bbfcaf7"}}

:aliases
{:dev
Expand Down
13 changes: 12 additions & 1 deletion src/fluree/http_api/components/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[donut.system :as ds]
[fluree.db.query.fql.syntax :as fql]
[fluree.db.query.history :as fqh]
[fluree.db.validation :as v]
[fluree.db.json-ld.credential :as cred]
[fluree.db.json-ld.transact :as transact]
[fluree.db.util.log :as log]
Expand Down Expand Up @@ -73,7 +74,7 @@

(def FqlQuery (m/schema [:and
[:map-of :keyword :any]
(fql/query-schema [[:from LedgerAlias]])]
(fql/query-schema [])]
{:registry fql/registry}))

(def SparqlQuery (m/schema :string))
Expand Down Expand Up @@ -130,12 +131,21 @@
{:port (ds/ref [:env :http/server :port])
:join? false}}})

(def query-coercer
(rcm/create
{:strip-extra-keys false
:error-keys #{}
:encode-error (fn [explained]
{:error :db/invalid-query
:message (v/format-explained-errors explained nil)})}))

(def query-endpoint
{:summary "Endpoint for submitting queries"
:parameters {:body QueryRequestBody}
:responses {200 {:body QueryResponse}
400 {:body ErrorResponse}
500 {:body ErrorResponse}}
:coercion ^:replace query-coercer
:handler #'ledger/query})

(def history-endpoint
Expand All @@ -144,6 +154,7 @@
:responses {200 {:body HistoryQueryResponse}
400 {:body ErrorResponse}
500 {:body ErrorResponse}}
:coercion ^:replace query-coercer
:handler #'ledger/history})

(defn wrap-assoc-conn
Expand Down
2 changes: 1 addition & 1 deletion src/fluree/http_api/handlers/ledger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
did (assoc :did did)))
query* (if opts (assoc query :opts opts) query)]
{:status 200
:body (deref! (fluree/from-query conn query* {:format format}))}))
:body (deref! (fluree/query-connection conn query* {:format format}))}))
cap10morgan marked this conversation as resolved.
Show resolved Hide resolved

(defhandler history
[{:keys [fluree/conn content-type credential/did] {{ledger :from :as query} :body} :parameters}]
Expand Down