Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions composition-js/src/__tests__/compose.composeDirective.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,60 @@ describe('composing custom core directives', () => {
]);
});

it('ensure that composeDirective argument cannot be undefined', () => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
composeText: '@composeDirective',
});
const subgraphB = generateSubgraph({
name: 'subgraphB',
});

const result = composeServices([subgraphA, subgraphB]);
expect(errors(result)).toStrictEqual([
[
'DIRECTIVE_COMPOSITION_ERROR',
'Argument to @composeDirective in subgraph "subgraphA" cannot be NULL or an empty String',
]
]);
});

it('ensure that composeDirective argument cannot be null', () => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
composeText: '@composeDirective(name: null)',
});
const subgraphB = generateSubgraph({
name: 'subgraphB',
});

const result = composeServices([subgraphA, subgraphB]);
expect(errors(result)).toStrictEqual([
[
'DIRECTIVE_COMPOSITION_ERROR',
'Argument to @composeDirective in subgraph "subgraphA" cannot be NULL or an empty String',
]
]);
});

it('ensure that composeDirective argument cannot be empty', () => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
composeText: '@composeDirective(name: "")',
});
const subgraphB = generateSubgraph({
name: 'subgraphB',
});

const result = composeServices([subgraphA, subgraphB]);
expect(errors(result)).toStrictEqual([
[
'DIRECTIVE_COMPOSITION_ERROR',
'Argument to @composeDirective in subgraph "subgraphA" cannot be NULL or an empty String',
]
]);
});

it('ensure that composeDirective argument must start with an @', () => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
Expand Down
8 changes: 8 additions & 0 deletions composition-js/src/composeDirectiveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ export class ComposeDirectiveManager {
.applications();

for (const composeInstance of composeDirectives) {
if (composeInstance.arguments().name == null || composeInstance.arguments().name === '') {
this.pushError(ERRORS.DIRECTIVE_COMPOSITION_ERROR.err(
`Argument to @composeDirective in subgraph "${sg.name}" cannot be NULL or an empty String`,
{ nodes: composeInstance.sourceAST },
));
continue;
}

if (composeInstance.arguments().name[0] !== '@') {
this.pushError(ERRORS.DIRECTIVE_COMPOSITION_ERROR.err(
`Argument to @composeDirective "${composeInstance.arguments().name}" in subgraph "${sg.name}" must have a leading "@"`,
Expand Down