Giter VIP home page Giter VIP logo

graphql-ld.js's Introduction

GraphQL-LD

Build status Coverage Status npm version

GraphQL-LD allows Linked Data to be queried via GraphQL queries and a JSON-LD context.

It is a developer-friendly way to query Linked Data and use the results in a straightforward way.

For example, assuming the following SPARQL query:

SELECT ?id ?starring WHERE {
  OPTIONAL {
    ?id <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Film>;
      <http://dbpedia.org/ontology/starring> ?starring.
    ?starring <http://www.w3.org/2000/01/rdf-schema#label> "Brad Pitt"@en.
  }
}

This could be written in a more compact way in GraphQL:

{
  id
  ... on Film {
    starring(label: "Brad Pitt")
  }
}

And this can be based on the following JSON-LD context:

{
  "@context": {
    "Film": "http://dbpedia.org/ontology/Film",
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "starring": "http://dbpedia.org/ontology/starring"
  }
}

Approach

This library takes a GraphQL-LD query and a JSON-LD context as input, converts it to a SPARQL query, sends the SPARQL query to a SPARQL query engine for execution (local or endpoint), and converts the SPARQL query results into a tree-based structure corresponding to the original GraphQL query.

More information about this approach can be found in our GraphQL-LD article.

Install

$ yarn add graphql-ld

This package also works out-of-the-box in browsers via tools such as webpack and browserify.

Require

import {Client} from "graphql-ld";

or

var Client = require("graphql-ld").Client;

Usage

With a client-side query engine

This requires you to install graphql-ld-comunica: yarn add graphql-ld-comunica.

If you want to use this for Solid apps, have a look at graphql-ld-comunica-solid instead.

import {Client} from "graphql-ld";
import {QueryEngineComunica} from "graphql-ld-comunica";

// Define a JSON-LD context
const context = {
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
};

// Create a GraphQL-LD client based on a client-side Comunica engine over 2 sources
const comunicaConfig = {
  sources: [ "http://dbpedia.org/sparql", "https://ruben.verborgh.org/profile/" ],
};
const client = new Client({ context, queryEngine: new QueryEngineComunica(comunicaConfig) });

// Define a query
const query = `
  query @single {
    label
  }`;

// Execute the query
const { data } = await client.query({ query });

With a remote SPARQL endpoint

This requires you to install graphql-ld-sparqlendpoint: yarn add graphql-ld-sparqlendpoint.

import {Client} from "graphql-ld";
import {QueryEngineSparqlEndpoint} from "graphql-ld-sparqlendpoint";

// Define a JSON-LD context
const context = {
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
};

// Create a GraphQL-LD client based on a SPARQL endpoint
const endpoint = 'http://dbpedia.org/sparql';
const client = new Client({ context, queryEngine: new QueryEngineSparqlEndpoint(endpoint) });

// Define a query
const query = `
  query @single {
    label
  }`;

// Execute the query
const { data } = await client.query({ query });

Examples

Below, you can find a couple examples of GraphQL-LD queries.

If you want more details on what kind of queries you can write, have a look at the README of the GraphQL-to-SPARQL repository.

Finding all available labels

Query:

query @single {
  label
}

Context:

{
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" }
  }
}

Output:

{
  "data": {
    "label": [
      "amateur victory",
      "amateur year",
      "ambasadóir",
      "ambasciatore",
      "ambassadeur",
      "ambassadeur",
      "ambassador",
      ...
    ]
  }
}

Finding all movies Brad Pitt stars in

Query:

{
  id @single
  ... on Film {
    starring(label: "Brad Pitt") @single
  }
}

Context:

{
  "@context": {
    "Film": "http://dbpedia.org/ontology/Film",
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "starring": "http://dbpedia.org/ontology/starring"
  }
}

Output:

