Bridges between GraphQL and RDF

Ruben Taelman

W3C Workshop on Web Standardization for Graph Data 2019 — Berlin, March 5 2019

Bridges between
GraphQL and RDF

Ghent University — imec — IDLab, Belgium

Finding a human by id with GraphQL

GraphQL Query:

{
  human(id: "1000") {
    name
    height
  }
}
          

JSON results:

{
  "data": {
    "human": {
      "name": "Luke Skywalker",
      "height": 1.72
    }
  }
}
          

Finding a human by URI with SPARQL

GraphQL Query:

@prefix schema: <https://schema.org/>.
SELECT ?name ?height WHERE {
  <http//example.org/human/1000> a schema:Person;
                                   schema:name ?name;
                                   schema:height ?height.
}
          

JSON results:

{
  "head": {
    "vars": [ "name" , "height" ]
  },
  "results": {
    "bindings": [
      {
        "name": { "type": "literal" , "value": "Luke Skywalker" },
        "height": { "type": "literal" , "value": "1.72", "datatype": "http://www.w3.org/2001/XMLSchema#double" },
      }
    ]
  }
}
          

GraphQL vs SPARQL

GraphQL SPARQL
Low developer effort
Wide availability of professional development tools
High expressivity
Reusability of queries across datasets

Using GraphQL to query RDF:
different approaches exist

These approaches are incompatible

GraphQL-LD:

{
  human {
    name
    height
  }
}
          

Stardog:

{
  Human {
    name
    height
  }
}
          

 

SELECT ?name ?height WHERE {
  _:b1 ex:human _:human.
  _:human ex:name ?name;
          ex:height ?height.
}
          

 

SELECT ?name ?height WHERE {
  _:b1 a ex:Human;
       ex:name ?name;
       ex:height ?height.
}
          

More differences

→ Annoying for developers if they want to switch between different approaches

A standard way of querying
RDF with GraphQL is needed

Proposal for a plan of action:

  1. Analyze the different aspects of querying RDF with GraphQL.
    (Property paths, joins, ordering, aggregation, ...)
  2. Categorize the existing approaches over these aspects.
  3. Compare the advantages and disadvantages of each aspect approach.
  4. Propose a standard approach and semantics for querying RDF with GraphQL.