Open renevds opened 3 years ago
Are you certain you're using the latest versions of everything? (how are you invoking this code?) Because if calling graphql-to-sparql.js manually works, then I guess it's a versioning issue.
@rubensworks It would seem I had linked the wrong repo in my "interesting note", I made a correction, it should make more sense now. I'm using GraphQl-LD withinWalder. I will check if versioning is the problem.
We are using the latest version:
"graphql-ld": "^1.4.0",
"graphql-ld-comunica": "^1.2.1",
I've made a failing example
JavaScript:
var Client = require("graphql-ld").Client;
const QueryEngineComunica = require('graphql-ld-comunica').QueryEngineComunica;
main();
async function main() {
// Define a JSON-LD context
const context = {
"@context": {
"type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"owl": "http://www.w3.org/2002/07/owl#",
"label": "rdfs:label",
"comment": "rdfs:comment",
"domain": "rdfs:domain",
"range": "rdfs:range",
"DatatypeProperty": "owl:DatatypeProperty"
}
};
// Create a GraphQL-LD client based on a client-side Comunica engine over 2 sources
const comunicaConfig = {
sources: ["http://localhost:8080/rml.ttl"],
};
const client = new Client({context, queryEngine: new QueryEngineComunica(comunicaConfig)});
// Define a query
const query = `
{
id @single
type (_:DatatypeProperty)
label @single
comment @single
domain @optional
range @optional
}`;
// Execute the query
const {data} = await client.query({query});
console.log(data);
}
Data:
@prefix cc: <http://creativecommons.org/ns#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rmlt: <http://semweb.mmlab.be/ns/rml-target#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix vann: <http://purl.org/vocab/vann/> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix : <http://semweb.mmlab.be/ns/rml#> .
@base <http://semweb.mmlab.be/ns/rml#> .
### http://semweb.mmlab.be/ns/rml#iterator
rml:iterator rdf:type owl:DatatypeProperty ;
rdfs:label "iterator" ;
rdfs:comment "an expression qualified according to the reference formulation specified for pointing to an extract of the source data. "@en ;
rdfs:domain rml:LogicalSource;
rdfs:range xsd:string .
### http://semweb.mmlab.be/ns/rml#reference
rml:reference rdf:type owl:DatatypeProperty ;
rdfs:label "reference" ;
rdfs:comment "A valid expression that selects values from the source data. The reference should confront to the syntax rules/grammar of the specified Reference Formulation. "@en ;
rdfs:domain rr:TermMap;
rdfs:range xsd:string .
### http://semweb.mmlab.be/ns/rml#version
rml:version rdf:type owl:DatatypeProperty ;
rdfs:label "version" ;
rdfs:comment "It defines the version of the reference Formulation used. "@en ;
rdfs:domain rml:LogicalSource;
rdfs:range xsd:string .
### http://semweb.mmlab.be/ns/rml#source
rml:source rdf:type rdf:Property ;
rdfs:label "source" ;
rdfs:comment "qualified name of the source data."@en ;
rdfs:domain rml:LogicalSource .
### http://mmlab.be/rml#query
rml:query rdf:type owl:DatatypeProperty ;
rdfs:comment "A valid query."@en ;
rdfs:domain rml:LogicalSource .
The owl:DatatypeProperty
instances without rdfs:range
are not found, while range
is optional in the query.
The following query:
On the following ttl file:
Returns the correct results. But when adding an
@optional
field. Changing the query to: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: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: