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

Wikidata SPARQL endpoint not working #152

Open
brechtvdv opened this issue Jun 9, 2022 · 7 comments
Open

Wikidata SPARQL endpoint not working #152

brechtvdv opened this issue Jun 9, 2022 · 7 comments

Comments

@brechtvdv
Copy link

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"
    }
@rubensworks
Copy link
Member

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

@marcelomachado
Copy link
Contributor

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)

@marcelomachado
Copy link
Contributor

marcelomachado commented Nov 8, 2022

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.

if (!quad.graph || quad.graph.termType !== 'DefaultGraph') {
if (!quad.graph || quad.graph.termType !== 'DefaultGraph')

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.

@rubensworks
Copy link
Member

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).

@marcelomachado
Copy link
Contributor

Ok, I will change this and see if I can fix the tests too.

@RdNetwork
Copy link

RdNetwork commented Apr 17, 2023

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.)

@marcelomachado
Copy link
Contributor

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.

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

No branches or pull requests

4 participants