Skip to content

Commit 74ab4ce

Browse files
committed
service:check add null check for validation config
The validationConfig is set to null when the backend does not perform any validations. This reformats the markdown output to reflect that
1 parent 5053584 commit 74ab4ce

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

  • packages/apollo/src/commands/service

packages/apollo/src/commands/service/check.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,23 @@ export function formatMarkdown({
105105

106106
const { validationConfig } = diffToPrevious;
107107

108-
if (!validationConfig) {
109-
throw new Error(
110-
"checkSchemaResult.diffToPrevious.validationConfig missing"
108+
let validationText = "";
109+
if (validationConfig) {
110+
// The validationConfig will always return a negative number. Use Math.abs to make it positive.
111+
const hours = Math.abs(
112+
moment()
113+
.add(validationConfig.from, "second")
114+
.diff(moment().add(validationConfig.to, "second"), "hours")
111115
);
112-
}
113116

114-
// This will always return a negative number. Use Math.abs to make it positive.
115-
const hours = Math.abs(
116-
moment()
117-
.add(validationConfig.from, "second")
118-
.diff(moment().add(validationConfig.to, "second"), "hours")
119-
);
117+
validationText = `🔢 Compared **${pluralize(
118+
diffToPrevious.changes.length,
119+
"schema change"
120+
)}** against **${pluralize(
121+
diffToPrevious.numberOfCheckedOperations,
122+
"operation"
123+
)}** seen over the **last ${formatTimePeriod(hours)}**.`;
124+
}
120125

121126
const breakingChanges = diffToPrevious.changes.filter(
122127
change => change.severity === "FAILURE"
@@ -131,13 +136,7 @@ export function formatMarkdown({
131136
🔄 Validated your local schema against schema tag \`${tag}\` ${
132137
serviceName ? `for service \`${serviceName}\` ` : ""
133138
}on graph \`${graphName}\`.
134-
🔢 Compared **${pluralize(
135-
diffToPrevious.changes.length,
136-
"schema change"
137-
)}** against **${pluralize(
138-
diffToPrevious.numberOfCheckedOperations,
139-
"operation"
140-
)}** seen over the **last ${formatTimePeriod(hours)}**.
139+
${validationText}
141140
${
142141
breakingChanges.length > 0
143142
? `❌ Found **${pluralize(
@@ -151,6 +150,8 @@ ${
151150
diffToPrevious.affectedClients && diffToPrevious.affectedClients.length,
152151
"client"
153152
)}**`
153+
: diffToPrevious.changes.length === 0
154+
? `✅ Found **no changes**.`
154155
: `✅ Found **no breaking changes**.`
155156
}
156157

0 commit comments

Comments
 (0)