Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Templated queries now also work for queries containing multiple occurrences of a template variable (#164).
- Works when served from any base URL including a path (e.g. `https://www.example.com/your/preferred/path`) (#165).

## [1.4.0] - 2024-10-02
Expand Down
17 changes: 17 additions & 0 deletions main/public/queries/musicians_variables_double.rq
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PREFIX schema: <http://schema.org/>

SELECT ?name ?sameAs_url WHERE {
{
?list schema:name ?listTitle;
schema:name ?name;
schema:genre $genre;
schema:sameAs ?sameAs_url;
}
UNION
{
?list schema:name ?listTitle;
schema:name ?name;
schema:genre $genre;
schema:sameAs ?sameAs_url;
}
}
20 changes: 20 additions & 0 deletions main/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@
]
}
},
{
"id": "9012",
"queryGroupId": "c-tst",
"queryLocation": "musicians_variables_double.rq",
"name": "A templated query about musicians (double results)",
"description": "This query tests whether a template variable is expanded more than once. If it works, this query will return all results twice.",
"icon": "MusicNoteIcon",
"variables": {
"genre": [
"\"Romantic\"",
"\"Baroque\"",
"\"Classical\""
]
},
"comunicaContext": {
"sources": [
"http://localhost:8080/example/favourite-musicians"
]
}
},
{
"id": "9020",
"queryGroupId": "c-tst",
Expand Down
2 changes: 1 addition & 1 deletion main/src/dataProvider/SparqlDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function buildQueryText(query) {
function replaceVariables(rawText, variables) {
for (const [variableName, variableValue] of Object.entries(variables)) {
// do not surround with double quotes here; add double quotes in the input if needed!
rawText = rawText.replace("$" + variableName, variableValue);
rawText = rawText.replaceAll("$" + variableName, variableValue);
}

return rawText;
Expand Down
15 changes: 15 additions & 0 deletions test/cypress/e2e/templated-query.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ describe("Templated query", () => {
// cy.get('button').contains('Query').should("not.exist"); -> useless if we add a 'new query' button
});

it("With 1 variables, double expansion", () => {
cy.visit("/");
cy.contains("For testing only").click();
cy.contains("A templated query about musicians (double results)").click();

cy.get('form').within(() => {
cy.get('#genre').click();
});
cy.get('li').contains('Romantic').click();

cy.get('button').contains('Query').click();
cy.contains("Finished in:");
cy.get('.column-name').find('span').should("have.length", 2);
});

it("With 2 variables", () => {
cy.visit("/");
cy.contains("For testing only").click();
Expand Down