Skip to content

Add interface addition event in SchemaDiff #3984

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

Merged
merged 4 commits into from
Jul 1, 2025
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
17 changes: 15 additions & 2 deletions src/main/java/graphql/schema/diff/SchemaDiff.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public int diffSchema(DiffSet diffSet, DifferenceReporter reporter) {
* This will perform a difference on the two schemas. The reporter callback
* interface will be called when differences are encountered.
*
* @param schemaDiffSet the two schemas to compare for difference
* @param reporter the place to report difference events to
* @param schemaDiffSet the two schemas to compare for difference
* @param reporter the place to report difference events to
*
* @return the number of API breaking changes
*/
Expand Down Expand Up @@ -533,6 +533,19 @@ private void checkImplements(DiffCtx ctx, ObjectTypeDefinition old, List<Type> o
checkInterfaceType(ctx, oldInterface.get(), newInterface.get());
}
}

for (Map.Entry<String, Type> entry : newImplementsMap.entrySet()) {
Optional<InterfaceTypeDefinition> newInterface = ctx.getNewTypeDef(entry.getValue(), InterfaceTypeDefinition.class);
if (!oldImplementsMap.containsKey(entry.getKey())) {
ctx.report(DiffEvent.apiInfo()
.category(DiffCategory.ADDITION)
.typeName(old.getName())
.typeKind(getTypeKind(old))
.components(newInterface.get().getName())
.reasonMsg("The new API has added the interface named '%s'", newInterface.get().getName())
.build());
}
}
}


Expand Down
39 changes: 39 additions & 0 deletions src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,43 @@ class SchemaDiffTest extends Specification {
then:
thrown(AssertException)
}

def "checkImplements emits ADDITION events for new interfaces"() {
def oldSchema = TestUtil.schema('''
type Query {
foo: Foo
}
type Foo {
a: String
}
interface Bar {
a: String
}
''')
def newSchema = TestUtil.schema('''
type Query {
foo: Foo
}
type Foo implements Bar {
a: String
}
interface Bar {
a: String
}
''')

when:
compareDiff(oldSchema, newSchema)

then:
validateReportersAreEqual()
introspectionReporter.breakageCount == 0
introspectionReporter.infos.any {
it.category == DiffCategory.ADDITION &&
it.typeKind == TypeKind.Object &&
it.typeName == "Foo" &&
it.level == DiffLevel.INFO
}

}
}