From dce7d6e69034a1338a7ee61c980ad74218be1f22 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 27 Sep 2019 14:36:00 +0300 Subject: [PATCH] findBreakingChanges: better message for removing standard scalar Fixes #2197 --- .../__tests__/findBreakingChanges-test.js | 33 +++++++++++++++++-- src/utilities/findBreakingChanges.js | 5 ++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/utilities/__tests__/findBreakingChanges-test.js b/src/utilities/__tests__/findBreakingChanges-test.js index ddb0cf9c1a..420ee42b68 100644 --- a/src/utilities/__tests__/findBreakingChanges-test.js +++ b/src/utilities/__tests__/findBreakingChanges-test.js @@ -37,6 +37,32 @@ describe('findBreakingChanges', () => { expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]); }); + it('should detect if a standard scalar was removed', () => { + const oldSchema = buildSchema(` + type Query { + foo: Float + } + `); + + const newSchema = buildSchema(` + type Query { + foo: String + } + `); + expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([ + { + type: BreakingChangeType.TYPE_REMOVED, + description: + 'Standard scalar Float was removed because it is not referenced anymore.', + }, + { + type: BreakingChangeType.FIELD_CHANGED_KIND, + description: 'Query.foo changed type from Float to String.', + }, + ]); + expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]); + }); + it('should detect if a type changed its type', () => { const oldSchema = buildSchema(` scalar TypeWasScalarBecomesEnum @@ -601,7 +627,7 @@ describe('findBreakingChanges', () => { directive @DirectiveName on FIELD_DEFINITION | QUERY type ArgThatChanges { - field1(id: Int): String + field1(id: Float): String } enum EnumTypeThatLosesAValue { @@ -660,7 +686,8 @@ describe('findBreakingChanges', () => { expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([ { type: BreakingChangeType.TYPE_REMOVED, - description: 'Int was removed.', + description: + 'Standard scalar Float was removed because it is not referenced anymore.', }, { type: BreakingChangeType.TYPE_REMOVED, @@ -669,7 +696,7 @@ describe('findBreakingChanges', () => { { type: BreakingChangeType.ARG_CHANGED_KIND, description: - 'ArgThatChanges.field1 arg id has changed type from Int to String.', + 'ArgThatChanges.field1 arg id has changed type from Float to String.', }, { type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM, diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index d53b107dd7..98863f8402 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -10,6 +10,7 @@ import { print } from '../language/printer'; import { visit } from '../language/visitor'; import { type GraphQLSchema } from '../type/schema'; +import { isSpecifiedScalarType } from '../type/scalars'; import { type GraphQLField, type GraphQLType, @@ -176,7 +177,9 @@ function findTypeChanges( for (const oldType of typesDiff.removed) { schemaChanges.push({ type: BreakingChangeType.TYPE_REMOVED, - description: `${oldType.name} was removed.`, + description: isSpecifiedScalarType(oldType) + ? `Standard scalar ${oldType.name} was removed because it is not referenced anymore.` + : `${oldType.name} was removed.`, }); }