From 0439e8d03a544336bf20fb959a4462cfaf093f19 Mon Sep 17 00:00:00 2001 From: Daniel Petranek Date: Tue, 21 Mar 2023 14:14:20 -0500 Subject: [PATCH] allow users to clear the default context for queries --- deps.edn | 2 +- src/fluree/db/api/query.cljc | 6 ++++++ src/fluree/db/query/fql/parse.cljc | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/deps.edn b/deps.edn index 908453551..d0156bd36 100644 --- a/deps.edn +++ b/deps.edn @@ -11,7 +11,7 @@ instaparse/instaparse {:mvn/version "1.4.12"} metosin/malli {:mvn/version "0.9.2"} com.fluree/json-ld {:git/url "https://github.com/fluree/json-ld.git" - :sha "a909330e33196504ef8a5411aaa0409ab72aaa35"} + :sha "010ea42e857eb1845fc390767d649aa539768d6f"} ;; logging org.clojure/tools.logging {:mvn/version "1.2.4"} diff --git a/src/fluree/db/api/query.cljc b/src/fluree/db/api/query.cljc index 78ca9d734..75f9a3a52 100644 --- a/src/fluree/db/api/query.cljc +++ b/src/fluree/db/api/query.cljc @@ -25,6 +25,12 @@ (let [{:keys [context history t commit-details] :as _parsed} (history/history-query-parser query-map) + ;; if context is explicitly nil, preserve it, otherwise fall back to default + context (if (or (contains? query-map :context) + (contains? query-map "@context")) + context + {}) + ;; from and to are positive ints, need to convert to negative or fill in default values {:keys [from to at]} t [from-t to-t] (if at diff --git a/src/fluree/db/query/fql/parse.cljc b/src/fluree/db/query/fql/parse.cljc index e2025dc4a..249b01e94 100644 --- a/src/fluree/db/query/fql/parse.cljc +++ b/src/fluree/db/query/fql/parse.cljc @@ -25,7 +25,12 @@ :context-str :context) db-ctx (get-in db [:schema ctx-key]) - q-ctx (or (:context q) (get q "@context"))] + ;; if context is explicitly set to nil, preserve it + q-ctx (if (or (contains? q :context) + (contains? q "@context")) + (or (:context q) (get q "@context")) + ;; otherwise, fall back to db-ctx + {})] (json-ld/parse-context db-ctx q-ctx))) (defn parse-var-name