{
  "data": [
    {
      "id": "http://dbpedia.org/resource/Ocean's_Eleven",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Favor",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Assassination_of_Jesse_James_by_the_Coward_Robert_Ford",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/True_Romance",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    ...
  ]
}

Finding all Belgian software developers

Query:

{
  softwareName: label @single
  developer @single(scope: all) {
    label
    country(label_en: "Belgium")
  }
}

Context:

{
  "@context": {
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" },
    "label_en": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "developer": { "@id": "http://dbpedia.org/ontology/developer" },
    "country": { "@id": "http://dbpedia.org/ontology/locationCountry" }
  }
}

Output:

{
  "data": [
    {
      "softwareName": "Divinity: Original Sin II",
      "developer": {
        "label": "Larian Studios",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    {
      "softwareName": "Divinity: Original Sin II",
      "developer": {
        "label": "Larian Studios",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    {
      "softwareName": "BioNumerics",
      "developer": {
        "label": "Applied Maths",
        "country": "http://dbpedia.org/resource/Belgium"
      }
    },
    ...
  ]
}

License

This software is written by Ruben Taelman.

This code is released under the MIT license.

graphql-ld.js's People

Contributors

greenkeeper[bot] avatar renovate-bot avatar renovate[bot] avatar rubensworks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-ld.js's Issues

Generating a Graphql Schema

I was looking to create a graphql endpoint along with a graphiql UI. Is there a way to generate a graphql schema from the context or possibly the triple store (ex. the defined SHACL)?

I also opened up a discussion in the Comunica discussion board.

Thanks.

TypeError: source.destroy is not a function when executing query

When executing this query

{ 
  label
  start
  end
}

with this context

{
  "label":  { "@id": "http://www.w3.org/2000/01/rdf-schema#label" },
  "start":  { "@id": "http://schema.org/startDate" },
  "end":    { "@id": "http://schema.org/endDate" }
}

on this Turtle file hosted via a TPF server

@prefix : <http://example.com/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:test a :Test;
  <http://schema.org/endDate> "2019-07-01";
  <http://schema.org/name> "test";
  <http://schema.org/startDate> "2019-06-27";
  rdfs:label "test" .

I get the following error

/Users/pieter/Developer/dhb-kg/node_modules/asynciterator-promiseproxy/node_modules/asynciterator/asynciterator.js:1089
      source.destroy();
             ^

TypeError: source.destroy is not a function
    at PromiseProxyIterator.TransformIterator._end (/Users/pieter/Developer/dhb-kg/node_modules/asynciterator-promiseproxy/node_modules/asynciterator/asynciterator.js:1089:14)
    at Immediate.end (/Users/pieter/Developer/dhb-kg/node_modules/asynciterator-promiseproxy/node_modules/asynciterator/asynciterator.js:263:36)
    at processImmediate (timers.js:634:17)

The following query does work

{ 
  label
  start
}

I used the code in the README at "With a client-side query engine".

Project running in React App

Hi,
Yesterday I used create-react-app for creating a new project to test this amazing project.
But I'm having a problem running it, with a log I can see:

TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation at SparqlEndpointFetcher.fetchCb (<anonymous>:1:883) at SparqlEndpointFetcher.<anonymous> (SparqlEndpointFetcher.js:167) at Generator.next (<anonymous>) at SparqlEndpointFetcher.js:29 at new Promise (<anonymous>) at __awaiter (SparqlEndpointFetcher.js:6) at SparqlEndpointFetcher.fetchRawStream (SparqlEndpointFetcher.js:162) at QueryEngineSparqlEndpoint.<anonymous> (QueryEngineSparqlEndpoint.js:54) at Generator.next (<anonymous>) at QueryEngineSparqlEndpoint.js:27 at new Promise (<anonymous>) at __awaiter (QueryEngineSparqlEndpoint.js:4) at QueryEngineSparqlEndpoint.query (QueryEngineSparqlEndpoint.js:52) at Client.<anonymous> (Client.js:94) at Generator.next (<anonymous>) at fulfilled (Client.js:7)

I did nothing but installing the dependencies in the 'Usage' demo and I got the error.
I don't know if this is something about the webpack configuration or something needed when running a react app.
Have you seen this problem before? Or can you help me?
Thanks!

Support for query variables

It's seems like query variables are not supported yet.

Example:

const Client = require('graphql-ld').Client;
const QueryEngineComunica = require('graphql-ld-comunica').QueryEngineComunica;

// Define a JSON-LD context
const context = {
    "@context": {
        "Film": "http://dbpedia.org/ontology/Film",
        "label": {"@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en"},
        "starring": "http://dbpedia.org/ontology/starring"
    }
};

// Create a GraphQL-LD client based on a client-side Comunica engine over 3 sources
const comunicaConfig = {
    sources: [
        {type: "sparql", value: "http://dbpedia.org/sparql"},
    ],
};
const client = new Client({context, queryEngine: new QueryEngineComunica(comunicaConfig)});

// Define a query
const query = `query MoviesActor($actor: String!){
          id @single
          ... on Film {
            starring(label: $actor) @single
          }
        }`;

const variables = {
    actor: "Angelina_Jolie"
};

// Execute the query
async function ex() {
    const data = await client.query({query: query, variables: variables});
    console.log(data);
}

ex();

Returns the following error:
Error: Undefined variable: actor

@Single not working

@single does not work with the following:

Context:

{
  "title": { "@id": "http://schema.org/name"}
}

Query:

{title @single}

Data:

<http://example.com/resources/Event/example-event> <http://schema.org/name> "My First Academic Event".

Actual result:

[ { title: [ "My First Academic Event" ] } ]

Expected result:

[ { title: "My First Academic Event" } ]

Block for you

The answer to your response

I don't think you're an expert to ask you in JavaScript
If you are an expert, write the correct code
Instead, I had to ask an expert and good person

When I thought to send you a message
Because the code did not work
I thought you were wrong and something you missed
I never thought you were an ignorant person
And you think that yourself is bigger than your real size
I do not need to you and your programs

Block

Error: requires a single source with an rdfjsSource to be present in the context.

    Error: https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-init-sparql/^1.0.0/config/sets/sparql-queryoperators.json#mediatorResolveQuadPattern mediated over all rejecting actors:
    https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-init-sparql/^1.0.0/config/sets/resolve-rdfjs.json#myRdfRdfJsSourceQuadPatternResolver requires a single source with an rdfjsSource to be present in the context.
    Actor https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-init-sparql/^1.0.0/config/sets/resolve-federated.json#myFederatedQuadPatternResolver can only resolve quad pattern queries against a sources array.
    Actor https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-init-sparql/^1.0.0/config/sets/resolve-hypermedia.json#myQuadPatternHypermediaResolver can only resolve quad pattern queries against a single source.
        at /app/node_modules/@comunica/mediator-race/lib/MediatorRace.js:22:32
        at processTicksAndRejections (internal/process/task_queues.js:97:5)

My code:

Captura de tela de 2021-05-05 12-40-46

@optional bugged

The following query:

{
      name @single
      image @single
      readMoreUrl @single
      rml @single
      knowledgeGraph @optional @single
}

On the following ttl file:

@prefix ex: <http://example.com/rmlio/> .
@prefix kees: <http://linkeddata.center/kees/v1#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .

<https://rml.io/usecases/BESOCIAL> a ex:useCase;
  ex:rules "https://github.com/RMLio/social-media-archiving/tree/master/mappings";
  schema:description """<a href=\"https://www.kbr.be/en/projects/besocial/\">BESOCIAL</a> is a cross-institutional research project,
aiming to develop a sustainable strategy for archiving and preserving social media in Belgium.
Heterogeneous social media content, provenance information provided by web archivists as well as preservation metadata enclosed in web archive (WARC) files characterize this use case.
A developed <a href=\"https://github.com/RMLio/social-media-archiving\">open source component</a> integrates RML.io into the existing <a href=\"https://gwu-libraries.github.io/sfm-ui/\">Social Feed Manager (SFM)</a> framework from the George Washington University Libraries.
Therefore, RML.io supports data stewardship tasks in a sustainable open source workflow by mapping heterogeneous data on the fly to a knowledge graph.
This use case uses RML rules in <a href=\"https://rml.io/yarrrml/\">YARRRML</a> syntax which are used by a <a href=\"https://github.com/RMLio/rmlmapper-java-wrapper-js\">javascript wrapper</a> of the <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> to generate the knowledge graph.""";
  schema:image "/img/use-cases/besocial.jpg";
  schema:name "BESOCIAL";
  schema:url "https://github.com/RMLio/social-media-archiving" .

<https://rml.io/usecases/Between%20Our%20Worlds> a ex:useCase;
  ex:rules "https://github.com/BetweenOurWorlds/generation-rules";
  kees:KnowledgeGraph "https://data.betweenourworlds.org/latest";
  schema:description "Between Our Worlds is an initiative to provide metadata information about anime as Linked Open Data. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how the knowledge graph is generated based on the metadata downloaded from a Web API. <a href=\"https://fno.io/\">FnO</a> is used to transform certain aspects of the original data. The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.";
  schema:downloadUrl "http://docs.kitsu.apiary.io/";
  schema:image "/img/use-cases/between-our-worlds.png";
  schema:name "Between Our Worlds";
  schema:url "https://betweenourworlds.org" .

<https://rml.io/usecases/COVID%2019%20Knowledge%20Graph> a ex:useCase;
  ex:rules "https://github.com/GillesVandewiele/COVID-KG/tree/master/rml";
  kees:KnowledgeGraph "https://www.kaggle.com/group16/covid19-literature-knowledge-graph";
  schema:description "This use case generates a <a href=\"https://www.kaggle.com/group16/covid19-literature-knowledge-graph\">knowledge graph</a> from the COVID-19 literature. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how the knowledge graph is generated based on the metadata of the literature. <a href=\"https://rml.io/yarrrml/matey/\">Matey</a> is used to assist in defining the YARRRML rules and the <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.";
  schema:downloadUrl "https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge";
  schema:image "/img/use-cases/covid-19-kg.jpg";
  schema:name "COVID 19 Knowledge Graph";
  schema:url "https://github.com/GillesVandewiele/COVID-KG" .

<https://rml.io/usecases/European%20Union%20Agency%20for%20Railways> a ex:useCase;
  ex:rules "https://github.com/julianrojas87/era-data-mappings/tree/master/rml";
  kees:KnowledgeGraph "http://era.ilabt.imec.be/query/";
  schema:description "The European Union Agency for Railways (ERA) generates a knowledge graph to foster interoperability across their base registry databases which are populated by all EU member states and different actors from the railway domain. This use case uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is automatically converted to RML, to define how the knowledge graph is generated based on different data sources, such as databases, CSV files, XML files, and so on. The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph, which can be explored and queried online.";
  schema:downloadUrl "https://github.com/julianrojas87/era-data-mappings/tree/master/data";
  schema:image "/img/use-cases/era.jpg";
  schema:name "European Union Agency for Railways";
  schema:url "https://www.era.europa.eu/" .

<https://rml.io/usecases/Montolo> a ex:useCase;
  ex:rules "https://github.com/IDLabResearch/Montolo/blob/master/montolo-raw/montolo.yml";
  kees:KnowledgeGraph "https://w3id.org/montolo/ns/montolo/";
  schema:description """<a href=\"https://w3id.org/montolo\">Montolo</a> is a knowledge graph with the aim to provide FAIR metadata of ontologies to support knowledge modeling tasks such as the assessment and reuse of existing ontologies,
currently existing related datasets are <a href=\"https://doi.org/10.5281/zenodo.3343052\">MontoloStats</a> for ontologies and <a href=\"https://doi.org/10.5281/zenodo.3988929\">MontoloSHACLStats</a> for data shapes.
The Montolo Knowledge Graph is manually curated using CSV files on <a href=\"https://github.com/IDLabResearch/Montolo/tree/master/montolo-raw\">GitHub</a> including an alignment with the <a href=\"https://zenodo.org/record/3626676\">Astrea Knowledge Graph</a>.
This use case uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is automatically converted
to RML, to define how the knowledge graph is generated.
The <a href=\"https://github.com/RMLio/rmlmapper-java\">RMLMapper</a> is used to execute the RML rules to generate the knowledge graph.""";
  schema:downloadUrl "https://github.com/IDLabResearch/Montolo/tree/master/montolo-raw";
  schema:image "/img/use-cases/montolo.jpg";
  schema:name "Montolo";
  schema:url "https://w3id.org/montolo" .

<https://rml.io/usecases/Sollicimeer%20%28Inclusion%20in%204D%29> a ex:useCase;
  schema:description "Sollicimeer is a job application platform for people with a learning disability. Companies provide their job applications using a spreadsheet. It uses <a href=\"https://rml.io/yarrrml\">YARRRML</a>, which is converted to RML, to define how knowledge graphs are generated based on the data in the spreadsheet. Next, each knowledge graph is added to the company's <a href=\"https://solidproject.org/\">Solid POD</a>. When a person wants to apply for a job the relevant application information is read from the POD and during the application the information about the person is stored in their personal POD.";
  schema:image "/img/use-cases/sollicimeer.png";
  schema:name "Sollicimeer (Inclusion in 4D)";
  schema:url "http://hellojennywordpress.azurewebsites.net/index.php/uitdaging-2-solliciteren-met-een-leerstoornis/" .

<https://rml.io/usecases/Velopark> a ex:useCase;
  ex:rules "https://github.com/linkedtimeseries/timeseries-server/tree/develop/mappings";
  schema:description "To facilitate information access to bicycle users about parking infrastructure, Fietsberaad, a pro-cycling organization managed by the Flemish government, worked together with local authorities, parking facility owners and operators in Belgium to design common framework for modeling and publishing (live) information of parking facilities. Existing data and interfaces (APIs) were reused and transformed to a common <a href=\"https://velopark.ilabt.imec.be/openvelopark/vocabulary\">semantic data representation</a> using <a href=\"https://github.com/linkedtimeseries/timeseries-server/tree/develop/mappings\">RML rules</a> in YARRRML syntax. Currently more than 30 municipalities across Belgium publish data of 2500+ parkings, made accessible to cyclists <a href=\"https://velopark.be/\">online</a>.";
  schema:image "/img/use-cases/velopark.png";
  schema:name "Velopark";
  schema:url "https://velopark.be/" .

Returns the correct results.
But when adding an @optional field.
Changing the query to:

{
      name @single
      image @single
      readMoreUrl @single
      rml @single
      rules @optional @single
}

Causes the resultset to shrink, the missing results may or may not have the rules field.
When adding another field to this query like so:

{
	  type (_:useCase)
	  name @single
	  image @single
	  readMoreUrl @single
	  rml @single
	  knowledgeGraph @optional @single
	  rules @optional @single
}

The resultset was suddenly back to what was to be expected.
I have had similar behavior on other queries and datasets.

Interesting note:
When using SPARQLAlgebra.js to convert the algebra object made by GraphQL-LD into sparql code and then back into an algebra object (producing a new but very different algebra object, I realise multiple algebra objects can represent the same query, but perhaps this could help towards debugging), the problem was solved.

Context for reference:

{
        "schema": "http://schema.org/",
        "ex": "http://example.com/rmlio/",
        "type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
        "softwareCategory": "ex:softwareCategory",
        "linkSet": "ex:linkSet",
        "slug": "ex:slug",
        "name": "schema:name",
        "description": "schema:description",
        "tools": "ex:content",
        "abstract": "schema:abstract",
        "links": "ex:linkSet",
        "url": "schema:url"
}

Mutation

Any chacne that there will be a (near) future version that includes mutation?

Query with vcard:title returns no results

The following code does not provide results while it should

const context = {
  "@context": {
    "vcard": "http://www.w3.org/2006/vcard/ns#",
    "schema": "http://schema.org/",
    "employee": "schema:employee",
    "title": "vcard:title",
    "KNOWS": "http://knows.proxy.ilabt.imec.be/person/office/#"
  }
};

const comunicaConfig = {
  sources: [
    "http://knows.proxy.ilabt.imec.be/person/office/employees.ttl",
    "https://ben.de-meester.org/#me"
  ],
};
const client = new Client({ context, queryEngine: new QueryEngineComunica(comunicaConfig) });

const query = `
{
  id(_:KNOWS)
  employee {
    id @single
    title @single
  }
}`;

const { data } = await client.query({ query });
console.log(data);

The corresponding use of communica-sparql works

comunica-sparql http://knows.proxy.ilabt.imec.be/person/office/employees.ttl https://ben.de-meester.org/#me 'SELECT * WHERE { ?s <http://schema.org/employee> ?person. ?person <http://www.w3.org/2006/vcard/ns#title> ?title.}'

I tried with other predicates and those work. The issue seems to be related to vcard:title.

@optional not working

@optional does not work with the following:

Context:

{
    "name":  { "@id": "http://schema.org/name" },
    "start":  { "@id": "http://schema.org/startDate" }
  }

Query:

{
  name @optional @single
  start @single
}

Data:

@prefix schema: <http://schema.org/> .
@prefix : <http://example.com/>.

:test1 schema:startDate "2019-03-23"^^schema:Date;
  <http://schema.org/name> "test".

:test2 schema:startDate "2019-03-24"^^schema:Date.

Actual result:

[ { name: 'test', start: '2019-03-23' } ]

Expected result:

[ { name: 'test', start: '2019-03-23' }, { start: '2019-03-24' }  ]

The code to execute the query is reused from the README and the data is hosted via the latest version of ldf-server.

Update README usage example

The usage example 'with a client-side query engine' gives errors.

Fix:

const comunicaConfig = {
  sources: [
    { type: "sparql", value: "http://dbpedia.org/sparql" },
    { type: "file", value: "https://ruben.verborgh.org/profile/" },
    { type: "hypermedia", value: "https://fragments.linkedsoftwaredependencies.org/npm" },
  ],
};

Should be

const comunicaConfig = {
  sources: [
    "http://dbpedia.org/sparql" ,
    "https://ruben.verborgh.org/profile/",
    "https://fragments.linkedsoftwaredependencies.org/npm",
  ],
};

(Linked to issue)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @rdfjs/types *
  • graphql-to-sparql ^2.4.0
  • jsonld-context-parser ^2.1.0
  • sparqlalgebrajs ^3.0.2
  • sparqljson-to-tree ^2.1.0
  • @types/graphql ^14.0.0
  • @types/jest ^27.0.0
  • @types/minimist ^1.2.0
  • coveralls ^3.0.0
  • jest ^27.0.0
  • manual-git-changelog ^1.0.1
  • pre-commit ^1.2.2
  • ts-jest ^27.0.0
  • tslint ^6.0.0
  • tslint-eslint-rules ^5.3.1
  • typescript ^5.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

An in-range update of @types/rdf-js is breaking the build 🚨

The dependency @types/rdf-js was updated from 2.0.9 to 2.0.10.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/rdf-js is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

@optional at root fails with other nested @optionals

Consider the following

const comunicaConfig = {
  sources: [
    'https://raw.githubusercontent.com/RMLio/rmlmapper-java/master/src/main/resources/functions_idlab.ttl',
    'https://raw.githubusercontent.com/RMLio/rmlmapper-java/master/src/main/resources/functions_grel.ttl'
  ],
};

const context = {
    "@context": {
      "fno": "https://w3id.org/function/ontology#",
      "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
      "dcterms": "http://purl.org/dc/terms/",
      "Function": "fno:Function",
      "fnoType": "fnoType",
      "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label" },
      "type": "rdf:type",
      "expects": "fno:expects",
      "predicate": "fno:predicate",
      "first": "rdf:first",
      "rest": "rdf:rest",
      "description": "dcterms:description",
      "name": "fno:name"
    }
  };
  const client = new Client({ context, queryEngine: new QueryEngineComunica(comunicaConfig) });

  const query = `
  query {
    id @single
    type (_:Function)
    description @single @optional
    expects @single @optional {
      first @single {
        id @single
        label @single
        predicate @single
      }
      rest @single @optional {
        first @single {
          id @single
          label @single
          predicate @single
        }
        rest @single @optional {
          first @single {
            id @single
            label @single
            predicate @single
          }
          rest @single @optional {
            first @single {
              id @single
              label @single
              predicate @single
            }
          }
        }
      }
    }
  }`;

  const { data } = await client.query({ query });

This fails, but no error is given.
But it works when I either:

  • Remove @optional from description @single @optional
  • Remove the following at the end of the query:
rest @single @optional {
            first @single {
              id @single
              label @single
              predicate @single
            }
          }

GraphQL-LD version = 1.0.1
Node version = 12.16.1

I did not try it with the latest version of Comunica on the master because I did not get that working locally. So the issue might be fixed already there.

id not working with inline fragments

id does not work with the following:

Context:

{
  "Person":  { "@id": "http://schema.org/Person" }
}

Query:

{
  ... on Person {
    id @single # @single does not affect the output actually.
  }
}

Data:

@prefix schema: <http://schema.org/> .
@prefix : <http://example.com/>.

:test1 a schema:Person.

:test2 a schema:Person.

Actual result:

[ { } ]

Expected result:

[ 
  { "id": "http://example.com/test1" }, 
  { "id": "http://example.com/test2" } 
]

The code to execute the query is reused from the README and the data is hosted via the latest version of ldf-server.

How to know result IRI is literal or named node?

Using the following context and output from the README, how do you if the value of starring in the original data that was queried is a literal or a named node?

{
  "@context": {
    "Film": "http://dbpedia.org/ontology/Film",
    "label": { "@id": "http://www.w3.org/2000/01/rdf-schema#label", "@language": "en" },
    "starring": "http://dbpedia.org/ontology/starring"
  }
}
{
  "data": [
    {
      "id": "http://dbpedia.org/resource/Ocean's_Eleven",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Favor",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/The_Assassination_of_Jesse_James_by_the_Coward_Robert_Ford",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    {
      "id": "http://dbpedia.org/resource/True_Romance",
      "starring": "http://dbpedia.org/resource/Brad_Pitt"
    },
    ...
  ]
}

Context object is changed by the engine

The context object is changed when the engine executes the query. This is important to know if you want to reuse the context for something later on. I would suggest to add this to the docs/README.

QraphQL query variables

Hello.

We are using GraphQL-LD as an interface to our triple store and noticed that variables passed alongside the query are silently ignored. Code responsible for handling then looks to be missing and marked as TODO. Any chance you might implement it?

Auto-generate TypeScript typings

When given a GraphQL-LD query, it should be possible to auto-generate TypeScript typings.

For example:

query MyQuery @single(scope: all) {
  graph
  ... on Collection {
    subset(_:PAGE)
    search @plural {
      template
      variableRepresentation
      mapping @plural {
        variable
        property
      }
    }
  }
}

Example of typings:

interface MyQuery {
  graph: string;
  search: MyQuery_search[];
}
interface MyQuery_search {
  template: string;
  variableRepresentation: string;
  mapping: MyQuery_search_mapping[];
}
interface MyQuery_search_mapping {
  property: string;
  variable: string;
}

Query stops suddenly, but works with comunica-sparql

The following code stops before the query returns the results.

const {Client} = require("graphql-ld");
const {QueryEngineComunica} = require( "graphql-ld-comunica");

main();

async function main() {
// Define a JSON-LD context
const context = {
            "@context": {
              "KNOWS": "https://data.knows.idlab.ugent.be/person/office/#",
              "schema": "http://schema.org/",
              "type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
              "name": "schema:name",
              "description": "schema:description",
              "Tutorial": "schema:HowTo",
              "hasTutorial": {"@reverse": "schema:contributor"},
              "url": "schema:url"
            }
          };

// Create a GraphQL-LD client based on a client-side Comunica engine over 2 sources
const comunicaConfig = {
  sources: [ "https://pieterheyvaert.com/",  "https://data.knows.idlab.ugent.be/person/office/tutorials.ttl", "https://data.knows.idlab.ugent.be/person/office/#" ],
};
const client = new Client({ context, queryEngine: new QueryEngineComunica(comunicaConfig) });

// Define a query
const query = `
{
            id(_:KNOWS)
            hasTutorial {
              type (_:Tutorial)
              description @single @optional
              name @single
              url @single
            }
          }

`;

const { data } = await client.query({ query });
};

When using comunica-sparql with the following details it works.

| software            | version
| ------------------- | -------
| Comunica Init Actor | 1.16.2 
| node                | v14.9.0
| npm                 | 6.14.8
| yarn                | 1.21.1
| Operating System    | linux (Linux 4.15.0-117-generic)

I used the following command.

comunica-sparql https://pieterheyvaert.com/ https://data.knows.idlab.ugent.be/person/office/tutorials.ttl https://data.knows.idlab.ugent.be/person/office/# -f my-query.query -c config.json -i graphql

support for rdf:List

If I have something such as following TTL:

:me :hobbies (:first :second :third)

:first :label "hobby 1"
...

I think I would expect

query {
  id
  hobbies {
    label
  }
}

to return

{
id: ":me",
hobbies: ["hobby 1", ...]
}

Multiple optionals doesn't work

Multiple optionals does not work with the following:

Context:

{
  "address": {"@id": "http://example.org/address"},
  "street": {"@id": "http://example.org/street"},
  "firstname": {"@id": "http://example.org/firstname"},
  "lastname": {"@id": "http://example.org/lastname"}
}

Query:

{  
  firstname @optional
  lastname @optional
  address {
    street
  }
}

Tested with both no data and data, but doesn't make a difference.
Results in this error

(node:8541) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated
(node:8541) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined
    at NestedLoopJoin.close (/Users/pieter/Developer/bug-graphql-ld/node_modules/asyncjoin/join/NestedLoopJoin.js:21:20)
    at NestedLoopJoin.set [as source] (/Users/pieter/Developer/bug-graphql-ld/node_modules/asynciterator/asynciterator.js:990:12)
    at NestedLoopJoin.TransformIterator (/Users/pieter/Developer/bug-graphql-ld/node_modules/asynciterator/asynciterator.js:969:27)
    at new MultiTransformIterator (/Users/pieter/Developer/bug-graphql-ld/node_modules/asynciterator/asynciterator.js:1383:21)
    at new NestedLoopJoin (/Users/pieter/Developer/bug-graphql-ld/node_modules/asyncjoin/join/NestedLoopJoin.js:11:9)
    at ActorRdfJoinNestedLoop.getOutput (/Users/pieter/Developer/bug-graphql-ld/node_modules/@comunica/actor-rdf-join-nestedloop/lib/ActorRdfJoinNestedLoop.js:13:22)
    at ActorRdfJoinNestedLoop.run (/Users/pieter/Developer/bug-graphql-ld/node_modules/@comunica/bus-rdf-join/lib/ActorRdfJoin.js:111:29)
    at ActorRdfJoinNestedLoop.runObservable (/Users/pieter/Developer/bug-graphql-ld/node_modules/@comunica/core/lib/Actor.js:57:29)
    at MediatorRace.mediate (/Users/pieter/Developer/bug-graphql-ld/node_modules/@comunica/core/lib/Mediator.js:80:22)
(node:8541) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 52)
(node:8541) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected result:

[ ]

The code to execute the query is reused from the README and the data is hosted via the latest version of ldf-server.

Example in README doesn't work anymore

Trying the example in the README I get the following error

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: Invalid JSON (Unexpected "s" at position 1 in state STOP)
    at Parser.proto.charError (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/jsonparse/jsonparse.js:90:16)
    at Parser.proto.write (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/jsonparse/jsonparse.js:267:27)
    at Stream.<anonymous> (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:713:22)
    at IncomingMessage.emit (events.js:326:22)
    at addChunk (_stream_readable.js:303:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at IncomingMessage.Readable.push (_stream_readable.js:218:10)
    at HTTPParser.parserOnBody (_http_common.js:132:24)
Emitted 'error' event on Stream instance at:
    at Stream.onerror (_stream_readable.js:754:14)
    at Stream.emit (events.js:314:20)
    at Parser.parser.onError (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/JSONStream/index.js:142:12)
    at Parser.proto.charError (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/jsonparse/jsonparse.js:90:8)
    at Parser.proto.write (/home/pieter/Desktop/temp/20200814-graphqlld/node_modules/jsonparse/jsonparse.js:267:27)
    [... lines matching original stack trace ...]
    at addChunk (_stream_readable.js:303:12)

Tried with installing graphql-ld and graphql-ld-comunica with both yarn (v1.21.1) and npm (v6.14.6), but no difference. Also tried with node versions 12.16.2 and 14.8.0, but also no difference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.