Skip to content

Commit

Permalink
Add message about empty schema registry in schema:check (#176)
Browse files Browse the repository at this point in the history
* Add message about empty schema registry in schema:check

* prettier on changeset...
  • Loading branch information
kamilkisiela authored Jun 24, 2022
1 parent 482dd42 commit 23eb4cc
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nice-geese-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/cli': minor
---

Add message about empty schema registry in schema:check
3 changes: 3 additions & 0 deletions integration-tests/fixtures/missing-type.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Query {
users: [User!]!
}
94 changes: 94 additions & 0 deletions integration-tests/tests/cli/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,97 @@ test('service url should be required in Federation', async () => {
])
).rejects.toThrowError(/url/);
});

test('schema:check should notify user when registry is empty', 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.Single,
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(schemaCheck(['--token', writeToken, 'fixtures/init-schema.graphql'])).resolves.toMatch('empty');
});

test('schema:check should throw on corrupted schema', 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.Single,
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;

const output = schemaCheck(['--token', writeToken, 'fixtures/missing-type.graphql']);

await expect(output).rejects.toThrowError('Unknown type');
});
1 change: 1 addition & 0 deletions packages/libraries/cli/src/commands/schema/check.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mutation schemaCheck($input: SchemaCheckInput!, $usesGitHubApp: Boolean!) {
__typename
... on SchemaCheckSuccess @skip(if: $usesGitHubApp) {
valid
initial
changes {
nodes {
message
Expand Down
4 changes: 3 additions & 1 deletion packages/libraries/cli/src/commands/schema/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export default class SchemaCheck extends Command {

if (result.schemaCheck.__typename === 'SchemaCheckSuccess') {
const changes = result.schemaCheck.changes;
if (!changes?.total) {
if (result.schemaCheck.initial) {
this.success('Schema registry is empty, nothing to compare your schema with.');
} else if (!changes?.total) {
this.success('No changes');
} else {
renderChanges.call(this, changes);
Expand Down

0 comments on commit 23eb4cc

Please sign in to comment.