Skip to content

Commit 0a56e28

Browse files
authored
Merge pull request #800 from joelgriffith/bugfix/find-breaking-arg-changes
Moving from raw instance check to name checks in `findBreakingArgChanges`
2 parents 490dc49 + c52949d commit 0a56e28

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/utilities/__tests__/findBreakingChanges-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,54 @@ describe('findBreakingChanges', () => {
392392
]);
393393
});
394394

395+
it('should not flag args with the same type signature as breaking', () => {
396+
const oldType = new GraphQLObjectType({
397+
name: 'Type1',
398+
fields: {
399+
field1: {
400+
type: GraphQLInt,
401+
args: {
402+
id: {
403+
type: new GraphQLNonNull(GraphQLInt),
404+
},
405+
},
406+
},
407+
},
408+
});
409+
410+
const newType = new GraphQLObjectType({
411+
name: 'Type1',
412+
fields: {
413+
field1: {
414+
type: GraphQLInt,
415+
args: {
416+
id: {
417+
type: new GraphQLNonNull(GraphQLInt),
418+
},
419+
},
420+
},
421+
},
422+
});
423+
424+
const oldSchema = new GraphQLSchema({
425+
query: queryType,
426+
types: [
427+
oldType,
428+
]
429+
});
430+
431+
const newSchema = new GraphQLSchema({
432+
query: queryType,
433+
types: [
434+
newType,
435+
]
436+
});
437+
438+
expect(
439+
findArgChanges(oldSchema, newSchema).breakingChanges
440+
).to.eql([]);
441+
});
442+
395443
it('should consider args that move away from NonNull as non-breaking', () => {
396444
const oldType = new GraphQLObjectType({
397445
name: 'Type1',

src/utilities/findBreakingChanges.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
GraphQLInterfaceType,
1717
GraphQLObjectType,
1818
GraphQLUnionType,
19-
getNullableType,
2019
} from '../type/definition';
2120

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

177+
const oldArgTypeName = getNamedType(oldArgDef.type);
178+
const newArgTypeName = newArgDef ?
179+
getNamedType(newArgDef.type) :
180+
null;
181+
182+
if (!oldArgTypeName) {
183+
return;
184+
}
185+
178186
// Arg not present
179-
if (newTypeArgIndex < 0) {
187+
if (!newArgTypeName) {
180188
breakingChanges.push({
181189
type: BreakingChangeType.ARG_REMOVED,
182190
description: `${oldType.name}.${fieldName} arg ` +
@@ -185,8 +193,7 @@ export function findArgChanges(
185193

186194
// Arg changed type in a breaking way
187195
} else if (
188-
oldArgDef.type !== newArgDef.type &&
189-
getNullableType(oldArgDef.type) !== newArgDef.type
196+
oldArgTypeName.name !== newArgTypeName.name
190197
) {
191198
breakingChanges.push({
192199
type: BreakingChangeType.ARG_CHANGED_KIND,

0 commit comments

Comments
 (0)