interfaces and enums

This commit is contained in:
Ben Roberts 2017-11-16 15:25:25 -05:00
parent 6e95b81aee
commit 55f6d6cf47

View File

@ -467,31 +467,29 @@ class FindBreakingChanges
Schema $oldSchema, Schema $newSchema Schema $oldSchema, Schema $newSchema
) )
{ {
/* const oldTypeMap = oldSchema.getTypeMap(); $newTypeMap = $newSchema->getTypeMap();
const newTypeMap = newSchema.getTypeMap();
const typesAddedToUnion = []; $typesAddedToUnion = [];
Object.keys(newTypeMap).forEach(typeName => {
const oldType = oldTypeMap[typeName]; foreach ($newTypeMap as $typeName => $oldType) {
const newType = newTypeMap[typeName]; $newType = isset($newTypeMap[$typeName]) ? $newTypeMap[$typeName] : null;
if (!(oldType instanceof GraphQLUnionType) || if (!($oldType instanceof UnionType) || !($newType instanceof UnionType)) {
!(newType instanceof GraphQLUnionType)) { continue;
return;
} }
const typeNamesInOldUnion = Object.create(null);
oldType.getTypes().forEach(type => { $typeNamesInOldUnion = [];
typeNamesInOldUnion[type.name] = true; foreach ($oldType->getTypes() as $type) {
}); $typeNamesInOldUnion[$type->name] = true;
newType.getTypes().forEach(type => {
if (!typeNamesInOldUnion[type.name]) {
typesAddedToUnion.push({
type: DangerousChangeType.TYPE_ADDED_TO_UNION,
description: `${type.name} was added to union type ${typeName}.`
});
} }
}); foreach ($newType->getTypes() as $type) {
}); if (!isset($typeNamesInOldUnion[$type->name])) {
return typesAddedToUnion;*/ $addedTypeName = $type->name;
$typesRemovedFromUnion[] = ['type' => self::DANGEROUS_CHANGE_TYPE_ADDED_TO_UNION, 'description' => "${addedTypeName} was removed to union type ${typeName}"];
}
}
}
return $typesAddedToUnion;
} }
/** /**
@ -502,31 +500,29 @@ class FindBreakingChanges
Schema $oldSchema, Schema $newSchema Schema $oldSchema, Schema $newSchema
) )
{ {
/* const oldTypeMap = oldSchema.getTypeMap(); $oldTypeMap = $oldSchema->getTypeMap();
const newTypeMap = newSchema.getTypeMap(); $newTypeMap = $newSchema->getTypeMap();
const valuesRemovedFromEnums = []; $valuesRemovedFromEnums = [];
Object.keys(oldTypeMap).forEach(typeName => {
const oldType = oldTypeMap[typeName]; foreach ($oldTypeMap as $typeName => $oldType) {
const newType = newTypeMap[typeName]; $newType = isset($newTypeMap[$typeName]) ? $newTypeMap[$typeName] : null;
if (!(oldType instanceof GraphQLEnumType) || if (!($oldType instanceof EnumType) || !($newType instanceof EnumType)) {
!(newType instanceof GraphQLEnumType)) { continue;
return;
} }
const valuesInNewEnum = Object.create(null); $valuesInNewEnum = [];
newType.getValues().forEach(value => { foreach ($newType->getValues() as $value) {
valuesInNewEnum[value.name] = true; $valuesInNewEnum[$value->name] = true;
});
oldType.getValues().forEach(value => {
if (!valuesInNewEnum[value.name]) {
valuesRemovedFromEnums.push({
type: BreakingChangeType.VALUE_REMOVED_FROM_ENUM,
description: `${value.name} was removed from enum type ${typeName}.`
});
} }
}); foreach ($oldType->getValues() as $value) {
}); if (!isset($valuesInNewEnum[$value->name])) {
return valuesRemovedFromEnums;*/ $valueName = $value->name;
$valuesRemovedFromEnums[] = ['type' => self::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM, 'description' => "${valueName} was removed from enum type ${typeName}"];
}
}
}
return $valuesRemovedFromEnums;
} }
/** /**
@ -537,65 +533,58 @@ class FindBreakingChanges
Schema $oldSchema, Schema $newSchema Schema $oldSchema, Schema $newSchema
) )
{ {
/* const oldTypeMap = oldSchema.getTypeMap(); $oldTypeMap = $oldSchema->getTypeMap();
const newTypeMap = newSchema.getTypeMap(); $newTypeMap = $newSchema->getTypeMap();
const valuesAddedToEnums = []; $valuesAddedToEnums = [];
Object.keys(oldTypeMap).forEach(typeName => { foreach ($oldTypeMap as $typeName => $oldType) {
const oldType = oldTypeMap[typeName]; $newType = isset($newTypeMap[$typeName]) ? $newTypeMap[$typeName] : null;
const newType = newTypeMap[typeName]; if (!($oldType instanceof EnumType) || !($newType instanceof EnumType)) {
if (!(oldType instanceof GraphQLEnumType) || continue;
!(newType instanceof GraphQLEnumType)) { }
return; $valuesInOldEnum = [];
foreach ($oldType->getValues() as $value) {
$valuesInOldEnum[$value->name] = true;
}
foreach ($newType->getValues() as $value) {
if (!isset($valuesInOldEnum[$value->name])) {
$valueName = $value->name;
$valuesAddedToEnums[] = ['type' => self::DANGEROUS_CHANGE_VALUE_ADDED_TO_ENUM, 'description' => "${valueName} was added to enum type ${typeName}"];
}
}
} }
const valuesInOldEnum = Object.create(null); return $valuesAddedToEnums;
oldType.getValues().forEach(value => {
valuesInOldEnum[value.name] = true;
});
newType.getValues().forEach(value => {
if (!valuesInOldEnum[value.name]) {
valuesAddedToEnums.push({
type: DangerousChangeType.VALUE_ADDED_TO_ENUM,
description: `${value.name} was added to enum type ${typeName}.`
});
}
});
});
return valuesAddedToEnums;*/
} }
public static function findInterfacesRemovedFromObjectTypes( public static function findInterfacesRemovedFromObjectTypes(
Schema $oldSchema, Schema $newSchema Schema $oldSchema, Schema $newSchema
) )
{ {
/* const oldTypeMap = oldSchema.getTypeMap(); $oldTypeMap = $oldSchema->getTypeMap();
const newTypeMap = newSchema.getTypeMap(); $newTypeMap = $newSchema->getTypeMap();
const breakingChanges = [];
Object.keys(oldTypeMap).forEach(typeName => { $breakingChanges = [];
const oldType = oldTypeMap[typeName]; foreach ($oldTypeMap as $typeName => $oldType) {
const newType = newTypeMap[typeName]; $newType = isset($newTypeMap[$typeName]) ? $newTypeMap[$typeName] : null;
if ( if (!($oldType instanceof ObjectType) || !($newType instanceof ObjectType)) {
!(oldType instanceof GraphQLObjectType) || continue;
!(newType instanceof GraphQLObjectType)
) {
return;
} }
const oldInterfaces = oldType.getInterfaces(); $oldInterfaces = $oldType->getInterfaces();
const newInterfaces = newType.getInterfaces(); $newInterfaces = $newType->getInterfaces();
oldInterfaces.forEach(oldInterface => { foreach ($oldInterfaces as $oldInterface) {
if (!newInterfaces.some(int => int.name === oldInterface.name)) { if (!Utils::find($newInterfaces, function (InterfaceType $interface) use ($oldInterface) {
breakingChanges.push({ return $interface->name === $oldInterface->name;
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT, })) {
description: `${typeName} no longer implements interface ` + $oldInterfaceName = $oldInterface->name;
`${oldInterface.name}.` $breakingChanges[] = ['type' => self::BREAKING_CHANGE_INTERFACE_REMOVED_FROM_OBJECT,
}); 'description' => "${typeName} no longer implements interface ${oldInterfaceName}"
];
} }
}); }
}); }
return breakingChanges;*/ return $breakingChanges;
} }
/** /**