diff --git a/src/utilities/__tests__/findBreakingChanges-test.js b/src/utilities/__tests__/findBreakingChanges-test.js index 8ef9c11650..70711a230e 100644 --- a/src/utilities/__tests__/findBreakingChanges-test.js +++ b/src/utilities/__tests__/findBreakingChanges-test.js @@ -392,6 +392,54 @@ describe('findBreakingChanges', () => { ]); }); + 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', diff --git a/src/utilities/findBreakingChanges.js b/src/utilities/findBreakingChanges.js index 3fdde6cd24..337a76ade9 100644 --- a/src/utilities/findBreakingChanges.js +++ b/src/utilities/findBreakingChanges.js @@ -16,7 +16,6 @@ import { GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, - getNullableType, } from '../type/definition'; import type { GraphQLNamedType, GraphQLFieldMap } from '../type/definition'; @@ -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 ` + @@ -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,