Skip to content

Added defaultGraph option for scoping queries to a named graph - #180

Merged
karelklima merged 1 commit into
karelklima:mainfrom
csgero:feat/default-graph
Sep 10, 2026
Merged

karelklima merged 1 commit into
karelklima:mainfrom
csgero:feat/default-graph

Conversation

@csgero

@csgero csgero commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #6

Adds a defaultGraph option to Options that scopes all SPARQL LDKit generates — reads and writes alike — to a single named graph, instead of running unscoped against whatever the store's notion is of the default graph.

  • Reads (find/findByIri/count/search): the outer WHERE clause is wrapped in GRAPH <defaultGraph> { ... }. Nested subqueries inherit the active graph per SPARQL 1.1 semantics, so only the outermost clause needs wrapping.
  • update/delete: use SPARQL's WITH <graph> clause, which scopes both the DELETE``/INSERT templates and the WHERE match in one construct.
  • insert/insertData/deleteData: each quad is filled in with defaultGraph only if it doesn't already carry an explicit graph term.

When defaultGraph is unset, behavior is unchanged.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation matches the stated SPARQL scoping approach and is backed by thorough new tests covering the main read/write operations.

Pull request overview

Adds a defaultGraph option to LDKit Options to consistently scope generated SPARQL reads and writes to a specific named graph, addressing issue #6 (named graph constraint for resources).

Changes:

  • Introduces Options.defaultGraph and ensures it is not forwarded into the RDF/JS query engine context.
  • Scopes read queries by wrapping the outer WHERE pattern in GRAPH <defaultGraph> { ... } and scopes updates/deletes via SPARQL WITH <defaultGraph>.
  • Adds comprehensive integration tests covering find/findByIri/count/update/delete/insert/insertData/deleteData behavior under graph scoping, and documents the new option.
File summaries
File Description
tests/lens_graph.test.ts Adds end-to-end tests validating named graph scoping for reads and writes.
library/options.ts Adds defaultGraph to Options and strips it from query engine context resolution.
library/lens/query_builder.ts Implements default graph scoping for query generation (GRAPH wrapper + WITH + quad graph filling).
docs/components/options.md Documents the new defaultGraph option in the Options table.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@karelklima
karelklima merged commit b282a5b into karelklima:main Sep 10, 2026
1 check passed
@karelklima

Copy link
Copy Markdown
Owner

Thanks for the PR, looks good!

This has been a long standing issue, resolving this is really appreciated. I will release the change ASAP.

@karelklima

Copy link
Copy Markdown
Owner

@csgero FYI I am planning to release this together with this PR #179.

@karelklima

Copy link
Copy Markdown
Owner

Published in 2.8.0
https://www.npmjs.com/package/ldkit/v/2.8.0

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.

Support named graph constraint for resources

4 participants