mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Invert instance of in BCFinder
This commit is contained in:
parent
20e98aefa4
commit
d97fac6ab0
@ -112,27 +112,31 @@ class BreakingChangesFinder
|
||||
* @return string[][]
|
||||
*/
|
||||
public static function findTypesThatChangedKind(
|
||||
Schema $oldSchema,
|
||||
Schema $newSchema
|
||||
) {
|
||||
$oldTypeMap = $oldSchema->getTypeMap();
|
||||
$newTypeMap = $newSchema->getTypeMap();
|
||||
Schema $schemaA,
|
||||
Schema $schemaB
|
||||
) : iterable {
|
||||
$schemaATypeMap = $schemaA->getTypeMap();
|
||||
$schemaBTypeMap = $schemaB->getTypeMap();
|
||||
|
||||
$breakingChanges = [];
|
||||
foreach ($oldTypeMap as $typeName => $oldType) {
|
||||
if (! isset($newTypeMap[$typeName])) {
|
||||
foreach ($schemaATypeMap as $typeName => $schemaAType) {
|
||||
if (! isset($schemaBTypeMap[$typeName])) {
|
||||
continue;
|
||||
}
|
||||
$newType = $newTypeMap[$typeName];
|
||||
if ($oldType instanceof $newType) {
|
||||
$schemaBType = $schemaBTypeMap[$typeName];
|
||||
if ($schemaAType instanceof $schemaBType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oldTypeKindName = self::typeKindName($oldType);
|
||||
$newTypeKindName = self::typeKindName($newType);
|
||||
$breakingChanges[] = [
|
||||
if ($schemaBType instanceof $schemaAType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$schemaATypeKindName = self::typeKindName($schemaAType);
|
||||
$schemaBTypeKindName = self::typeKindName($schemaBType);
|
||||
$breakingChanges[] = [
|
||||
'type' => self::BREAKING_CHANGE_TYPE_CHANGED_KIND,
|
||||
'description' => "${typeName} changed from ${oldTypeKindName} to ${newTypeKindName}.",
|
||||
'description' => "${typeName} changed from ${schemaATypeKindName} to ${schemaBTypeKindName}.",
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,47 @@ class BreakingChangesFinderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to compare type of class A (old type) and type of class B (new type)
|
||||
* Class B extends A but are evaluated as same types (if all properties match).
|
||||
* The reason is that when constructing schema from remote schema,
|
||||
* we have no certain way to get information about our classes.
|
||||
* Thus object types from remote schema are constructed as Object Type
|
||||
* while their local counterparts are usually a subclass of Object Type.
|
||||
*
|
||||
* @see https://github.com/webonyx/graphql-php/pull/431
|
||||
*/
|
||||
public function testShouldNotMarkTypesWithInheritedClassesAsChanged() : void
|
||||
{
|
||||
$objectTypeConstructedFromRemoteSchema = new ObjectType([
|
||||
'name' => 'ObjectType',
|
||||
'fields' => [
|
||||
'field1' => ['type' => Type::string()],
|
||||
],
|
||||
]);
|
||||
|
||||
$localObjectType = new class([
|
||||
'name' => 'ObjectType',
|
||||
'fields' => [
|
||||
'field1' => ['type' => Type::string()],
|
||||
],
|
||||
]) extends ObjectType{
|
||||
};
|
||||
|
||||
$schemaA = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' => [$objectTypeConstructedFromRemoteSchema],
|
||||
]);
|
||||
|
||||
$schemaB = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' => [$localObjectType],
|
||||
]);
|
||||
|
||||
self::assertEmpty(BreakingChangesFinder::findTypesThatChangedKind($schemaA, $schemaB));
|
||||
self::assertEmpty(BreakingChangesFinder::findTypesThatChangedKind($schemaB, $schemaA));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('should detect if a field on a type was deleted or changed type')
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user