Skip to content

Commit 01d4cf0

Browse files
findBreakingChanges: better message for removing standard scalar (#2204)
Fixes #2197
1 parent 21de98e commit 01d4cf0

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ 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:
56+
'Standard scalar Float was removed because it is not referenced anymore.',
57+
},
58+
{
59+
type: BreakingChangeType.FIELD_CHANGED_KIND,
60+
description: 'Query.foo changed type from Float to String.',
61+
},
62+
]);
63+
expect(findBreakingChanges(oldSchema, oldSchema)).to.deep.equal([]);
64+
});
65+
4066
it('should detect if a type changed its type', () => {
4167
const oldSchema = buildSchema(`
4268
scalar TypeWasScalarBecomesEnum
@@ -601,7 +627,7 @@ describe('findBreakingChanges', () => {
601627
directive @DirectiveName on FIELD_DEFINITION | QUERY
602628
603629
type ArgThatChanges {
604-
field1(id: Int): String
630+
field1(id: Float): String
605631
}
606632
607633
enum EnumTypeThatLosesAValue {
@@ -660,7 +686,8 @@ describe('findBreakingChanges', () => {
660686
expect(findBreakingChanges(oldSchema, newSchema)).to.deep.equal([
661687
{
662688
type: BreakingChangeType.TYPE_REMOVED,
663-
description: 'Int was removed.',
689+
description:
690+
'Standard scalar Float was removed because it is not referenced anymore.',
664691
},
665692
{
666693
type: BreakingChangeType.TYPE_REMOVED,
@@ -669,7 +696,7 @@ describe('findBreakingChanges', () => {
669696
{
670697
type: BreakingChangeType.ARG_CHANGED_KIND,
671698
description:
672-
'ArgThatChanges.field1 arg id has changed type from Int to String.',
699+
'ArgThatChanges.field1 arg id has changed type from Float to String.',
673700
},
674701
{
675702
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)