Added defaultGraph option for scoping queries to a named graph - #180
Merged
Merged
Conversation
thenonameguy
approved these changes
Sep 9, 2026
There was a problem hiding this comment.
🟢 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.defaultGraphand ensures it is not forwarded into the RDF/JS query engine context. - Scopes read queries by wrapping the outer
WHEREpattern inGRAPH <defaultGraph> { ... }and scopes updates/deletes via SPARQLWITH <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.
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. |
Owner
Owner
|
Published in 2.8.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
WHEREclause is wrapped inGRAPH <defaultGraph> { ... }. Nested subqueries inherit the active graph per SPARQL 1.1 semantics, so only the outermost clause needs wrapping.WITH <graph>clause, which scopes both theDELETE``/INSERTtemplates and theWHEREmatch in one construct.When defaultGraph is unset, behavior is unchanged.