graphql4sparql 0.7.0 Released

We’re excit­ed to announce the release of graphql4sparql 0.7.0 — a fast, stream­ing GraphQL-to-SPAR­QL rewrit­ing sys­tem that brings the pow­er of GraphQL to query SPARQL end­points and RDF data.

What is graphql4sparql?

graphql4sparql trans­forms GraphQL queries into SPARQL queries at run­time, enabling you to:

  • Query SPARQL end­points using intu­itive GraphQL syntax
  • Define cus­tom map­pings between GraphQL fields and SPARQL graph patterns
  • Lever­age RDF’s flex­i­bil­i­ty while enjoy­ing GraphQL’s declar­a­tive querying
  • Get JSON respons­es direct­ly from SPARQL end­points with stream­ing performance

The sys­tem does­n’t use GraphQL-Java’s exe­cu­tion engine. Instead, it rewrites GraphQL doc­u­ments into SPARQL queries and post-process­es the result sets — a more effi­cient approach for RDF data.

Key Fea­tures

Declar­a­tive SPARQL Map­ping with GraphQL Directives

graphql4sparql intro­duces a pow­er­ful set of GraphQL direc­tives for map­ping to SPARQL pat­terns, such as:

  • @prefix — Define name­space pre­fix­es for your queries
  • @pattern — Map GraphQL fields to SPARQL graph patterns
  • @bind — Bind SPARQL expres­sions to fields (e.g., gen­er­at­ing IDs from enti­ty URIs)
  • @one / @many — Con­trol field car­di­nal­i­ty for sin­gle or mul­ti­ple values
  • @join — Explic­it­ly define how par­ent and child fields join
  • @index — Trans­form query results into indexed JSON objects
  • @array — Flat­ten sub-fields into a sin­gle array (field name becomes array container)

Apache Jena Fuse­ki Integration

The release includes a ful­ly func­tion­al Fuse­ki plu­g­in that adds a native GraphQL end­point type to Apache Jena Fuse­ki serv­er. You can con­fig­ure it with a sim­ple Tur­tle con­fig­u­ra­tion file and start query­ing your RDF data with GraphQL immediately.

See our exam­ple set­up for a com­plete work­ing con­fig­u­ra­tion with demo data.

Schema Gen­er­a­tor

Gen­er­ate GraphQL schemas from your RDF data with the graphql4sparql schemagen CLI tool. This removes the need to write SPARQL pat­terns man­u­al­ly and pro­vides type-safe query­ing out of the box.

Exam­ple Usage

Once the Fuse­ki plu­g­in is con­fig­ured, you can query your RDF data with sim­ple GraphQL syntax:

query Works @pretty @debug {
  Work {
    type
    title
    creator
  }
}

Or use the sophis­ti­cat­ed @index direc­tive to group data by sub­jects 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")
    }
  }
}

Get­ting Started

With Apache Jena Fuseki

  1. Down­load the graphql4s­par­ql-fuse­ki-plu­g­in JAR
  2. Place it in Fuseki’s run/extra directory
  3. Con­fig­ure your Fuse­ki ser­vice with the GraphQl4Sparql endpoint
  4. Start query­ing at http://localhost:3030/your-service/graphql

See our exam­ple set­up for a com­plete, work­ing configuration.

Tech­ni­cal Highlights

  • Fast stream­ing: Gen­er­ates effi­cient SPARQL queries with­out break­ing them into mul­ti­ple requests and process­es results as they arrive from the SPARQL endpoint
  • Bleed­ing-edge SPARQL fea­tures: Lever­ages cut­ting-edge SPARQL exten­sions like LATERAL joins. Note: These fea­tures may not be uni­ver­sal­ly sup­port­ed across all SPARQL engines
  • Apache Jena & GraphQL-Java: Built on proven, wide­ly-used libraries

Resources

Acknowl­edg­ments

graphql4sparql is devel­oped and main­tained by the AKSW research group at the Insti­tute for Applied Infor­mat­ics.

This work was par­tial­ly sup­port­ed by grants from the Ger­man Fed­er­al Min­istry of Trans­port (BMV) under the pro­gram mFund to the Moby­Dex project (19F2266A).