Skip to content
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
48 changes: 48 additions & 0 deletions src/utilities/__tests__/findBreakingChanges-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,54 @@ describe('findBreakingChanges', () => {
]);
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test asserts were not using instance equality to validate that an argument has changed in a breaking way (this test will fail if so)

it('should not flag args with the same type signature as breaking', () => {
const oldType = new GraphQLObjectType({
name: 'Type1',
fields: {
field1: {
type: GraphQLInt,
args: {
id: {
type: new GraphQLNonNull(GraphQLInt),
},
},
},
},
});

const newType = new GraphQLObjectType({
name: 'Type1',
fields: {
field1: {
type: GraphQLInt,
args: {
id: {
type: new GraphQLNonNull(GraphQLInt),
},
},
},
},
});

const oldSchema = new GraphQLSchema({
query: queryType,
types: [
oldType,
]
});

const newSchema = new GraphQLSchema({
query: queryType,
types: [
newType,
]
});

expect(
findArgChanges(oldSchema, newSchema).breakingChanges
).to.eql([]);
});

it('should consider args that move away from NonNull as non-breaking', () => {
const oldType = new GraphQLObjectType({
name: 'Type1',
Expand Down
15 changes: 11 additions & 4 deletions src/utilities/findBreakingChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLUnionType,
getNullableType,
} from '../type/definition';

import type { GraphQLNamedType, GraphQLFieldMap } from '../type/definition';
Expand Down Expand Up @@ -175,8 +174,17 @@ export function findArgChanges(
);
const newArgDef = newArgs[newTypeArgIndex];

const oldArgTypeName = getNamedType(oldArgDef.type);
const newArgTypeName = newArgDef ?
getNamedType(newArgDef.type) :
null;

if (!oldArgTypeName) {
return;
}

// Arg not present
if (newTypeArgIndex < 0) {
if (!newArgTypeName) {
breakingChanges.push({
type: BreakingChangeType.ARG_REMOVED,
description: `${oldType.name}.${fieldName} arg ` +
Expand All @@ -185,8 +193,7 @@ export function findArgChanges(

// Arg changed type in a breaking way
} else if (
oldArgDef.type !== newArgDef.type &&
getNullableType(oldArgDef.type) !== newArgDef.type
oldArgTypeName.name !== newArgTypeName.name
) {
breakingChanges.push({
type: BreakingChangeType.ARG_CHANGED_KIND,
Expand Down