Skip to content

Conversation

@dpetran
Copy link
Contributor

@dpetran dpetran commented Oct 14, 2025

SPARQL Federated Query Support

Demonstrate a local/remote join using a SPARQL SERVICE query clause.

Also refactors our http router and adds support for ledger-specific requests.

Ledger specific request support

Now you can address a specific ledger via URL, which is critical for SPARQL SERVICE clauses - you cannot specify custom headers or payloads within the syntax provided, so the URL needs to contain all the information necessary to properly resolve the ledger or graph the query needs.

The ledger-specific requests are available via these paths:

/fluree/ledger/<ledger-alias>/<operation>

Requests with URIs that match this path are rewritten to target the more general endpoint and the ledger-alias is supplied as a fluree-ledger header, and then rerouted. For example, a POST /fluree/ledger/my/ledger/query is rerouted to /fluree/query with the added fluree-ledger: my/ledger header (overriding any supplied fluree-ledger header.

Implementation notes

After looking at #174, I decided to implement similar functionality but with an approach that requires less code and that is more performant. All ledger-specific requests are rerouted transparently by the ledger-specific-handler so that we maintain the same middleware stack and all operations are handled the same, regardless of how they are addressed.

I've chosen the path prefix /fluree/ledger/<ledger-alias> for our ledger-specific routes instead of /fluree/<ledger-alias> in order to avoid "conflicting" routes, which come with a performance penalty.

https://github.com/fluree/core/issues/207
fluree/db#1134

Also add support for SPARQL protocol headers for specifying query graphs.
@dpetran dpetran force-pushed the feature/sparql-federated-query branch from 773f219 to a902fa1 Compare October 15, 2025 03:41
@dpetran dpetran changed the title add ledger-specific query route SPARQL Federated Query support Oct 15, 2025
@bplatz
Copy link
Contributor

bplatz commented Oct 15, 2025

For the reasons I noted in the other PR I don't think this endpoint approach is ideal. It creates inconsistencies between a ledger I visit via a webpage and then how it is used. It also slightly complicates developer experience because I can't just append methods to an api URL but need to reconstruct every method I want to use. It gets away from "Resource" semantics which I think is valuable.

Not sure the breadth of the benefits of our router config this approach makes, and I'm sure there is a balance that has to be weighed, but I'd much rather put extra weight on DX and semantics than chosen library patterns in that balance.

@dpetran
Copy link
Contributor Author

dpetran commented Oct 15, 2025

This approach was because I had to get something working quickly, and after about 90 minutes of faffing trying to get the other approach to support POST queries I binned it and whipped this up. I still think that the simplicity and performance of this approach are worth a lot, but this wasn't intended as a production implementation, just what was necessary for the demo.

We do not currently support dynamic middleware, so there is no need for the ability to
sort it dynamically.
There was an awful lot of indirection in the construction of our router. I've
consolidated all of the routes into one top-level definition so we can see all the
routes at one time.
Requests made to `/fluree/ledger/<ledger-alias/<op>`, where op corresponds to the
operation endpoint suffix (query, update, insert, upsert, transact) are rewritten and
rerouted to the top-level `/fluree/<op>` route handlers. This saves us from having to
manually handle all the work the middleware does while still allowing the
`/<ledger-alias/<op>` route construction instead of the `/<op>/<ledger-alias>` form.
@dpetran dpetran force-pushed the feature/sparql-federated-query branch from 0c8b011 to f761f82 Compare October 21, 2025 16:35
This reverts commit 964542a. Now that the demo is over
we no longer need this task.
Also updates the db dep to fix an issue with SERVICE SILENT.
@dpetran dpetran force-pushed the feature/sparql-federated-query branch from 0b82e23 to 9f754d2 Compare October 21, 2025 21:44
Need to dissoc the :reitit.core/match key in order to properly re-match during routing.
@dpetran dpetran force-pushed the feature/sparql-federated-query branch from 94b4d50 to 67eefe9 Compare October 22, 2025 20:08
@dpetran dpetran force-pushed the feature/sparql-federated-query branch from 67eefe9 to 4ff9245 Compare October 22, 2025 20:10
@dpetran dpetran marked this pull request as ready for review October 22, 2025 20:42
@dpetran dpetran requested a review from a team October 22, 2025 20:42
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.

🍏

@dpetran dpetran merged commit 51d2d0f into main Oct 23, 2025
7 checks passed
@dpetran dpetran deleted the feature/sparql-federated-query branch October 23, 2025 20:38
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.

4 participants