diff --git a/composition-js/src/merging/merge.ts b/composition-js/src/merging/merge.ts index 6c367187c..57df2841e 100644 --- a/composition-js/src/merging/merge.ts +++ b/composition-js/src/merging/merge.ts @@ -2612,12 +2612,13 @@ class Merger { const map = new Map(); for (const linkDirective of schema.schemaDefinition.appliedDirectivesOf('link')) { const { url, import: imports } = linkDirective.arguments(); - if (imports) { + const parsedUrl = FeatureUrl.maybeParse(url); + if (parsedUrl && imports) { for (const i of imports) { if (typeof i === 'string') { - map.set(i, FeatureUrl.parse(url)); + map.set(i, parsedUrl); } else { - map.set(i.as ?? i.name, FeatureUrl.parse(url)); + map.set(i.as ?? i.name, parsedUrl); } } } @@ -2654,9 +2655,10 @@ class Merger { if (directive.name === 'link') { const { url } = directive.arguments(); - if (typeof url === 'string') { + const parsedUrl = FeatureUrl.maybeParse(url); + if (typeof url === 'string' && parsedUrl) { shouldIncludeAsJoinDirective = - this.shouldUseJoinDirectiveForURL(FeatureUrl.parse(url)); + this.shouldUseJoinDirectiveForURL(parsedUrl); } } else { // To be consistent with other code accessing diff --git a/internals-js/src/specs/coreSpec.ts b/internals-js/src/specs/coreSpec.ts index cc809b2de..95ac988da 100644 --- a/internals-js/src/specs/coreSpec.ts +++ b/internals-js/src/specs/coreSpec.ts @@ -750,7 +750,14 @@ export class FeatureUrl { public readonly element?: string, ) { } - /// Parse a spec URL or throw + public static maybeParse(input: string, node?: ASTNode): FeatureUrl | undefined { + try { + return FeatureUrl.parse(input, node); + } catch (err) { + return undefined; + } + } + /// Parse a spec URL or throw public static parse(input: string, node?: ASTNode): FeatureUrl { const url = new URL(input) if (!url.pathname || url.pathname === '/') {