Skip to content

Commit

Permalink
BC checker: use readable snapshot output
Browse files Browse the repository at this point in the history
This output has less information but it should be the right subset to check breaking changes affecting our clients. The good thing is that it's very well readable for us.

kiwicom-source-id: 32abf3c34699c205128c2d6cb7da673aa51e9afa
  • Loading branch information
mrtnzlml authored and kiwicom-github-bot committed Apr 8, 2019
1 parent d18ef06 commit 78475aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/packages/bc-checker/README.md
@@ -0,0 +1,5 @@
TODO:

- turn this script into bin file (for NPM usage)
- add "allow BC break option" with BC breaks changelog
- add README
3 changes: 2 additions & 1 deletion src/packages/bc-checker/package.json
Expand Up @@ -4,6 +4,7 @@
"version": "0.0.0",
"main": "src/index.js",
"dependencies": {
"@kiwicom/signed-source": "^0"
"@kiwicom/signed-source": "^0",
"chalk": "^2.4.1"
}
}
23 changes: 7 additions & 16 deletions src/packages/bc-checker/src/index.js
@@ -1,12 +1,7 @@
// @flow
/* eslint-disable */

import {
findBreakingChanges,
buildClientSchema,
introspectionQuery,
graphql,
} from 'graphql';
import { findBreakingChanges, buildSchema, printSchema } from 'graphql';
import SignedSource from '@kiwicom/signed-source';
import chalk from 'chalk';
import path from 'path';
Expand All @@ -15,7 +10,10 @@ import fs from 'fs';
import schema from '../../../Schema.js';
import paths from '../../../../paths';

const snapshotLocation = path.join(paths.scripts, 'graphql-schema-snapshot.js');
const snapshotLocation = path.join(
paths.scripts,
'graphql-schema-snapshot.graphql',
);

const printChanges = (changes: Object[]) => {
console.error('');
Expand All @@ -26,8 +24,7 @@ const printChanges = (changes: Object[]) => {
};

(async () => {
// $FlowExpectedError: the parameter passed to require() must be a literal string
const oldSchema = buildClientSchema(require(snapshotLocation));
const oldSchema = buildSchema(fs.readFileSync(snapshotLocation).toString());
const newSchema = schema;

const changes = findBreakingChanges(oldSchema, newSchema);
Expand Down Expand Up @@ -56,15 +53,9 @@ const printChanges = (changes: Object[]) => {
process.exit(1);
}

// non-breaking changes must be committed
const meta = await graphql(schema, introspectionQuery);
const oldSnapshot = fs.readFileSync(snapshotLocation, { encoding: 'utf-8' });
const newSnapshot = SignedSource.signFile(
`// ${SignedSource.getSigningToken()}\n\nmodule.exports = ${JSON.stringify(
meta.data,
null,
2,
)}\n`,
`# ${SignedSource.getSigningToken()}\n\n${printSchema(schema)}`,
);

if (!SignedSource.verifySignature(oldSnapshot)) {
Expand Down

0 comments on commit 78475aa

Please sign in to comment.