From 74ab4cea5c93e5eeab84f69bce494a1b0497e559 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 14 Aug 2019 15:30:35 -0700 Subject: [PATCH] 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 --- packages/apollo/src/commands/service/check.ts | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/apollo/src/commands/service/check.ts b/packages/apollo/src/commands/service/check.ts index f11a919cd8..67f3be76e2 100644 --- a/packages/apollo/src/commands/service/check.ts +++ b/packages/apollo/src/commands/service/check.ts @@ -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" @@ -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( @@ -151,6 +150,8 @@ ${ diffToPrevious.affectedClients && diffToPrevious.affectedClients.length, "client" )}**` + : diffToPrevious.changes.length === 0 + ? `✅ Found **no changes**.` : `✅ Found **no breaking changes**.` }