Skip to content

Commit

Permalink
Support SchemaPublishMissingUrlError in CLI (#157)
Browse files Browse the repository at this point in the history
This PR adds a dedicated error message with instructions when a service URL is missing (federated projects) thanks to the recently added `SchemaPublishMissingUrlError` type.
  • Loading branch information
kamilkisiela authored Jun 23, 2022
1 parent 6868119 commit 5de7e38
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-pandas-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/cli': minor
---

Support SchemaPublishMissingUrlError type
58 changes: 58 additions & 0 deletions integration-tests/tests/cli/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,61 @@ test('service url should be available in supergraph', async () => {

expect(supergraph.body).toMatch('(name: "users" url: "https://api.com/users-subgraph")');
});

test('service url should be required in Federation', async () => {
const { access_token: owner_access_token } = await authenticate('main');
const orgResult = await createOrganization(
{
name: 'foo',
},
owner_access_token
);
const org = orgResult.body.data!.createOrganization.ok!.createdOrganizationPayload.organization;
const code = org.inviteCode;

// Join
const { access_token: member_access_token } = await authenticate('extra');
await joinOrganization(code, member_access_token);

const projectResult = await createProject(
{
organization: org.cleanId,
type: ProjectType.Federation,
name: 'foo',
},
owner_access_token
);

const project = projectResult.body.data!.createProject.ok!.createdProject;
const target = projectResult.body.data!.createProject.ok!.createdTarget;

// Create a token with write rights
const writeTokenResult = await createToken(
{
name: 'test',
organization: org.cleanId,
project: project.cleanId,
target: target.cleanId,
organizationScopes: [],
projectScopes: [],
targetScopes: [TargetAccessScope.RegistryRead, TargetAccessScope.RegistryWrite],
},
owner_access_token
);
expect(writeTokenResult.body.errors).not.toBeDefined();
const writeToken = writeTokenResult.body.data!.createToken.ok!.secret;

await expect(
schemaPublish([
'--token',
writeToken,
'--author',
'Kamil',
'--commit',
'abc123',
'--service',
'users',
'fixtures/federation-init.graphql',
])
).rejects.toThrowError('EXIT: 1');
});
3 changes: 3 additions & 0 deletions packages/libraries/cli/src/commands/schema/publish.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ mutation schemaPublish($input: SchemaPublishInput!, $usesGitHubApp: Boolean!) {
... on SchemaPublishMissingServiceError @skip(if: $usesGitHubApp) {
missingServiceError: message
}
... on SchemaPublishMissingUrlError @skip(if: $usesGitHubApp) {
missingUrlError: message
}
... on GitHubSchemaPublishSuccess @include(if: $usesGitHubApp) {
message
}
Expand Down
3 changes: 3 additions & 0 deletions packages/libraries/cli/src/commands/schema/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export default class SchemaPublish extends Command {
} else if (result.schemaPublish.__typename === 'SchemaPublishMissingServiceError') {
this.fail(`${result.schemaPublish.missingServiceError} Please use the '--service <name>' parameter.`);
this.exit(1);
} else if (result.schemaPublish.__typename === 'SchemaPublishMissingUrlError') {
this.fail(`${result.schemaPublish.missingUrlError} Please use the '--url <url>' parameter.`);
this.exit(1);
} else if (result.schemaPublish.__typename === 'SchemaPublishError') {
const changes = result.schemaPublish.changes;
const errors = result.schemaPublish.errors;
Expand Down

0 comments on commit 5de7e38

Please sign in to comment.