mirror of
https://github.com/retailcrm/graphql-php.git
synced 2025-02-06 07:49:24 +03:00
testDetectsAllBreakingChanges
This commit is contained in:
parent
dbccf9b196
commit
3c0ed787ba
@ -17,6 +17,8 @@ use GraphQL\Utils\FindBreakingChanges;
|
||||
class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $queryType;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->queryType = new ObjectType([
|
||||
@ -1017,4 +1019,213 @@ class FindBreakingChangesTest extends \PHPUnit_Framework_TestCase
|
||||
],
|
||||
FindBreakingChanges::findInterfacesRemovedFromObjectTypes($oldSchema, $newSchema)[0]);
|
||||
}
|
||||
|
||||
public function testDetectsAllBreakingChanges()
|
||||
{
|
||||
$typeThatGetsRemoved = new ObjectType([
|
||||
'name' => 'TypeThatGetsRemoved',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$argThatChanges = new ObjectType([
|
||||
'name' => 'ArgThatChanges',
|
||||
'fields' => [
|
||||
'field1' => [
|
||||
'type' => Type::string(),
|
||||
'args' => [
|
||||
'id' => Type::int()
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$argChanged = new ObjectType([
|
||||
'name' => 'ArgThatChanges',
|
||||
'fields' => [
|
||||
'field1' => [
|
||||
'type' => Type::string(),
|
||||
'args' => [
|
||||
'id' => Type::string()
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$typeThatChangesTypeOld = new ObjectType([
|
||||
'name' => 'TypeThatChangesType',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeThatChangesTypeNew = new InterfaceType([
|
||||
'name' => 'TypeThatChangesType',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeThatHasBreakingFieldChangesOld = new InterfaceType([
|
||||
'name' => 'TypeThatHasBreakingFieldChanges',
|
||||
'fields' => [
|
||||
'field1' => Type::string(),
|
||||
'field2' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeThatHasBreakingFieldChangesNew = new InterfaceType([
|
||||
'name' => 'TypeThatHasBreakingFieldChanges',
|
||||
'fields' => [
|
||||
'field2' => Type::boolean()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeInUnion1 = new ObjectType([
|
||||
'name' => 'TypeInUnion1',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeInUnion2 = new ObjectType([
|
||||
'name' => 'TypeInUnion2',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$unionTypeThatLosesATypeOld = new UnionType([
|
||||
'name' => 'UnionTypeThatLosesAType',
|
||||
'types' => [$typeInUnion1, $typeInUnion2],
|
||||
'resolveType' => function () {
|
||||
}
|
||||
]);
|
||||
|
||||
$unionTypeThatLosesATypeNew = new UnionType([
|
||||
'name' => 'UnionTypeThatLosesAType',
|
||||
'types' => [$typeInUnion1],
|
||||
'resolveType' => function () {
|
||||
}
|
||||
]);
|
||||
|
||||
$enumTypeThatLosesAValueOld = new EnumType([
|
||||
'name' => 'EnumTypeThatLosesAValue',
|
||||
'values' => [
|
||||
'VALUE0' => 0,
|
||||
'VALUE1' => 1,
|
||||
'VALUE2' => 2
|
||||
]
|
||||
]);
|
||||
|
||||
$enumTypeThatLosesAValueNew = new EnumType([
|
||||
'name' => 'EnumTypeThatLosesAValue',
|
||||
'values' => [
|
||||
'VALUE1' => 1,
|
||||
'VALUE2' => 2
|
||||
]
|
||||
]);
|
||||
|
||||
$interface1 = new InterfaceType([
|
||||
'name' => 'Interface1',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
],
|
||||
'resolveType' => function () {
|
||||
}
|
||||
]);
|
||||
|
||||
$typeThatLosesInterfaceOld = new ObjectType([
|
||||
'name' => 'TypeThatLosesInterface1',
|
||||
'interfaces' => [$interface1],
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$typeThatLosesInterfaceNew = new ObjectType([
|
||||
'name' => 'TypeThatLosesInterface1',
|
||||
'fields' => [
|
||||
'field1' => Type::string()
|
||||
]
|
||||
]);
|
||||
|
||||
$oldSchema = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' =>
|
||||
[
|
||||
'TypeThatGetsRemoved' => $typeThatGetsRemoved,
|
||||
'TypeThatChangesType' => $typeThatChangesTypeOld,
|
||||
'TypeThatHasBreakingFieldChanges' => $typeThatHasBreakingFieldChangesOld,
|
||||
'UnionTypeThatLosesAType' => $unionTypeThatLosesATypeOld,
|
||||
'EnumTypeThatLosesAValue' => $enumTypeThatLosesAValueOld,
|
||||
'ArgThatChanges' => $argThatChanges,
|
||||
'TypeThatLosesInterface' => $typeThatLosesInterfaceOld
|
||||
]
|
||||
]);
|
||||
|
||||
$newSchema = new Schema([
|
||||
'query' => $this->queryType,
|
||||
'types' =>
|
||||
[
|
||||
'TypeThatChangesType' => $typeThatChangesTypeNew,
|
||||
'TypeThatHasBreakingFieldChanges' => $typeThatHasBreakingFieldChangesNew,
|
||||
'UnionTypeThatLosesAType' => $unionTypeThatLosesATypeNew,
|
||||
'EnumTypeThatLosesAValue' => $enumTypeThatLosesAValueNew,
|
||||
'ArgThatChanges' => $argChanged,
|
||||
'TypeThatLosesInterface' => $typeThatLosesInterfaceNew,
|
||||
'Interface1' => $interface1
|
||||
]
|
||||
]);
|
||||
|
||||
$expectedBreakingChanges = [
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_REMOVED,
|
||||
'description' => 'TypeThatGetsRemoved was removed.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_REMOVED,
|
||||
'description' => 'TypeInUnion2 was removed.',
|
||||
],
|
||||
/*
|
||||
// NB the below assertion is included in the graphql-js tests, but it makes no sense.
|
||||
// Seriously, look for what `int` type was supposed to be removed between the two schemas. There is none.
|
||||
// I honestly think it's a bug in the js implementation and was put into the test just to make it pass.
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_REMOVED,
|
||||
'description' => 'Int was removed.'
|
||||
],*/
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_CHANGED,
|
||||
'description' => 'TypeThatChangesType changed from an Object type to an Interface type.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_FIELD_REMOVED,
|
||||
'description' => 'TypeThatHasBreakingFieldChanges->field1 was removed.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_FIELD_CHANGED,
|
||||
'description' => 'TypeThatHasBreakingFieldChanges->field2 changed type from String to Boolean.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_TYPE_REMOVED_FROM_UNION,
|
||||
'description' => 'TypeInUnion2 was removed from union type UnionTypeThatLosesAType.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_VALUE_REMOVED_FROM_ENUM,
|
||||
'description' => 'VALUE0 was removed from enum type EnumTypeThatLosesAValue.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_ARG_CHANGED,
|
||||
'description' => 'ArgThatChanges->field1 arg id has changed type from Int to String.',
|
||||
],
|
||||
[
|
||||
'type' => FindBreakingChanges::BREAKING_CHANGE_INTERFACE_REMOVED_FROM_OBJECT,
|
||||
'description' => 'TypeThatLosesInterface1 no longer implements interface Interface1.',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedBreakingChanges, FindBreakingChanges::findBreakingChanges($oldSchema, $newSchema));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user