From 53f235ca5fbeb58ce179e434e02fabf5d29a4cf9 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 14 Aug 2019 15:30:35 -0700 Subject: [PATCH 1/3] 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 17fe1aa976..7a462614a4 100644 --- a/packages/apollo/src/commands/service/check.ts +++ b/packages/apollo/src/commands/service/check.ts @@ -110,18 +110,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" @@ -136,13 +141,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( @@ -156,6 +155,8 @@ ${ diffToPrevious.affectedClients && diffToPrevious.affectedClients.length, "client" )}**` + : diffToPrevious.changes.length === 0 + ? `✅ Found **no changes**.` : `✅ Found **no breaking changes**.` } From 63a7c87437e941e1b1d095e5bc5c50702d2adf8e Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 21 Aug 2019 11:04:07 -0700 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b598f1f294..fb0a03eacb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - `apollo` - Shorten `client:check` and `service:check` output in CI [#1404](https://github.com/apollographql/apollo-tooling/pull/1404) + - service:check add null check for validation config [#1471](https://github.com/apollographql/apollo-tooling/pull/1471) - `apollo-codegen-core` - - `apollo-codegen-flow` From 3d99cc08e486682b34f3fb3da2b1e97f8f7437e4 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 21 Aug 2019 12:04:04 -0700 Subject: [PATCH 3/3] add test for no changes and update snapshots --- .../__snapshots__/check.test.ts.snap | 13 +++++++- .../commands/service/__tests__/check.test.ts | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/apollo/src/commands/service/__tests__/__snapshots__/check.test.ts.snap b/packages/apollo/src/commands/service/__tests__/__snapshots__/check.test.ts.snap index d79773ed23..7823d4c60f 100644 --- a/packages/apollo/src/commands/service/__tests__/__snapshots__/check.test.ts.snap +++ b/packages/apollo/src/commands/service/__tests__/__snapshots__/check.test.ts.snap @@ -316,9 +316,20 @@ exports[`service:check markdown formatting is correct with no breaking changes 1 " ### Apollo Service Check 🔄 Validated your local schema against schema tag \`staging\` on graph \`engine\`. -🔢 Compared **0 schema changes** against **100 operations** seen over the **last 24 hours**. +🔢 Compared **1 schema change** against **100 operations** seen over the **last 24 hours**. ✅ Found **no breaking changes**. 🔗 [View your service check details](https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z?graphCompositionId=fff). " `; + +exports[`service:check markdown formatting is correct with no changes 1`] = ` +" +### Apollo Service Check +🔄 Validated your local schema against schema tag \`staging\` on graph \`engine\`. + +✅ Found **no changes**. + +🔗 [View your service check details](https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z?graphCompositionId=fff). +" +`; diff --git a/packages/apollo/src/commands/service/__tests__/check.test.ts b/packages/apollo/src/commands/service/__tests__/check.test.ts index b0027a624a..7072bdf52e 100644 --- a/packages/apollo/src/commands/service/__tests__/check.test.ts +++ b/packages/apollo/src/commands/service/__tests__/check.test.ts @@ -9,6 +9,7 @@ import chalk from "chalk"; import nock = require("nock"); import { stdout, stderr } from "stdout-stderr"; import * as graphql from "graphql"; +import { graphqlTypes } from "apollo-language-server"; /** * Single URL for all local requests to be mocked @@ -696,7 +697,34 @@ describe("service:check", () => { severity: ChangeSeverity.NOTICE, affectedClients: [], affectedQueries: [], - changes: [] + changes: [ + { + __typename: "Change", + code: "FIELD_ADDED", + severity: ChangeSeverity.NOTICE + } as graphqlTypes.CheckSchema_service_checkSchema_diffToPrevious_changes + ] + } + }, + graphCompositionID: "fff" + }) + ).toMatchSnapshot(); + }); + + it("is correct with no changes", () => { + expect( + formatMarkdown({ + graphName: "engine", + tag: "staging", + checkSchemaResult: { + ...checkSchemaResult, + diffToPrevious: { + ...checkSchemaResult.diffToPrevious, + severity: ChangeSeverity.NOTICE, + affectedClients: [], + affectedQueries: [], + changes: [], + validationConfig: null } }, graphCompositionID: "fff"