Skip to content

Commit

Permalink
Add namespaces queryFormat context entry
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 27, 2018
1 parent e63934a commit 0bff69f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions packages/actor-init-sparql/lib/ActorInitSparql-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export class ActorInitSparql extends ActorInit implements IActorInitSparqlArgs {
context[KEY_CONTEXT_INITIALBINDINGS] = context.initialBindings;
delete context.initialBindings;
}
if (context.queryFormat) {
context[KEY_CONTEXT_QUERYFORMAT] = context.queryFormat;
delete context.queryFormat;
}

context = ActionContext(context);

Expand All @@ -111,9 +115,9 @@ export class ActorInitSparql extends ActorInit implements IActorInitSparqlArgs {

// Parse query
let queryFormat: string = 'sparql';
if (context && context.has('queryFormat')) {
queryFormat = context.get('queryFormat');
context = context.delete('queryFormat');
if (context && context.has(KEY_CONTEXT_QUERYFORMAT)) {
queryFormat = context.get(KEY_CONTEXT_QUERYFORMAT);
context = context.delete(KEY_CONTEXT_QUERYFORMAT);
}
let operation: Algebra.Operation = (await this.mediatorSparqlParse.mediate(
{ context, query, queryFormat })).operation;
Expand Down Expand Up @@ -192,3 +196,4 @@ export interface IActorInitSparqlArgs extends IActorArgs<IActionInit, IActorTest
}

export const KEY_CONTEXT_INITIALBINDINGS: string = '@comunica/actor-init-sparql:initialBindings';
export const KEY_CONTEXT_QUERYFORMAT: string = '@comunica/actor-init-sparql:queryFormat';
6 changes: 3 additions & 3 deletions packages/actor-init-sparql/test/ActorInitSparql-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {literal, namedNode, variable} from "rdf-data-model";
import {Factory} from "sparqlalgebrajs";
import {PassThrough, Readable} from "stream";
import {ActorInitSparql} from "../lib/ActorInitSparql";
import {ActorInitSparql as ActorInitSparqlBrowser} from "../lib/ActorInitSparql-browser";
import {ActorInitSparql as ActorInitSparqlBrowser, KEY_CONTEXT_QUERYFORMAT} from "../lib/ActorInitSparql-browser";

const FACTORY: Factory = new Factory();

Expand Down Expand Up @@ -203,7 +203,7 @@ describe('ActorInitSparql', () => {
mediatorSparqlSerializeMediaTypeCombiner: mediatorSparqlSerialize, name: 'actor', queryString });
const spy = jest.spyOn(actor, 'query');
(await actor.run({ argv: [], env: {}, stdin: new PassThrough() }));
return expect(spy.mock.calls[0][1].queryFormat).toEqual('sparql');
return expect(spy.mock.calls[0][1][KEY_CONTEXT_QUERYFORMAT]).toEqual('sparql');
});

it('should allow the query format to be changed with -i', async () => {
Expand All @@ -212,7 +212,7 @@ describe('ActorInitSparql', () => {
mediatorSparqlSerializeMediaTypeCombiner: mediatorSparqlSerialize, name: 'actor', queryString });
const spy = jest.spyOn(actor, 'query');
(await actor.run({ argv: [ '-i', 'graphql' ], env: {}, stdin: new PassThrough() }));
return expect(spy.mock.calls[0][1].queryFormat).toEqual('graphql');
return expect(spy.mock.calls[0][1][KEY_CONTEXT_QUERYFORMAT]).toEqual('graphql');
});

it('should allow a media type to be passed with -t', async () => {
Expand Down

0 comments on commit 0bff69f

Please sign in to comment.