Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service:check add null check for validation config #1471

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
- <First `apollo-codegen-core` related entry goes here>
- `apollo-codegen-flow`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"
`;
30 changes: 29 additions & 1 deletion packages/apollo/src/commands/service/__tests__/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
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 @@ -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"
Expand All @@ -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(
Expand All @@ -156,6 +155,8 @@ ${
diffToPrevious.affectedClients && diffToPrevious.affectedClients.length,
"client"
)}**`
: diffToPrevious.changes.length === 0
? `✅ Found **no changes**.`
: `✅ Found **no breaking changes**.`
}

Expand Down