Skip to content

Commit

Permalink
service:check add null check for validation config
Browse files Browse the repository at this point in the history
The validationConfig is set to null when the backend does not perform
any validations. This reformats the markdown output to reflect that
  • Loading branch information
evans committed Aug 14, 2019
1 parent 5053584 commit 74ab4ce
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/apollo/src/commands/service/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,23 @@ export function formatMarkdown({

const { validationConfig } = diffToPrevious;

if (!validationConfig) {
throw new Error(
"checkSchemaResult.diffToPrevious.validationConfig missing"
let validationText = "";
if (validationConfig) {
// The validationConfig will always return a negative number. Use Math.abs to make it positive.
const hours = Math.abs(
moment()
.add(validationConfig.from, "second")
.diff(moment().add(validationConfig.to, "second"), "hours")
);
}

// This will always return a negative number. Use Math.abs to make it positive.
const hours = Math.abs(
moment()
.add(validationConfig.from, "second")
.diff(moment().add(validationConfig.to, "second"), "hours")
);
validationText = `🔢 Compared **${pluralize(
diffToPrevious.changes.length,
"schema change"
)}** against **${pluralize(
diffToPrevious.numberOfCheckedOperations,
"operation"
)}** seen over the **last ${formatTimePeriod(hours)}**.`;
}

const breakingChanges = diffToPrevious.changes.filter(
change => change.severity === "FAILURE"
Expand All @@ -131,13 +136,7 @@ export function formatMarkdown({
🔄 Validated your local schema against schema tag \`${tag}\` ${
serviceName ? `for service \`${serviceName}\` ` : ""
}on graph \`${graphName}\`.
🔢 Compared **${pluralize(
diffToPrevious.changes.length,
"schema change"
)}** against **${pluralize(
diffToPrevious.numberOfCheckedOperations,
"operation"
)}** seen over the **last ${formatTimePeriod(hours)}**.
${validationText}
${
breakingChanges.length > 0
? `❌ Found **${pluralize(
Expand All @@ -151,6 +150,8 @@ ${
diffToPrevious.affectedClients && diffToPrevious.affectedClients.length,
"client"
)}**`
: diffToPrevious.changes.length === 0
? `✅ Found **no changes**.`
: `✅ Found **no breaking changes**.`
}
Expand Down

0 comments on commit 74ab4ce

Please sign in to comment.