Skip to content

Added DKG SPARQL query tool and minor code cleanup#13

Merged
zsculac merged 2 commits intomainfrom
feature/add-query-tool
Jan 30, 2026
Merged

Added DKG SPARQL query tool and minor code cleanup#13
zsculac merged 2 commits intomainfrom
feature/add-query-tool

Conversation

@Jurij89
Copy link
Contributor

@Jurij89 Jurij89 commented Dec 10, 2025

Added DKG SPARQL query tool to plugin-dkg-essentials, fixed the concurrency issue when running in dev mode, and made some general code cleanup in the plugin-dkg-essentials.

…ing in dev mode, and made some general code cleanup in the plugin-dkg-essentials.

// Only allow query types supported by the DKG node
const allowedQueryTypes = ["SELECT", "CONSTRUCT"];
if (!allowedQueryTypes.includes(parsed.queryType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could normalize the case here to make sure queryTyoe is always in uppercase. So something like this:

if (!allowedQueryTypes.includes(parsed.queryType?.toUpperCase()))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sparqljs parser already returns queryType in uppercase (it's part of the library's contract). So if you parse "select * where { ?s ?p ?o }", the parser returns { queryType: "SELECT", ... } - but I it doesn't hurt to add another check in case the library changes.

}

// Use validated query type
const queryType = validation.queryType || "SELECT";
Copy link
Contributor

Choose a reason for hiding this comment

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

if query passes validation, queryType should always be set so this fallback might hide potential bugs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, this has been updated.

Comment on lines 199 to 208
const queryResult = await ctx.dkg.graph.query(query, queryType);

const resultText = JSON.stringify(queryResult, null, 2);

return {
content: [
{
type: "text",
text: `✅ Query executed successfully\n\n**Results:**\n\`\`\`json\n${resultText}\n\`\`\``,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use JSON.stringify when a CONSTRUCT query is called since construct returns a raw string of N-triples?

Copy link
Contributor Author

@Jurij89 Jurij89 Jan 29, 2026

Choose a reason for hiding this comment

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

Good catch, updated so that SELECT and CONSTRUCT queries are handled differently based on their output format. Tested it out and works well now.

@zsculac zsculac merged commit 8604fd8 into main Jan 30, 2026
6 of 9 checks passed
@zsculac zsculac deleted the feature/add-query-tool branch January 30, 2026 08:44
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.

2 participants