GraphdbStore — Ontotext GraphDB RDF triplestore
Read this page in the documentation
GraphdbStore — Ontotext GraphDB RDF triplestore Overview Ontotext GraphDB is an RDF triplestore that 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 GraphDB repository exposes a query endpoint (/repositories/<repo>) and a separate update endpoint (/repositories/<repo>/statements). Because none of that fits the SQL-shaped Dialect interface, GraphdbStore 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 | 'graphdb' | library | 'fetch' | No canonical driver — HTTP over fetch GraphDB 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 GraphdbStoreOptions 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). The endpoint paths are derived from the repository id — note the query and update paths differ: Getter | Value | Default (repository = 'repo') | ------------- | --------------------------------- | -------------------------------- | queryPath | /repositories/<repo> | /repositories/repo | updatePath | /repositories/<repo>/statements | /repositories/repo/statements | Connection Build a store from connection options and call connect(): All options are optional: Option | Type | Purpose | ------------ | ------------------------- | -------------------------------------------------------------------------- | endpoint | string | Base URL of the GraphDB server. Defaults to http://localhost:7200. | repository | string | Repository id. Defaults to repo. Drives queryPath / updatePath. | 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 queryPath; returns body.results.bindings (or []). | ask | ask(sparql: string): Promise<boolean> | Runs an ASK query against queryPath; returns Boolean(body.boolean). | update | update(sparql: string): Promise<any> | Runs a SPARQL UPDATE against updatePath (/repositories/<repo>/statements); 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/graphdb.test.ts are fully mock-driven: an in-memory SparqlHttpClient is injected via GraphdbStoreOptions.client; it records each request (endpoint path + SPARQL body) and returns a canned SPARQL results envelope. There is no live GraphDB server and no network in the test run. What this proves: name/library are 'graphdb'/'fetch', and paths derive from the repository (/repositories/kb, /repositories/kb/statements). query() POSTs to /repositories/repo and returns results.bindings; ask() returns the boolean; update() POSTs to /repositories/repo/statements. add() emits INSERT DATA { <a> <b> <c> . }; 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 GraphDB 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