use of graphql.language.ScalarTypeDefinition in project graphql-java by graphql-java.
the class SchemaDiff method checkType.
private void checkType(DiffCtx ctx, Type oldType, Type newType) {
String typeName = getTypeName(oldType);
// prevent circular references
if (ctx.examiningType(typeName)) {
return;
}
if (isSystemScalar(typeName)) {
return;
}
if (isReservedType(typeName)) {
return;
}
Optional<TypeDefinition> oldTD = ctx.getOldTypeDef(oldType, TypeDefinition.class);
Optional<TypeDefinition> newTD = ctx.getNewTypeDef(newType, TypeDefinition.class);
if (!oldTD.isPresent()) {
ctx.report(DiffEvent.apiInfo().typeName(typeName).reasonMsg("Type '%s' is missing", typeName).build());
return;
}
TypeDefinition oldDef = oldTD.get();
ctx.report(DiffEvent.apiInfo().typeName(typeName).typeKind(getTypeKind(oldDef)).reasonMsg("Examining type '%s' ...", typeName).build());
if (!newTD.isPresent()) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(typeName).typeKind(getTypeKind(oldDef)).reasonMsg("The new API does not have a type called '%s'", typeName).build());
ctx.exitType();
return;
}
TypeDefinition newDef = newTD.get();
if (!oldDef.getClass().equals(newDef.getClass())) {
ctx.report(DiffEvent.apiBreakage().category(DiffCategory.INVALID).typeName(typeName).typeKind(getTypeKind(oldDef)).components(getTypeKind(oldDef), getTypeKind(newDef)).reasonMsg("The new API has changed '%s' from a '%s' to a '%s'", typeName, getTypeKind(oldDef), getTypeKind(newDef)).build());
ctx.exitType();
return;
}
if (oldDef instanceof ObjectTypeDefinition) {
checkObjectType(ctx, (ObjectTypeDefinition) oldDef, (ObjectTypeDefinition) newDef);
}
if (oldDef instanceof InterfaceTypeDefinition) {
checkInterfaceType(ctx, (InterfaceTypeDefinition) oldDef, (InterfaceTypeDefinition) newDef);
}
if (oldDef instanceof UnionTypeDefinition) {
checkUnionType(ctx, (UnionTypeDefinition) oldDef, (UnionTypeDefinition) newDef);
}
if (oldDef instanceof InputObjectTypeDefinition) {
checkInputObjectType(ctx, (InputObjectTypeDefinition) oldDef, (InputObjectTypeDefinition) newDef);
}
if (oldDef instanceof EnumTypeDefinition) {
checkEnumType(ctx, (EnumTypeDefinition) oldDef, (EnumTypeDefinition) newDef);
}
if (oldDef instanceof ScalarTypeDefinition) {
checkScalarType(ctx, (ScalarTypeDefinition) oldDef, (ScalarTypeDefinition) newDef);
}
ctx.exitType();
}
Aggregations