Skip to content

Commit 1f92241

Browse files
authored
Merge pull request #3984 from mgadda/add-interface-addition-event
Add interface addition event in SchemaDiff
2 parents 700fcf0 + 073b317 commit 1f92241

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/main/java/graphql/schema/diff/SchemaDiff.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public int diffSchema(DiffSet diffSet, DifferenceReporter reporter) {
135135
* This will perform a difference on the two schemas. The reporter callback
136136
* interface will be called when differences are encountered.
137137
*
138-
* @param schemaDiffSet the two schemas to compare for difference
139-
* @param reporter the place to report difference events to
138+
* @param schemaDiffSet the two schemas to compare for difference
139+
* @param reporter the place to report difference events to
140140
*
141141
* @return the number of API breaking changes
142142
*/
@@ -533,6 +533,19 @@ private void checkImplements(DiffCtx ctx, ObjectTypeDefinition old, List<Type> o
533533
checkInterfaceType(ctx, oldInterface.get(), newInterface.get());
534534
}
535535
}
536+
537+
for (Map.Entry<String, Type> entry : newImplementsMap.entrySet()) {
538+
Optional<InterfaceTypeDefinition> newInterface = ctx.getNewTypeDef(entry.getValue(), InterfaceTypeDefinition.class);
539+
if (!oldImplementsMap.containsKey(entry.getKey())) {
540+
ctx.report(DiffEvent.apiInfo()
541+
.category(DiffCategory.ADDITION)
542+
.typeName(old.getName())
543+
.typeKind(getTypeKind(old))
544+
.components(newInterface.get().getName())
545+
.reasonMsg("The new API has added the interface named '%s'", newInterface.get().getName())
546+
.build());
547+
}
548+
}
536549
}
537550

538551

src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,4 +768,43 @@ class SchemaDiffTest extends Specification {
768768
then:
769769
thrown(AssertException)
770770
}
771+
772+
def "checkImplements emits ADDITION events for new interfaces"() {
773+
def oldSchema = TestUtil.schema('''
774+
type Query {
775+
foo: Foo
776+
}
777+
type Foo {
778+
a: String
779+
}
780+
interface Bar {
781+
a: String
782+
}
783+
''')
784+
def newSchema = TestUtil.schema('''
785+
type Query {
786+
foo: Foo
787+
}
788+
type Foo implements Bar {
789+
a: String
790+
}
791+
interface Bar {
792+
a: String
793+
}
794+
''')
795+
796+
when:
797+
compareDiff(oldSchema, newSchema)
798+
799+
then:
800+
validateReportersAreEqual()
801+
introspectionReporter.breakageCount == 0
802+
introspectionReporter.infos.any {
803+
it.category == DiffCategory.ADDITION &&
804+
it.typeKind == TypeKind.Object &&
805+
it.typeName == "Foo" &&
806+
it.level == DiffLevel.INFO
807+
}
808+
809+
}
771810
}

0 commit comments

Comments
 (0)