Server.js
Server.js copied to clipboard
Wikidata SPARQL endpoint not working
The Wikidata SPARQL endpoint doesn't work:
Error: Error accessing SPARQL endpoint https://query.wikidata.org/sparql: The endpoint returned an invalid SPARQL results JSON response.
at emitError (/usr/local/lib/node_modules/@ldf/server/node_modules/@ldf/datasource-sparql/lib/datasources/SparqlDatasource.js:74:33)
at Request.<anonymous> (/usr/local/lib/node_modules/@ldf/server/node_modules/@ldf/datasource-sparql/lib/datasources/SparqlDatasource.js:48:28)
at Request.emit (events.js:327:22)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/@ldf/server/node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
I use following configuration:
{
"@id": "ex:mySparqlDatasource",
"@type": "SparqlDatasource",
"datasourceTitle": "Wikidata",
"description": "Wikidata",
"datasourcePath": "wikidata",
"sparqlEndpoint": "https://query.wikidata.org/sparql"
}
Can you inspect the error message of e
to see what is going wrong? (just adding a console.log
should be sufficient) https://github.com/LinkedDataFragments/Server.js/blob/master/packages/datasource-sparql/lib/datasources/SparqlDatasource.js#L48
Same here:
Error accessing SPARQL endpoint https://query.wikidata.org/sparql: The endpoint returned an invalid SPARQL results JSON response.
at emitError (.../.nvm/versions/node/v14.19.0/lib/node_modules/@ldf/server/node_modules/@ldf/datasource-sparql/lib/datasources/SparqlDatasource.js:74:33)
at Request.<anonymous> (.../.nvm/versions/node/v14.19.0/lib/node_modules/@ldf/server/node_modules/@ldf/datasource-sparql/lib/datasources/SparqlDatasource.js:48:28)
at Request.emit (events.js:412:35)
at IncomingMessage.<anonymous> (....nvm/versions/node/v14.19.0/lib/node_modules/@ldf/server/node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:519:28)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1334:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
This problem is caused by two reasons:
(1) Wikidata (Blazegraph) does not support queries with GRAPH. So the following lines that add the GRAPH in the query causes problems on the server. https://github.com/LinkedDataFragments/Server.js/blob/2861f58f4a0af49652618e9161df7dc1ebf6335b/packages/datasource-sparql/lib/datasources/SparqlDatasource.js#L145 https://github.com/LinkedDataFragments/Server.js/blob/2861f58f4a0af49652618e9161df7dc1ebf6335b/packages/datasource-sparql/lib/datasources/SparqlDatasource.js#L160
Furthermore I think this logic is wrong. I believe the correct condition is to add the GRAPH clause only when the quad.graph is defined and it is different from DefaultGraph:
if (quad.graph && quad.graph.termType !== 'DefaultGraph')
(2) The deprecated library request
doesn't know how to handle this request (I don't know exactly why).
Changing the condition as I mentioned and replacing request to the node-fetch
library everything worked like a charm. However, many tests failed exactly because the condition was changed , which imho is wrong.
So the following lines that add the GRAPH in the query causes problems on the server.
Oh, good catch. That looks wrong indeed!
The deprecated library require doesn't know how to handle this request (I don't know exactly why). Changing the condition as I mentioned and replacing request to the node-fetch library everything worked like a charm. However, many tests failed exactly because the condition was changed , which imho is wrong.
We could even go a step further, and use fetch-sparql-endpoint, which would simplify the code quite a bit (and also simplify mocking in the unit tests).
Ok, I will change this and see if I can fix the tests too.
Hi,
I use a simple LDF server encompassing three data sources: an HDT dump, a TTL dump, and an active SPARQL endpoint. But I have the same issue when trying to query my server (or when I try to go an the source's page on the server website, in 'Available Datasets') I get the same error than in this issue.
The SPARQL endpoint I want to query is this one: https://mediag.bunka.go.jp/sparql (This page doesn't work, but the endpoint is working, and is the one queried through this page: https://mediag.bunka.go.jp/madb_lab/lod/sparql/ )
Is there a way to solve this? Did I miss an update?
I use a standard Node/NPM setup of LDF (npm install -g @ldf/server
etc.)
Hi @RdNetwork, sorry for the delay.
The solution is described in the issue, however I still haven't had time to replace the request
library nor to change the tests.