Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findBreakingChanges: better message for removing standard scalar #2204

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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