fix: Support BGPs with variables in SPARQL UPDATE queries

This commit is contained in:
Joachim Van Herwegen
2021-06-25 16:49:20 +02:00
parent 25f33ee4cd
commit f299b36e24
4 changed files with 2732 additions and 59 deletions

View File

@@ -13,6 +13,7 @@ import type { ResourceStore } from '../../../../src/storage/ResourceStore';
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
import { NotImplementedHttpError } from '../../../../src/util/errors/NotImplementedHttpError';
import { guardedStreamFrom } from '../../../../src/util/StreamUtil';
describe('A SparqlUpdatePatchHandler', (): void => {
let converter: jest.Mocked<RepresentationConverter>;
@@ -75,11 +76,16 @@ describe('A SparqlUpdatePatchHandler', (): void => {
}
async function handle(query: string): Promise<void> {
const sparqlPrefix = 'prefix : <http://test.com/>\n';
const prefixedQuery = `prefix : <http://test.com/>\n${query}`;
await handler.handle({
source,
identifier,
patch: { algebra: translate(sparqlPrefix.concat(query), { quads: true }) } as SparqlUpdatePatch,
patch: {
algebra: translate(prefixedQuery, { quads: true }),
data: guardedStreamFrom(prefixedQuery),
metadata: new RepresentationMetadata(),
binary: true,
} as SparqlUpdatePatch,
});
}
@@ -124,6 +130,16 @@ describe('A SparqlUpdatePatchHandler', (): void => {
)).toBe(true);
});
it('handles DELETE WHERE updates with variables.', async(): Promise<void> => {
const query = 'DELETE WHERE { :startS1 :startP1 ?o }';
await handle(query);
expect(await basicChecks(
[ quad(namedNode('http://test.com/startS2'),
namedNode('http://test.com/startP2'),
namedNode('http://test.com/startO2')) ],
)).toBe(true);
});
it('handles DELETE/INSERT updates with empty WHERE.', async(): Promise<void> => {
const query = 'DELETE { :startS1 :startP1 :startO1 } INSERT { :s1 :p1 :o1 . } WHERE {}';
await handle(query);
@@ -178,8 +194,8 @@ describe('A SparqlUpdatePatchHandler', (): void => {
await expect(handle(query)).rejects.toThrow(NotImplementedHttpError);
});
it('rejects DELETE/INSERT updates with a non-empty WHERE.', async(): Promise<void> => {
const query = 'DELETE { :s1 :p1 :o1 } INSERT { :s1 :p1 :o1 } WHERE { ?s ?p ?o }';
it('rejects DELETE/INSERT updates with non-BGP WHERE.', async(): Promise<void> => {
const query = 'DELETE { :s1 :p1 :o1 } INSERT { :s1 :p1 :o1 } WHERE { ?s ?p ?o. FILTER (?o > 5) }';
await expect(handle(query)).rejects.toThrow(NotImplementedHttpError);
});
@@ -188,11 +204,6 @@ describe('A SparqlUpdatePatchHandler', (): void => {
await expect(handle(query)).rejects.toThrow(NotImplementedHttpError);
});
it('rejects DELETE WHERE updates with variables.', async(): Promise<void> => {
const query = 'DELETE WHERE { ?v :startP1 :startO1 }';
await expect(handle(query)).rejects.toThrow(NotImplementedHttpError);
});
it('rejects non-DELETE/INSERT updates.', async(): Promise<void> => {
const query = 'MOVE DEFAULT TO GRAPH :newGraph';
await expect(handle(query)).rejects.toThrow(NotImplementedHttpError);