Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 74 #75

Merged
merged 1 commit into from
Mar 27, 2024
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
14 changes: 14 additions & 0 deletions samples/issues.sparqlbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"kind": 1,
"language": "markdown",
"value": "# Using FROM clause yields 'Unknown query type' #74\n\n## Error\nSPARQL error: Unknown query type\n\n## Cause\nThe notebook tries to guess the query type in order to set the HTTP ACCEPT header. Because some stores return a SPO SPARQL JSON result for construct queries and we want turtle.\n\nThe notebook ignores comment and empty lines, so the first non-empty line should be a construct, select, ask, or describe.\n\nThis test is not enough. \n\n## Solution\n\nAt the moment we don't want to parse the query with SPARQLjs. To be store / sparql flavour agnostic. \n",
"metadata": {}
},
{
"kind": 2,
"language": "sparql",
"value": "PREFIX cube: <https://cube.link/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n\nfrom <https://lindas.admin.ch/foen/cube>\nselect *\nWHERE \n{ \n BIND(<https://environment.ld.admin.ch/foen/ubd000502/1> AS ?cube)\n ?cube rdf:type cube:Cube\n}\n",
"metadata": {}
}
]
15 changes: 14 additions & 1 deletion src/extension/endpoint/sparql-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ export function getSPARQLQueryKind(query: string): SPARQLQueryKind {
const linesWithoutPrefix = linesWithoutCommentsAndEmpty.filter(line => {
return !line.startsWith('prefix');
});
const firstLine = linesWithoutPrefix[0];
const lineWithQueryKind = linesWithoutPrefix.filter(line => {
return line.startsWith(SPARQLQueryKind.select) ||
line.startsWith(SPARQLQueryKind.construct) ||
line.startsWith(SPARQLQueryKind.describe) ||
line.startsWith(SPARQLQueryKind.ask) ||
line.startsWith(SPARQLQueryKind.update) ||
line.startsWith(SPARQLQueryKind.load) ||
line.startsWith(SPARQLQueryKind.clear) ||
line.startsWith(SPARQLQueryKind.drop) ||
line.startsWith(SPARQLQueryKind.create) ||
line.startsWith(SPARQLQueryKind.json);
}
);
const firstLine = lineWithQueryKind[0];
if (firstLine !== undefined) {
if (firstLine.startsWith(SPARQLQueryKind.select)) {
return SPARQLQueryKind.select;
Expand Down
Loading