Add message about empty schema registry in schema:check (#176)

* Add message about empty schema registry in schema:check

* prettier on changeset...
This commit is contained in:
Kamil Kisiela 2022-06-24 21:04:50 +02:00 committed by GitHub
parent 482dd426ff
commit 23eb4cc07f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 106 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/cli': minor
---
Add message about empty schema registry in schema:check

View file

@ -0,0 +1,3 @@
type Query {
users: [User!]!
}

View file

@ -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');
});

View file

@ -3,6 +3,7 @@ mutation schemaCheck($input: SchemaCheckInput!, $usesGitHubApp: Boolean!) {
__typename
... on SchemaCheckSuccess @skip(if: $usesGitHubApp) {
valid
initial
changes {
nodes {
message

View file

@ -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);