Problem
The SPARQL endpoint (POST /api/v1/search/sparql) always executes queries against an empty RDFLib Graph, returning empty results for every query. The SPARQLQuery schema already defines ontology_id and default_graph fields, but they are completely unused.
Root Cause
- The route handler calls
service.execute_sparql(query) without passing a graph
- The service silently falls back to
Graph() (an empty graph) when no graph is provided
- No ontology is ever loaded for the SPARQL endpoint
Expected Behavior
When ontology_id is provided in the request, the endpoint should load the corresponding project's ontology graph and execute the SPARQL query against it, returning actual results.
Proposed Solution
See docs/plans/sparql-ontology-loading.md for the full implementation plan. Key steps:
- Load the ontology graph in the route handler using the existing
_load_graph pattern from quality.py
- Add branch resolution (default to project's default branch)
- Add authentication/access control
- Extract the shared
_load_graph helper to avoid duplication
- Make
ontology_id required (or validate in the route)
Files to Modify
ontokit/api/routes/search.py — add db/user/branch deps, load graph
ontokit/schemas/search.py — make ontology_id required or validate in route
ontokit/services/search.py — optionally add service-level guard
- Extract shared
_load_graph helper from duplicated pattern
Problem
The SPARQL endpoint (
POST /api/v1/search/sparql) always executes queries against an empty RDFLibGraph, returning empty results for every query. TheSPARQLQueryschema already definesontology_idanddefault_graphfields, but they are completely unused.Root Cause
service.execute_sparql(query)without passing a graphGraph()(an empty graph) when no graph is providedExpected Behavior
When
ontology_idis provided in the request, the endpoint should load the corresponding project's ontology graph and execute the SPARQL query against it, returning actual results.Proposed Solution
See
docs/plans/sparql-ontology-loading.mdfor the full implementation plan. Key steps:_load_graphpattern fromquality.py_load_graphhelper to avoid duplicationontology_idrequired (or validate in the route)Files to Modify
ontokit/api/routes/search.py— add db/user/branch deps, load graphontokit/schemas/search.py— makeontology_idrequired or validate in routeontokit/services/search.py— optionally add service-level guard_load_graphhelper from duplicated pattern