LDflex / Query-Solid

Simple access to data in Solid pods through LDflex expressions
https://solid.github.io/query-ldflex/
MIT License
66 stars 15 forks source link

Example in Readme on node #20

Closed labra closed 5 years ago

labra commented 5 years ago

I was trying to test LDFlex by following the example instructions in the Readme and created the following program:

const { PathFactory } = require('ldflex');
const { default: ComunicaEngine } = require('ldflex-comunica');
const { namedNode } = require('@rdfjs/data-model');

// The JSON-LD context for resolving properties
const context = {
  "@context": {
    "@vocab": "http://xmlns.com/foaf/0.1/",
    "friends": "knows",
    "label": "http://www.w3.org/2000/01/rdf-schema#label",
  }
};
// The query engine and its source
const queryEngine = new ComunicaEngine('https://ruben.verborgh.org/profile/');
// The object that can create new paths
const path = new PathFactory({ context, queryEngine });

const ruben = path.create({ subject: namedNode('https://ruben.verborgh.org/profile/#me') });
showPerson(ruben);

async function showPerson(person) {
  console.log(`This person is ${await person.name}`);
}

When executing it in node (version v11.12.0), it returns:

> node testReadme.js 
(node:7097) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
    at currentUrl (/home/labra/src/cursos/ldflextest/node_modules/solid-auth-client/lib/url-util.js:9:42)
    at toUrlString (/home/labra/src/cursos/ldflextest/node_modules/solid-auth-client/lib/url-util.js:32:23)
    at SolidAuthClient.fetch (/home/labra/src/cursos/ldflextest/node_modules/solid-auth-client/lib/solid-auth-client.js:41:51)
    at ActorHttpSolidAuthFetch.run (/home/labra/src/cursos/ldflextest/node_modules/@comunica/actor-http-solid-auth-fetch/lib/ActorHttpSolidAuthFetch.js:13:22)
    at ActorHttpSolidAuthFetch.runObservable (/home/labra/src/cursos/ldflextest/node_modules/@comunica/core/lib/Actor.js:53:29)
    at MediatorNumber.mediate (/home/labra/src/cursos/ldflextest/node_modules/@comunica/core/lib/Mediator.js:80:22)
(node:7097) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 91)
(node:7097) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Should it work or is there something missing?

I created this simple repository in case you want to reproduce it: https://github.com/cursosLabra/ldflextest

rubensworks commented 5 years ago

LDflex for Solid only works in browser environments at the moment (due to a recent change). However, a solution to make it work in Node.js is being worked on, see https://github.com/RubenVerborgh/LDflex-Comunica/issues/12.

RubenVerborgh commented 5 years ago

Indeed, as @rubensworks said, since we started using the authenticated Solid client, we lost Node compatibility for @solid/query-ldflex, because that client is browser-only. Following up in https://github.com/RubenVerborgh/LDflex-Comunica/issues/12.