Skip to content

Commit 07ac11a

Browse files
sam-swarrleebyron
authored andcommitted
Add utility functions to compare schemas (#508)
* Add utility functions to compare schemas * Add top level check that invokes other sub checks * Return Arrays instead of Sets, forEach instead of for in, other tweaks * Return a BreakingChange object rather than just a string * Only expose findBreakingChanges; other minor changes * Add static prettyName property to Type classes
1 parent 3e9d493 commit 07ac11a

File tree

5 files changed

+680
-0
lines changed

5 files changed

+680
-0
lines changed

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,7 @@ export {
203203

204204
// Asserts a string is a valid GraphQL name.
205205
assertValidName,
206+
207+
// Compares two GraphQLSchemas and detects breaking changes.
208+
findBreakingChanges,
206209
} from './utilities';

src/type/definition.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ export class GraphQLScalarType {
223223

224224
_scalarConfig: GraphQLScalarTypeConfig<*, *>;
225225

226+
static prettyName: string = 'Scalar';
227+
226228
constructor(config: GraphQLScalarTypeConfig<*, *>) {
227229
invariant(config.name, 'Type must be named.');
228230
assertValidName(config.name);
@@ -324,6 +326,8 @@ export class GraphQLObjectType {
324326
_fields: GraphQLFieldDefinitionMap;
325327
_interfaces: Array<GraphQLInterfaceType>;
326328

329+
static prettyName: string = 'Object';
330+
327331
constructor(config: GraphQLObjectTypeConfig<*>) {
328332
invariant(config.name, 'Type must be named.');
329333
assertValidName(config.name);
@@ -570,6 +574,8 @@ export class GraphQLInterfaceType {
570574
_typeConfig: GraphQLInterfaceTypeConfig;
571575
_fields: GraphQLFieldDefinitionMap;
572576

577+
static prettyName: string = 'Interface';
578+
573579
constructor(config: GraphQLInterfaceTypeConfig) {
574580
invariant(config.name, 'Type must be named.');
575581
assertValidName(config.name);
@@ -641,6 +647,8 @@ export class GraphQLUnionType {
641647
_types: Array<GraphQLObjectType>;
642648
_possibleTypeNames: {[typeName: string]: boolean};
643649

650+
static prettyName: string = 'Union';
651+
644652
constructor(config: GraphQLUnionTypeConfig) {
645653
invariant(config.name, 'Type must be named.');
646654
assertValidName(config.name);
@@ -742,6 +750,8 @@ export class GraphQLEnumType/* <T> */ {
742750
_valueLookup: Map<any/* T */, GraphQLEnumValueDefinition>;
743751
_nameLookup: { [valueName: string]: GraphQLEnumValueDefinition };
744752

753+
static prettyName: string = 'Enum';
754+
745755
constructor(config: GraphQLEnumTypeConfig/* <T> */) {
746756
this.name = config.name;
747757
assertValidName(config.name);
@@ -893,6 +903,8 @@ export class GraphQLInputObjectType {
893903
_typeConfig: InputObjectConfig;
894904
_fields: InputObjectFieldMap;
895905

906+
static prettyName: string = 'InputObject';
907+
896908
constructor(config: InputObjectConfig) {
897909
invariant(config.name, 'Type must be named.');
898910
assertValidName(config.name);

0 commit comments

Comments
 (0)