From d34d1a08f13ecdf0e077aa154932e69f716edc0b Mon Sep 17 00:00:00 2001 From: Mark Lindeman Date: Thu, 23 May 2024 12:32:09 +0200 Subject: [PATCH] fix: sparql@... URLs (#50) --- src/utils/getEndpoint.ts | 3 ++- src/utils/tests/utilities.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/utils/getEndpoint.ts b/src/utils/getEndpoint.ts index c6e2479..b256e57 100644 --- a/src/utils/getEndpoint.ts +++ b/src/utils/getEndpoint.ts @@ -25,7 +25,8 @@ export default function getEndpoint( return new File(endpoint); } else if (endpoint !== undefined) { try { - return new URL(endpoint); + // fix for GraphDB, see https://github.com/comunica/comunica/issues/962 + return new URL((endpoint as string).replace(/^sparql@/, '')); } catch (e) { throw new Error(`"${endpoint as string}" is not a valid URL`); } diff --git a/src/utils/tests/utilities.test.ts b/src/utils/tests/utilities.test.ts index 5e615ff..8b01669 100644 --- a/src/utils/tests/utilities.test.ts +++ b/src/utils/tests/utilities.test.ts @@ -357,6 +357,31 @@ describe('Utilities', () => { // getEndpoint is use in Stage's Iterator, and it will throw there. expect(() => new Stage(pipeline, stageConfig)).to.throw('Error in the iterator of stage `Stage 1`: "invalidExample" is not a valid URL') }) + it('should work with URL\'s prepended with \'sparql@\'', () => { + const url = 'sparql@https://www.goudatijdmachine.nl/sparql/repositories/nafotocollectie' // will be accepted + const config: LDWorkbenchConfiguration = { + name: 'Example Pipeline', + description: 'This is an example pipeline. It uses files that are available in this repository and SPARQL endpoints that should work.\n', + destination: 'file://pipelines/data/example-pipeline.nt', + stages: [ + { + name: 'Stage 1', + iterator: { + query: 'file://static/example/iterator-stage-1.rq', + endpoint: url + }, + generator: [ +{ + query: 'file://static/example/generator-stage-1-1.rq' + } +] } + ] + } + const pipeline = new Pipeline(config, {silent: true}) + const stageConfig = config.stages[0] + // getEndpoint is use in Stage's Iterator, and it will throw there. + expect(() => new Stage(pipeline, stageConfig)).to.not.throw() + }) it('should throw if stage has undefined endpoint and is first stage', () => { const endpoint = undefined const config: LDWorkbenchConfiguration = {