GraphSPARQL is a library that allows you to run a GraphQL queries like
query {
scientist (id: "http://dbpedia.org/resource/Albert_Einstein") {
spouse (filter: "bound(?child_label) && regex(?child_label,'^Lieserl')") {
label (filter: "lang(?_)='en'")
birthDate
child (limit: 2) {
_id
}
}
}
}
against one or more SPARQL endpoints (e.g. DBpedia) returning the following JSON
{
"data": {
"scientist": [
{
"spouse": [
{
"label": [{ "value": "Mileva Marić", "language": "en" }],
"birthDate": [{ "year": 1875, "month": 12, "day": 19, "kind": 0 }],
"child": [
{ "_id": "http://dbpedia.org/resource/Hans_Albert_Einstein" },
{ "_id": "http://dbpedia.org/resource/Lieserl_Einstein" }
]
}
]
}
]
}
}
without having to know almost any SPARQL (except for filtering).
It supports harvesting schemas from RDF(S), OWL, GraphQL and JSON. Each field can belong to a different SPARQL endpoint, even a different named graph within that endpoint. In other words, it fully supports linked data.
There is also support for SPARQL updates through GraphQL mutations. For example, the following mutation (falsely) attributes another child to Einstein:
mutation {
createPerson (id: "http://fakepedia.com/Ente_Einstein", template: {
label: ["'Ente Einstein'@de", "'Canard Einstein'@en"]
birthDate: { year: 1900, month: 2, day: 8 }
}) {_id}
updateScientist (filter: "?label='Albert Einstein'@en") {
child (add: "http://fakepedia.com/Ente_Einstein") {_id}
}
}
The fastest way to get started is by looking at .\example\config.json
, which
is loaded by default, and pulls in most of the DBpedia schema through the
RDF harvester.
Settings for the harvester are per namespace and documented in the
RdfNamespace
class, located in the .\src\Types\Providers\Rdf.cs
file.
.\example\sample1.json
is a small schema sample showcasing most of the
features using the internal GraphSPARQL format. To use it, you have to load
the configuration file .\example\config-sample1.json
in .\src\Startup.cs
.
The API documentation is available in the doc folder.
Downloading the source allows you to run GraphSPARQL in either IIS Express or Kestrel. By running the debugger in Visual Studio an instance of GraphiQL opens in your browser. Give it a couple of seconds to load the schema and then start querying.
Note: Due to the size of the schema, ordinary introspection is disabled.
Instead use the special field _fields
to get a list of all available fields.
This also works for the root objects query
and mutation
.
To get the IRI of an object, use the special field _id
. In filters, you
can refer to either the IRI or the current value with ?_
, to the parent
with ?__parent
, and to any other field with ?fieldName
. Walking down the
class hierarchy in filters can be achieved by concatenating field names with
an underscore, e.g. ?childField_grandChildField
.
The following three prefixes are available in filters:
This implementation is published as "GraphSPARQL: A GraphQL Interface for Linked Data" at "The 37th ACM/SIGAPP Symposium On Applied Computing" (SAC 2022). GraphSPARQL was evaluated against the existing open-source solution HyperGraphQL and Stardog.
The benchmarking script and the used queries are available in the benchmark
folder. For further details consider the paper.