graphdb-js
This module is a convenient wrapper for GraphDB's REST API. Large parts are still to be implemented, however, it's already providing key features like SPARQL querying and document uploading.
Disclaimer
This module was only tested against the API of GraphDB-free version 8.7.2.
Usage
Install this package via npm:
npm i graphdb-js
Initialization
const GraphDB = ; let graphdb = hostname: "localhost" repository: "test";
In theory you can pass on everything according to the http module's configuration, since
these parameters are used by this exact module.
However, it is recommended to stick to the one's listed, since you might override stuff that's
already correctly configured for you, also there's some options that are not directly related to
http
like the repository
field, which is required.
For instance if you pass {method: "GET"}
you'll override SPARQL query request parameter's, such
that they won't work anymore, since they work with POST requests only.
Parameters you might actually be required to modify are listed in the table below.
Parameter | Datatypes | Description |
---|---|---|
hostname | String | Name of the host |
port | Integer | The port the GraphDB instance listens on |
repository | String | The repository you want to connect to |
Authorization
Non-free versions of GraphDB also support authorization techniques, which might require you, depending on the repository setup, to perform a login.
/* TODO: not possible yet since I did not have any repo to test this on */
Issuing SPARQL Queries
The following was taken from the w3.org SPARQL specification page. Assuming GraphDB follows this specification, every valid SPARQL query should be possible using this client.
SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by expressions, extensible value testing, and constraining queries by source RDF graph. The results of SPARQL queries can be result sets or RDF graphs.
SELECT Queries
const select = "select * where { ?s ?p ?o . }"; graphdbQuery;
UPDATE Queries
const insert = "insert data { <http://purl.org/dc/elements/1.1/title> <http://purl.org/dc/elements/1.1/title> \"Fundamentals of Compiler Construction\" .}"; graphdbQuery;
Upload RDF Files
When it comes to uploading files, there are different ways to do that. Either as strings or by URL, in either case, you are free to use any format that is supported by GraphDB.
As String
graphdbImporttext data: JSON { console; console;};
Parameters
You can pass any of the following parameters to the above method call.
By URL
graphdbImport;
Parameters
You can pass any of the following parameters to the above method call.