Skip to content

Commit

Permalink
findBreakingChanges: better message for removing standard scalar
Browse files Browse the repository at this point in the history
Fixes #2197
  • Loading branch information
IvanGoncharov committed Sep 27, 2019
1 parent 21de98e commit dce7d6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
33 changes: 30 additions & 3 deletions src/utilities/__tests__/findBreakingChanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -601,7 +627,7 @@ describe('findBreakingChanges', () => {
directive @DirectiveName on FIELD_DEFINITION | QUERY
type ArgThatChanges {
field1(id: Int): String
field1(id: Float): String
}
enum EnumTypeThatLosesAValue {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/utilities/findBreakingChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.`,
});
}

Expand Down

0 comments on commit dce7d6e

Please sign in to comment.