Useful or not, from you.
rdflib.js jsonld wrong handling of default graph

I am experimenting with the rdflib and the hydra jsonld API.


import * as rdf from "rdflib"

const store: rdf.IndexedFormula = rdf.graph();
const fetcher: rdf.Fetcher = new rdf.Fetcher(store);
const updateMgr: rdf.UpdateManager = new rdf.UpdateManager(store);
const MY_DOMAIN = rdf.Namespace("");
const docNode = rdf.sym("https://localhost:8443/companions");
const context = "";

const jsonDoc ={
    "@context": "",
    "@id": `${docNode.uri}`,
    "title": "A companion container.",
    "description": "Companions can be managed with ldp container.",
    "operation": [
        "@type": "Operation",
        "method": "POST"

const asNquads = `<https://localhost:8443/companions> <> "This issue can be deleted with an HTTP DELETE request" .
<https://localhost:8443/companions> <> _:b0 .
<https://localhost:8443/companions> <> "An exemplary issue representation" .
_:b0 <> <> .
_:b0 <> "DELETE" .
rdf.parse(JSON.stringyfi(jsonldDoc), store, docNode.uri, 'application/ld+json', (err, res) => {
      if (err) {
          throw new Error();
      } else {
          rdf.serialize(docNode, store, docNode.uri, 'application/ld+json', (err, res) => {
              if (err) {
                  throw new Error();
              } else {

If i am not mistaken, all nodes should belong to the default graph. If I parse a turtle document, rdflib uses the base-parameter of the parse function as the graph name. But if I parse the jsonld-document rdflib sets nodeobjects as the graph names. In a result I get a rdf dataset with two different graphs instead of one. The line of code where the why (graphname) gets set is in indexed-formular.js lines 270-273:

if (!why) {
        // system generated
        why = this.fetcher ? this.fetcher.appNode : this.sym(defaultGraphURI);

Thus the serializing of docNode does only print 3 rdf-triples instead of 5.

If this behavior is not intended, I could write a fix. I think there must just be a check for the default graph be included in parser.js. If the default graph is detected, why will be set to base.

That's a useful answer
Without any help

Looks good