mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 14:26:08 +03:00
Invert instance of in BCFinder
This commit is contained in:
parent
20e98aefa4
commit
d97fac6ab0
@ -112,27 +112,31 @@ class BreakingChangesFinder
|
|||||||
* @return string[][]
|
* @return string[][]
|
||||||
*/
|
*/
|
||||||
public static function findTypesThatChangedKind(
|
public static function findTypesThatChangedKind(
|
||||||
Schema $oldSchema,
|
Schema $schemaA,
|
||||||
Schema $newSchema
|
Schema $schemaB
|
||||||
) {
|
) : iterable {
|
||||||
$oldTypeMap = $oldSchema->getTypeMap();
|
$schemaATypeMap = $schemaA->getTypeMap();
|
||||||
$newTypeMap = $newSchema->getTypeMap();
|
$schemaBTypeMap = $schemaB->getTypeMap();
|
||||||
|
|
||||||
$breakingChanges = [];
|
$breakingChanges = [];
|
||||||
foreach ($oldTypeMap as $typeName => $oldType) {
|
foreach ($schemaATypeMap as $typeName => $schemaAType) {
|
||||||
if (! isset($newTypeMap[$typeName])) {
|
if (! isset($schemaBTypeMap[$typeName])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$newType = $newTypeMap[$typeName];
|
$schemaBType = $schemaBTypeMap[$typeName];
|
||||||
if ($oldType instanceof $newType) {
|
if ($schemaAType instanceof $schemaBType) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldTypeKindName = self::typeKindName($oldType);
|
if ($schemaBType instanceof $schemaAType) {
|
||||||
$newTypeKindName = self::typeKindName($newType);
|
continue;
|
||||||
$breakingChanges[] = [
|
}
|
||||||
|
|
||||||
|
$schemaATypeKindName = self::typeKindName($schemaAType);
|
||||||
|
$schemaBTypeKindName = self::typeKindName($schemaBType);
|
||||||
|
$breakingChanges[] = [
|
||||||
'type' => self::BREAKING_CHANGE_TYPE_CHANGED_KIND,
|
'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')
|
* @see it('should detect if a field on a type was deleted or changed type')
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user