We’re excited to announce the release of graphql4sparql 0.7.0 — a fast, streaming GraphQL-to-SPARQL rewriting system that brings the power of GraphQL to query SPARQL endpoints and RDF data.
What is graphql4sparql?
graphql4sparql transforms GraphQL queries into SPARQL queries at runtime, enabling you to:
- Query SPARQL endpoints using intuitive GraphQL syntax
- Define custom mappings between GraphQL fields and SPARQL graph patterns
- Leverage RDF’s flexibility while enjoying GraphQL’s declarative querying
- Get JSON responses directly from SPARQL endpoints with streaming performance
The system doesn’t use GraphQL-Java’s execution engine. Instead, it rewrites GraphQL documents into SPARQL queries and post-processes the result sets — a more efficient approach for RDF data.
Key Features
Declarative SPARQL Mapping with GraphQL Directives
graphql4sparql introduces a powerful set of GraphQL directives for mapping to SPARQL patterns, such as:
@prefix— Define namespace prefixes for your queries@pattern— Map GraphQL fields to SPARQL graph patterns@bind— Bind SPARQL expressions to fields (e.g., generating IDs from entity URIs)@one/@many— Control field cardinality for single or multiple values@join— Explicitly define how parent and child fields join@index— Transform query results into indexed JSON objects@array— Flatten sub-fields into a single array (field name becomes array container)
Apache Jena Fuseki Integration
The release includes a fully functional Fuseki plugin that adds a native GraphQL endpoint type to Apache Jena Fuseki server. You can configure it with a simple Turtle configuration file and start querying your RDF data with GraphQL immediately.
See our example setup for a complete working configuration with demo data.
Schema Generator
Generate GraphQL schemas from your RDF data with the graphql4sparql schemagen CLI tool. This removes the need to write SPARQL patterns manually and provides type-safe querying out of the box.
Example Usage
Once the Fuseki plugin is configured, you can query your RDF data with simple GraphQL syntax:
query Works @pretty @debug {
Work {
type
title
creator
}
}
Or use the sophisticated @index directive to group data by subjects and predicates:
query spo {
subjects @pattern(of: "SELECT DISTINCT ?s { ?s ?p ?o } ", to: "s")
@index(by: "?s", oneIf: "true") {
predicates @pattern(of: "?s2 ?p2 ?o2", from: "s2", to: "o2")
@index(by: "?p2", oneIf: "false") {
objects @bind(of: "?o2")
}
}
}
Getting Started
With Apache Jena Fuseki
- Download the graphql4sparql-fuseki-plugin JAR
- Place it in Fuseki’s
run/extradirectory - Configure your Fuseki service with the GraphQl4Sparql endpoint
- Start querying at
http://localhost:3030/your-service/graphql
See our example setup for a complete, working configuration.
Technical Highlights
- Fast streaming: Generates efficient SPARQL queries without breaking them into multiple requests and processes results as they arrive from the SPARQL endpoint
- Bleeding-edge SPARQL features: Leverages cutting-edge SPARQL extensions like
LATERALjoins. Note: These features may not be universally supported across all SPARQL engines - Apache Jena & GraphQL-Java: Built on proven, widely-used libraries
Resources
Acknowledgments
graphql4sparql is developed and maintained by the AKSW research group at the Institute for Applied Informatics.
This work was partially supported by grants from the German Federal Ministry of Transport (BMV) under the program mFund to the MobyDex project (19F2266A).