Skip to main content
The Sdk facade does not care which engine answers SPARQL. The sparqlEngine option accepts any implementation of SparqlEngineInterface, and the SDK ships one opinionated default: the zero-dependency WazooSparqlEngine (SPARQL 1.1 & 1.2 over any RDF/JS store, with built-in timeout and abort handling). If you need a different engine — Comunica’s federation, actors, or query-planning features, for example — implement the interface yourself. It is a single method. Nobody is locked in. This guide builds a complete Comunica-backed engine, wire by wire, using @comunica/query-sparql-rdfjs-lite directly. It does not rely on any Worlds-provided Comunica adapter.

The contract

SparqlEngineInterface has one method:
  • SparqlRequest carries query, baseIri?, timeoutMs?, and signal? (an AbortSignal the caller uses to cancel an in-flight request).
  • SparqlResponse is one of four shapes: { kind: "select", data }, { kind: "ask", data }, { kind: "construct", data }, or { kind: "void" }.

Install

Comunica and its RDF/JS types are npm packages:

Implement the interface

The engine runs Comunica over the same RDF/JS store the quad facade uses, so imports and SPARQL queries see one consistent dataset.
comunica-sparql-engine.ts

Wire it into a client

Swap the engine in the same way you would configure any other SparqlEngineInterface:
index.ts
The engine handles SELECT, ASK, CONSTRUCT/DESCRIBE, and SPARQL UPDATE, maps binding terms into the standard SPARQL results JSON shape, and honors timeoutMs and signal exactly as the interface documents.

Notes

  • Transactional updates. Comunica writes directly to the store. If your backend needs atomic writes through its own transaction (like the built-in engine’s createTransaction), wrap the read store in a TransactionalRdfjsStore from @worlds/sdk/quad-store, hand that to the engine, and commit on void responses.
  • When to stay on Wazoo. The built-in WazooSparqlEngine is zero-dependency and covers SPARQL 1.1 & 1.2 for in-process RDF/JS stores. Reach for a custom engine when you need capabilities it does not provide — for example Comunica’s federation or actor customization.
  • No SDK changes needed. The adapter lives entirely in your project; the Worlds SDK only defines the interface.