Skip to content

Wikidata SPARQL endpoint not working #152

Open

Description

@brechtvdv

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"
    }

Activity

  1. rubensworks commented on Jun 9, 2022

    @rubensworks
    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

  2. marcelomachado commented on Aug 10, 2022

    @marcelomachado
    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)
    
  3. marcelomachado commented on Nov 8, 2022

    @marcelomachado
    Contributor

    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.

  4. rubensworks commented on Nov 8, 2022

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

  5. marcelomachado commented on Nov 8, 2022

    @marcelomachado
    Contributor

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

  6. RdNetwork commented on Apr 17, 2023

    @RdNetwork

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

  7. marcelomachado commented on Sep 5, 2023

    @marcelomachado
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions