mirror of
https://github.com/graphql-hive/console
synced 2026-05-24 09:38:26 +00:00
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:
parent
482dd426ff
commit
23eb4cc07f
5 changed files with 106 additions and 1 deletions
5
.changeset/nice-geese-learn.md
Normal file
5
.changeset/nice-geese-learn.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/cli': minor
|
||||
---
|
||||
|
||||
Add message about empty schema registry in schema:check
|
||||
3
integration-tests/fixtures/missing-type.graphql
Normal file
3
integration-tests/fixtures/missing-type.graphql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type Query {
|
||||
users: [User!]!
|
||||
}
|
||||
|
|
@ -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');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ mutation schemaCheck($input: SchemaCheckInput!, $usesGitHubApp: Boolean!) {
|
|||
__typename
|
||||
... on SchemaCheckSuccess @skip(if: $usesGitHubApp) {
|
||||
valid
|
||||
initial
|
||||
changes {
|
||||
nodes {
|
||||
message
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue