BlazegraphStore — Blazegraph RDF triplestore

Read this page in the documentation

BlazegraphStore — Blazegraph RDF triplestore Overview Blazegraph is a high-performance RDF triplestore. It speaks the SPARQL 1.1 Protocol over HTTP. It is not a SQL database: there are no rows, no DDL, and no identifier escaping. Data is a set of RDF triples queried and mutated over HTTP. A Blazegraph namespace exposes a single combined SPARQL endpoint (/blazegraph/namespace/<ns>/sparql) used for both queries and updates — the server dispatches on the request content-type. Because none of that fits the SQL-shaped Dialect interface, BlazegraphStore implements the minimal NoSqlStore marker interface (src/nosql/store.ts) — connection lifecycle plus a getClient() escape hatch — and exposes SPARQL query/update operations directly. Identity: Property | Value | --------- | -------------- | name | 'blazegraph' | library | 'fetch' | No canonical driver — HTTP over fetch Blazegraph has no dedicated npm client; it is just a SPARQL/HTTP endpoint. Rather than depend on any package, this store talks to the server with the global fetch. The internal client (createFetchClient) POSTs the SPARQL text with Content-Type: application/sparql-query (queries, Accept: application/sparql-results+json) or application/sparql-update (updates). Injected client BlazegraphStoreOptions accepts a pre-built client implementing the small SparqlHttpClient interface. When provided it is used verbatim and endpoint is ignored; otherwise the internal fetch-based client is built against endpoint at connect() time. This is how the test suite injects a mock (no network). Queries and updates share the same combined path, derived from the namespace: Getter | Value | Default (namespace = 'kb') | ------------- | ---------------------------------------- | --------------------------------- | sparqlPath | /blazegraph/namespace/<ns>/sparql | /blazegraph/namespace/kb/sparql | queryPath | same as sparqlPath | /blazegraph/namespace/kb/sparql | updatePath | same as sparqlPath | /blazegraph/namespace/kb/sparql | Connection Build a store from connection options and call connect(): All options are optional: Option | Type | Purpose | ----------- | ------------------------- | --------------------------------------------------------------------------- | endpoint | string | Base URL of the Blazegraph server. Defaults to http://localhost:9999. | namespace | string | Namespace name. Defaults to kb. Drives the combined sparqlPath. | client | SparqlHttpClient | Pre-built client used verbatim; when set, endpoint is ignored. | headers | Record<string, string> | Extra HTTP headers sent with every internal-client request. | Injected-client form Methods Every SPARQL method resolves the client (throwing ConnectionError if not connected), POSTs via the client, and wraps any client failure in a DatabaseError (carrying the SPARQL text as sql). Lifecycle Method | Signature | Behavior | -------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------- | connect | connect(): Promise<void> | Uses an injected client if provided, otherwise builds the internal fetch client. Idempotent. | disconnect | disconnect(): Promise<void> | Clears the client and connection state. | isConnected | isConnected(): boolean | true only when connected and a client is present. | getClient | getClient(): SparqlHttpClient | Returns the underlying (internal or injected) client. Throws ConnectionError if not connected. | SPARQL surface Method | Signature | Behavior | -------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ | query | query(sparql: string): Promise<any[]> | Runs a SELECT/CONSTRUCT query against the combined endpoint; returns body.results.bindings (or []). | ask | ask(sparql: string): Promise<boolean> | Runs an ASK query against the combined endpoint; returns Boolean(body.boolean). | update | update(sparql: string): Promise<any> | Runs a SPARQL UPDATE against the same combined endpoint; returns the client's response. | add | add(triples: string \| string[], graph?: string): Promise<any> | Issues INSERT DATA { ... }. Arrays are joined with newlines; when graph is given, wraps the body in GRAPH <g> { ... }. | drop | drop(graph?: string): Promise<any> | Issues DROP GRAPH <g> when a graph is given, else DROP ALL. | Example Verification status Unit / mock-verified only. The tests in tests/nosql/blazegraph.test.ts are fully mock-driven: an in-memory SparqlHttpClient is injected via BlazegraphStoreOptions.client; it records each request (endpoint path + SPARQL body) and returns a canned SPARQL results envelope. There is no live Blazegraph server and no network in the test run. What this proves: name/library are 'blazegraph'/'fetch', and the combined queryPath/updatePath derive from the namespace (/blazegraph/namespace/wiki/sparql). query() and update() both POST to /blazegraph/namespace/kb/sparql; query() returns results.bindings, ask() returns the boolean. add() emits INSERT DATA { ... }; drop() emits DROP GRAPH <urn:g> / DROP ALL. Lifecycle: connect/disconnect (idempotent), getClient() returns the injected client, and ConnectionError before connect(). Error wrapping: client failures surface as DatabaseError. What this does not prove: live execution against a real Blazegraph server. The request shape is verified against the SPARQL 1.1 Protocol contract, but end-to-end execution over the wire has not been exercised here. Related reading All data stores — the full catalogue, grouped by purpose Database types — where this sits among the 22 categories