UNPKG

graphql-ld-comunica-solid

Version:

A GraphQL-LD engine that is backed by Comunica with Solid authentication

35 lines 1.84 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.QueryEngineComunicaSolid = void 0; const actor_init_sparql_solid_1 = require("@comunica/actor-init-sparql-solid"); const stringifyStream = require("stream-to-string"); /** * A GraphQL-LD engine that is backed by Comunica. */ class QueryEngineComunicaSolid { constructor(context) { this.comunicaEngine = (0, actor_init_sparql_solid_1.newEngine)(); this.context = context; } query(query, options = {}) { return __awaiter(this, void 0, void 0, function* () { const context = Object.assign(Object.assign({}, options), this.context); if (context.session) { context['@comunica/actor-http-inrupt-solid-client-authn:session'] = context.session; } const { data } = yield this.comunicaEngine.resultToString(yield this.comunicaEngine.query(query, context), 'application/sparql-results+json'); return JSON.parse(yield stringifyStream(data)); }); } } exports.QueryEngineComunicaSolid = QueryEngineComunicaSolid; //# sourceMappingURL=QueryEngineComunicaSolid.js.map