Skip to content

Commit e6a970f

Browse files
authored
feat(api): expose fields for schema versions and schema checks (#6658)
1 parent 2b220a5 commit e6a970f

36 files changed

+526
-316
lines changed

.changeset/chatty-tomatoes-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/cli': minor
3+
---
4+
5+
Internal adjustments for using non-deprecated API fields.

.changeset/many-timers-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': minor
3+
---
4+
5+
Adjust GraphQL schema according to schema design policies.

packages/libraries/cli/src/commands/dev.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ const CLI_SchemaComposeMutation = graphql(/* GraphQL */ `
3838
compositionResult {
3939
supergraphSdl
4040
errors {
41-
total
42-
nodes {
43-
message
44-
}
41+
...RenderErrors_SchemaErrorConnectionFragment
4542
}
4643
}
4744
}

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@ const schemaCheckMutation = graphql(/* GraphQL */ `
4242
total
4343
}
4444
changes {
45-
nodes {
46-
message(withSafeBasedOnUsageNote: false)
47-
criticality
48-
isSafeBasedOnUsage
49-
approval {
50-
approvedBy {
51-
id
52-
displayName
45+
edges {
46+
node {
47+
message(withSafeBasedOnUsageNote: false)
48+
criticality
49+
isSafeBasedOnUsage
50+
approval {
51+
approvedBy {
52+
id
53+
displayName
54+
}
5355
}
5456
}
5557
}
56-
total
5758
...RenderChanges_schemaChanges
5859
}
5960
schemaCheck {
@@ -63,12 +64,13 @@ const schemaCheckMutation = graphql(/* GraphQL */ `
6364
... on SchemaCheckError {
6465
valid
6566
changes {
66-
nodes {
67-
message(withSafeBasedOnUsageNote: false)
68-
criticality
69-
isSafeBasedOnUsage
67+
edges {
68+
node {
69+
message(withSafeBasedOnUsageNote: false)
70+
criticality
71+
isSafeBasedOnUsage
72+
}
7073
}
71-
total
7274
...RenderChanges_schemaChanges
7375
}
7476
warnings {
@@ -81,10 +83,7 @@ const schemaCheckMutation = graphql(/* GraphQL */ `
8183
total
8284
}
8385
errors {
84-
nodes {
85-
message
86-
}
87-
total
86+
...RenderErrors_SchemaErrorConnectionFragment
8887
}
8988
schemaCheck {
9089
webUrl
@@ -290,7 +289,7 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
290289
const changes = result.schemaCheck.changes;
291290
if (result.schemaCheck.initial) {
292291
this.logSuccess('Schema registry is empty, nothing to compare your schema with.');
293-
} else if (!changes?.total) {
292+
} else if (!changes?.edges.length) {
294293
this.logSuccess('No changes');
295294
} else {
296295
this.log(renderChanges(changes));
@@ -314,7 +313,7 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
314313
this.log(renderWarnings(warnings));
315314
}
316315

317-
if (changes && changes.total) {
316+
if (changes?.edges.length) {
318317
this.log(renderChanges(changes));
319318
}
320319

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,21 @@ const schemaDeleteMutation = graphql(/* GraphQL */ `
2020
... on SchemaDeleteSuccess {
2121
valid
2222
changes {
23-
nodes {
24-
criticality
25-
message
23+
edges {
24+
node {
25+
criticality
26+
message
27+
}
2628
}
27-
total
2829
}
2930
errors {
30-
nodes {
31-
message
32-
}
33-
total
31+
...RenderErrors_SchemaErrorConnectionFragment
3432
}
3533
}
3634
... on SchemaDeleteError {
3735
valid
3836
errors {
39-
nodes {
40-
message
41-
}
42-
total
37+
...RenderErrors_SchemaErrorConnectionFragment
4338
}
4439
}
4540
}

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ const SchemaVersionForActionIdQuery = graphql(/* GraphQL */ `
3030
sdl @include(if: $includeSDL)
3131
supergraph @include(if: $includeSupergraph)
3232
schemas @include(if: $includeSubgraphs) {
33-
nodes {
34-
__typename
35-
... on SingleSchema {
36-
id
37-
date
38-
}
39-
... on CompositeSchema {
40-
id
41-
date
42-
url
43-
service
33+
edges {
34+
node {
35+
__typename
36+
... on SingleSchema {
37+
id
38+
date
39+
}
40+
... on CompositeSchema {
41+
id
42+
date
43+
url
44+
service
45+
}
4446
}
4547
}
46-
total
4748
}
4849
}
4950
}
@@ -62,20 +63,21 @@ const LatestSchemaVersionQuery = graphql(/* GraphQL */ `
6263
sdl @include(if: $includeSDL)
6364
supergraph @include(if: $includeSupergraph)
6465
schemas @include(if: $includeSubgraphs) {
65-
nodes {
66-
__typename
67-
... on SingleSchema {
68-
id
69-
date
70-
}
71-
... on CompositeSchema {
72-
id
73-
date
74-
url
75-
service
66+
edges {
67+
node {
68+
__typename
69+
... on SingleSchema {
70+
id
71+
date
72+
}
73+
... on CompositeSchema {
74+
id
75+
date
76+
url
77+
service
78+
}
7679
}
7780
}
78-
total
7981
}
8082
}
8183
}
@@ -217,17 +219,15 @@ export default class SchemaFetch extends Command<typeof SchemaFetch> {
217219
}
218220

219221
if (schemaVersion.schemas) {
220-
const { total, nodes } = schemaVersion.schemas;
221222
const tableData = [
222223
['service', 'url', 'date'],
223-
...nodes.map(node => [
224-
/** @ts-expect-error: If service is undefined then use id. */
225-
node.service ?? node.id,
226-
node.__typename === 'CompositeSchema' ? node.url : 'n/a',
227-
node.date as string,
224+
...schemaVersion.schemas.edges.map(edge => [
225+
'service' in edge.node && edge.node.service != null ? edge.node.service : edge.node.id,
226+
'url' in edge.node && edge.node.url != null ? edge.node.url : 'n/a',
227+
edge.node.date as string,
228228
]),
229229
];
230-
const stats = `subgraphs length: ${total}`;
230+
const stats = `subgraphs length: ${schemaVersion.schemas.edges.length}`;
231231
const printed = `${Texture.table(tableData)}\n\r${stats}`;
232232

233233
if (flags.write) {

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,23 @@ const schemaPublishMutation = graphql(/* GraphQL */ `
3434
successMessage: message
3535
linkToWebsite
3636
changes {
37-
nodes {
38-
message(withSafeBasedOnUsageNote: false)
39-
criticality
40-
isSafeBasedOnUsage
37+
edges {
38+
__typename
4139
}
42-
total
4340
...RenderChanges_schemaChanges
4441
}
4542
}
4643
... on SchemaPublishError @skip(if: $usesGitHubApp) {
4744
valid
4845
linkToWebsite
4946
changes {
50-
nodes {
51-
message(withSafeBasedOnUsageNote: false)
52-
criticality
53-
isSafeBasedOnUsage
47+
edges {
48+
__typename
5449
}
55-
total
5650
...RenderChanges_schemaChanges
5751
}
5852
errors {
59-
nodes {
60-
message
61-
}
62-
total
53+
...RenderErrors_SchemaErrorConnectionFragment
6354
}
6455
}
6556
... on SchemaPublishMissingServiceError @skip(if: $usesGitHubApp) {
@@ -324,7 +315,7 @@ export default class SchemaPublish extends Command<typeof SchemaPublish> {
324315
this.logSuccess('Published initial schema.');
325316
} else if (result.schemaPublish.successMessage) {
326317
this.logSuccess(result.schemaPublish.successMessage);
327-
} else if (changes && changes.total === 0) {
318+
} else if (changes?.edges?.length === 0) {
328319
this.logSuccess('No changes. Skipping.');
329320
} else {
330321
if (changes) {
@@ -349,7 +340,7 @@ export default class SchemaPublish extends Command<typeof SchemaPublish> {
349340
const errors = result.schemaPublish.errors;
350341
this.log(renderErrors(errors));
351342

352-
if (changes && changes.total) {
343+
if (changes?.edges.length) {
353344
this.log('');
354345
this.log(renderChanges(changes));
355346
}

packages/libraries/cli/src/helpers/errors.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { GraphQLError } from 'graphql';
44
import { InvalidDocument } from '@graphql-inspector/core';
55
import { CLIError } from '@oclif/core/lib/errors';
66
import { CompositionFailure } from '@theguild/federation-composition';
7-
import { SchemaErrorConnection } from '../gql/graphql';
8-
import { renderErrors } from './schema';
7+
import { FragmentType, makeFragmentData } from '../gql/index';
8+
import { renderErrors, RenderErrors_SchemaErrorConnectionFragment } from './schema';
99
import { Texture } from './texture/texture';
1010

1111
export enum ExitCode {
@@ -306,18 +306,24 @@ export class ServiceAndUrlLengthMismatch extends HiveCLIError {
306306

307307
export class LocalCompositionError extends HiveCLIError {
308308
constructor(compositionResult: CompositionFailure) {
309-
const message = renderErrors({
310-
total: compositionResult.errors.length,
311-
nodes: compositionResult.errors.map(error => ({
312-
message: error.message,
313-
})),
314-
});
309+
const message = renderErrors(
310+
makeFragmentData(
311+
{
312+
edges: compositionResult.errors.map(error => ({
313+
node: {
314+
message: error.message,
315+
},
316+
})),
317+
},
318+
RenderErrors_SchemaErrorConnectionFragment,
319+
),
320+
);
315321
super(ExitCode.ERROR, errorCode(ErrorCategory.DEV, 1), `Local composition failed:\n${message}`);
316322
}
317323
}
318324

319325
export class RemoteCompositionError extends HiveCLIError {
320-
constructor(errors: SchemaErrorConnection) {
326+
constructor(errors: FragmentType<typeof RenderErrors_SchemaErrorConnectionFragment>) {
321327
const message = renderErrors(errors);
322328
super(
323329
ExitCode.ERROR,

0 commit comments

Comments
 (0)