Skip to content

Commit 39eac03

Browse files
authored
fix: handle missing service error for federation project schema checks (#6483)
1 parent c549af7 commit 39eac03

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

.changeset/strange-shrimps-battle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-hive/cli': patch
3+
---
4+
5+
Show correct error message when attempting a schema check on a federation project without the
6+
`--service` paramater.

integration-tests/testkit/cli.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ async function generateTmpFile(content: string, extension: string) {
1919
return filepath;
2020
}
2121

22-
async function exec(cmd: string) {
22+
async function exec(cmd: string, env?: Record<string, string>) {
2323
const outout = await execaCommand(`${binPath} ${cmd}`, {
2424
shell: true,
2525
env: {
2626
OCLIF_CLI_CUSTOM_PATH: cliDir,
2727
NODE_OPTIONS: '--no-deprecation',
28+
...env,
2829
},
2930
});
3031

@@ -44,11 +45,12 @@ export async function schemaPublish(args: string[]) {
4445
);
4546
}
4647

47-
export async function schemaCheck(args: string[]) {
48+
export async function schemaCheck(args: string[], env?: Record<string, string>) {
4849
const registryAddress = await getServiceHost('server', 8082);
4950

5051
return await exec(
5152
['schema:check', `--registry.endpoint`, `http://${registryAddress}/graphql`, ...args].join(' '),
53+
env,
5254
);
5355
}
5456

integration-tests/tests/cli/schema.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,47 @@ test.concurrent(
453453
`);
454454
},
455455
);
456+
457+
test('schema:check gives correct error message for missing `--service` name flag in federation project', async ({
458+
expect,
459+
}) => {
460+
const { createOrg } = await initSeed().createOwner();
461+
const { inviteAndJoinMember, createProject } = await createOrg();
462+
await inviteAndJoinMember();
463+
const { createTargetAccessToken } = await createProject(ProjectType.Federation);
464+
const { secret } = await createTargetAccessToken({});
465+
466+
await expect(
467+
schemaCheck(
468+
[
469+
'--registry.accessToken',
470+
secret,
471+
'--github',
472+
'--author',
473+
'Kamil',
474+
'fixtures/init-schema.graphql',
475+
],
476+
{
477+
// set these environment variables to "emulate" a GitHub actions environment
478+
// We set GITHUB_EVENT_PATH to "" because on our CI it can be present and we want
479+
// consistent snapshot output behaviour.
480+
GITHUB_ACTIONS: '1',
481+
GITHUB_REPOSITORY: 'foo/foo',
482+
GITHUB_EVENT_PATH: '',
483+
},
484+
),
485+
).rejects.toMatchInlineSnapshot(`
486+
:::::::::::::::: CLI FAILURE OUTPUT :::::::::::::::
487+
exitCode------------------------------------------:
488+
1
489+
stderr--------------------------------------------:
490+
› Warning: Could not resolve pull request number. Are you running this
491+
› command on a 'pull_request' event?
492+
› See https://__URL__
493+
› b-workflow-for-ci
494+
stdout--------------------------------------------:
495+
✖ Detected 1 error
496+
497+
- Missing service name
498+
`);
499+
});

packages/libraries/cli/src/commands/schema/check.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import {
2626
import * as TargetInput from '../../helpers/target-input';
2727

2828
const schemaCheckMutation = graphql(/* GraphQL */ `
29-
mutation schemaCheck($input: SchemaCheckInput!, $usesGitHubApp: Boolean!) {
29+
mutation schemaCheck($input: SchemaCheckInput!) {
3030
schemaCheck(input: $input) {
3131
__typename
32-
... on SchemaCheckSuccess @skip(if: $usesGitHubApp) {
32+
... on SchemaCheckSuccess {
3333
valid
3434
initial
3535
warnings {
@@ -60,7 +60,7 @@ const schemaCheckMutation = graphql(/* GraphQL */ `
6060
webUrl
6161
}
6262
}
63-
... on SchemaCheckError @skip(if: $usesGitHubApp) {
63+
... on SchemaCheckError {
6464
valid
6565
changes {
6666
nodes {
@@ -90,10 +90,10 @@ const schemaCheckMutation = graphql(/* GraphQL */ `
9090
webUrl
9191
}
9292
}
93-
... on GitHubSchemaCheckSuccess @include(if: $usesGitHubApp) {
93+
... on GitHubSchemaCheckSuccess {
9494
message
9595
}
96-
... on GitHubSchemaCheckError @include(if: $usesGitHubApp) {
96+
... on GitHubSchemaCheckError {
9797
message
9898
}
9999
}
@@ -274,7 +274,6 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
274274
contextId: flags.contextId ?? undefined,
275275
target,
276276
},
277-
usesGitHubApp,
278277
},
279278
});
280279

packages/services/api/src/modules/schema/providers/schema-publisher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export class SchemaPublisher {
346346
) {
347347
this.logger.debug('No service name provided (type=%s)', project.type);
348348
increaseSchemaCheckCountMetric('rejected');
349+
349350
return {
350351
__typename: 'SchemaCheckError',
351352
valid: false,

0 commit comments

Comments
 (0)