Skip to content

Commit b80312a

Browse files
committed
findBreakingChanges: better message for removing standard scalar
Fixes #2197
1 parent 21de98e commit b80312a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ describe('findBreakingChanges', () => {
3737
expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]);
3838
});
3939

40+
it('should detect if a standard scalar was removed', () => {
41+
const oldSchema = buildSchema(`
42+
type Query {
43+
foo: Float
44+
}
45+
`);
46+
47+
const newSchema = buildSchema(`
48+
type Query {
49+
foo: String
50+
}
51+
`);
52+
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
53+
{
54+
type: BreakingChangeType.TYPE_REMOVED,
55+
description: 'Standard scalar Float was removed because it is not referenced anymore.',
56+
},
57+
{
58+
type: BreakingChangeType.FIELD_CHANGED_KIND,
59+
description: 'Query.foo changed type from Float to String.',
60+
}
61+
]);
62+
expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]);
63+
});
64+
4065
it('should detect if a type changed its type', () => {
4166
const oldSchema = buildSchema(`
4267
scalar TypeWasScalarBecomesEnum
@@ -601,7 +626,7 @@ describe('findBreakingChanges', () => {
601626
directive @DirectiveName on FIELD_DEFINITION | QUERY
602627
603628
type ArgThatChanges {
604-
field1(id: Int): String
629+
field1(id: Float): String
605630
}
606631
607632
enum EnumTypeThatLosesAValue {
@@ -660,7 +685,7 @@ describe('findBreakingChanges', () => {
660685
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
661686
{
662687
type: BreakingChangeType.TYPE_REMOVED,
663-
description: 'Int was removed.',
688+
description: 'Standard scalar Float was removed because it is not referenced anymore.',
664689
},
665690
{
666691
type: BreakingChangeType.TYPE_REMOVED,
@@ -669,7 +694,7 @@ describe('findBreakingChanges', () => {
669694
{
670695
type: BreakingChangeType.ARG_CHANGED_KIND,
671696
description:
672-
'ArgThatChanges.field1 arg id has changed type from Int to String.',
697+
'ArgThatChanges.field1 arg id has changed type from Float to String.',
673698
},
674699
{
675700
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,

src/utilities/findBreakingChanges.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { print } from '../language/printer';
1010
import { visit } from '../language/visitor';
1111

1212
import { type GraphQLSchema } from '../type/schema';
13+
import { isSpecifiedScalarType } from '../type/scalars';
1314
import {
1415
type GraphQLField,
1516
type GraphQLType,
@@ -176,7 +177,9 @@ function findTypeChanges(
176177
for (const oldType of typesDiff.removed) {
177178
schemaChanges.push({
178179
type: BreakingChangeType.TYPE_REMOVED,
179-
description: `${oldType.name} was removed.`,
180+
description: isSpecifiedScalarType(oldType)
181+
? `Standard scalar ${oldType.name} was removed because it is not referenced anymore.`
182+
: `${oldType.name} was removed.`,
180183
});
181184
}
182185

0 commit comments

Comments
 (0)