in src/main/com/intellij/lang/jsgraphql/types/schema/diff/SchemaDiff.java [763:838]
void checkDirectives(DiffCtx ctx,
TypeDefinition old,
List<Directive> oldDirectives,
List<Directive> newDirectives) {
if (!options.enforceDirectives) {
return;
}
Map<String, Directive> oldDirectivesMap = sortedMap(oldDirectives, Directive::getName);
Map<String, Directive> newDirectivesMap = sortedMap(newDirectives, Directive::getName);
for (String directiveName : oldDirectivesMap.keySet()) {
Directive oldDirective = oldDirectivesMap.get(directiveName);
Optional<Directive> newDirective = Optional.ofNullable(newDirectivesMap.get(directiveName));
if (newDirective.isEmpty()) {
ctx.report(DiffEvent.apiBreakage()
.category(DiffCategory.MISSING)
.typeName(old.getName())
.typeKind(getTypeKind(old))
.components(directiveName)
.reasonMsg("The new API does not have a directive named '%s' on type '%s'", directiveName,
old.getName())
.build());
continue;
}
Map<String, Argument> oldArgumentsByName = new TreeMap<>(oldDirective.getArgumentsByName());
Map<String, Argument> newArgumentsByName = new TreeMap<>(newDirective.get().getArgumentsByName());
if (oldArgumentsByName.size() > newArgumentsByName.size()) {
ctx.report(DiffEvent.apiBreakage()
.category(DiffCategory.MISSING)
.typeName(old.getName())
.typeKind(getTypeKind(old))
.components(directiveName)
.reasonMsg("The new API has less arguments on directive '%s' on type '%s' than the old API",
directiveName, old.getName())
.build());
return;
}
for (String argName : oldArgumentsByName.keySet()) {
Argument oldArgument = oldArgumentsByName.get(argName);
Optional<Argument> newArgument = Optional.ofNullable(newArgumentsByName.get(argName));
if (newArgument.isEmpty()) {
ctx.report(DiffEvent.apiBreakage()
.category(DiffCategory.MISSING)
.typeName(old.getName())
.typeKind(getTypeKind(old))
.components(directiveName, argName)
.reasonMsg("The new API does not have an argument named '%s' on directive '%s' on type '%s'",
argName, directiveName, old.getName())
.build());
}
else {
Value oldValue = oldArgument.getValue();
Value newValue = newArgument.get().getValue();
if (oldValue != null && newValue != null) {
if (!oldValue.getClass().equals(newValue.getClass())) {
ctx.report(DiffEvent.apiBreakage()
.category(DiffCategory.INVALID)
.typeName(old.getName())
.typeKind(getTypeKind(old))
.components(directiveName, argName)
.reasonMsg(
"The new API has changed value types on argument named '%s' on directive '%s' on type '%s'",
argName, directiveName, old.getName())
.build());
}
}
}
}
}
}