Skip to content

SPARQL endpoint queries empty graph — wire to project ontology #2

@JohnRDOrazio

Description

@JohnRDOrazio

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:

  1. Load the ontology graph in the route handler using the existing _load_graph pattern from quality.py
  2. Add branch resolution (default to project's default branch)
  3. Add authentication/access control
  4. Extract the shared _load_graph helper to avoid duplication
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions