Skip to content

Feature/sparql protocol query#117

Merged
dpetran merged 7 commits intomainfrom
feature/sparql-protocol-query
Mar 13, 2025
Merged

Feature/sparql protocol query#117
dpetran merged 7 commits intomainfrom
feature/sparql-protocol-query

Conversation

@dpetran
Copy link
Contributor

@dpetran dpetran commented Feb 28, 2025

This adds support for Accept: application/sparql-results+json headers, making our fluree/query endpoint a SPARQL Protocol compliant endpoint.

I also added support for all query opts being specified as http headers in order to bring feature parity to SPARQL queries. Options specified in headers take precedence over those specified in the query body for FQL.

Related to https://github.com/fluree/core/issues/170

@dpetran
Copy link
Contributor Author

dpetran commented Mar 3, 2025

@dpetran dpetran force-pushed the feature/sparql-protocol-query branch 2 times, most recently from a7ffcf6 to 02f6fd6 Compare March 10, 2025 16:51
@dpetran
Copy link
Contributor Author

dpetran commented Mar 10, 2025

Rebased on main.

Copy link
Contributor

@zonotope zonotope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few suggestions, but looks good.

(defn wrap-header-opts
"Extract options from headers, parse and validate them where necessary, and attach to
request. Opts set in the header override those specified within the transaction or
query. Intended mainly to provide a method of specifying opts for SPARQL queries"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor, but I would drop this last sentence since these opts apply generally.

(fn [{:keys [headers credential/did] :as req}]
(let [{:keys [meta max-fuel identity policy-identity policy policy-class policy-values format output]}
(-> headers
(select-keys ["fluree-meta" "fluree-max-fuel" "fluree-identity" "fluree-policy-identity"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these recognized keys should be defined in a separate top level binding so we can easily reference the recognized header options.


meta (when meta
(case meta
"false" false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's friendlier to run clojure.string/lower-case on this value first.

{:status 400})))))
policy-values (when policy-values
(try (let [pv (json/parse policy-values false)]
(if (sequential? pv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to validate this with malli since we already have a validator for that defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original idea was that the whole query will be run through the coercer/validator down the line, so we just do a very cheap check right here. If it's malformed we'll get a proper error message when the whole query is checked.

@dpetran
Copy link
Contributor Author

dpetran commented Mar 10, 2025

This PR depends on a couple of companion PRs in db, so I'm going to wait on merging this until those have been reviewed:
fluree/db#973
fluree/db#985

dpetran added 6 commits March 12, 2025 10:31
Now we support all query opts as headers prefixed with "Fluree-". By handling them in
middleware we can ensure that we never accidentally forget to override supplied
identities with the verified identity. We don't currently support transaction opts but
this would be a useful place to introduce that support in the future.
@dpetran dpetran force-pushed the feature/sparql-protocol-query branch from 24b13c4 to c28643a Compare March 12, 2025 15:33
@dpetran
Copy link
Contributor Author

dpetran commented Mar 12, 2025

Rebased on main.

@dpetran dpetran merged commit 189201d into main Mar 13, 2025
5 checks passed
@dpetran dpetran deleted the feature/sparql-protocol-query branch March 13, 2025 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants