Skip to content

Commit

Permalink
MNT Compatibility with webonyx/graphql-php v14
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 12, 2022
1 parent fab7143 commit 41427f0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
21 changes: 20 additions & 1 deletion tests/php/GraphQL/Fake/FakeResolveInfo.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php


namespace SilverStripe\Versioned\Tests\GraphQL\Fake;

use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;

// GraphQL dependency is optional in versioned,
// and the follow implementation relies on existence of this class (in GraphQL v4)
Expand All @@ -15,5 +18,21 @@ class FakeResolveInfo extends ResolveInfo
{
public function __construct()
{
// webonyx/graphql-php v0.12
if (!property_exists(__CLASS__, 'fieldDefinition')) {
return;
}
// webonyx/graphql-php v14
parent::__construct(
FieldDefinition::create(['name' => 'fake', 'type' => Type::string()]),
[],
new ObjectType(['name' => 'fake']),
[],
new Schema([]),
[],
'',
null,
[]
);
}
}
3 changes: 2 additions & 1 deletion tests/php/GraphQL/Legacy/Extensions/ReadExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Versioned\GraphQL\Types\VersionedInputType;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Core\Injector\Injector;

// GraphQL dependency is optional in versioned,
Expand Down Expand Up @@ -54,6 +55,6 @@ public function testReadExtensionAppliesFilters()
$read->setUsePagination(false);
$readScaffold = $read->scaffold($manager);
$this->assertIsCallable($readScaffold['resolve']);
$readScaffold['resolve'](null, ['Versioning' => true], ['currentUser' => new Member()], new ResolveInfo([]));
$readScaffold['resolve'](null, ['Versioning' => true], ['currentUser' => new Member()], new FakeResolveInfo());
}
}
3 changes: 2 additions & 1 deletion tests/php/GraphQL/Legacy/Extensions/ReadOneExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Versioned\GraphQL\Types\VersionedInputType;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Versioned\Versioned;

// GraphQL dependency is optional in versioned,
Expand Down Expand Up @@ -60,7 +61,7 @@ public function testReadOneExtensionAppliesFilters()
null,
$args,
['currentUser' => Security::getCurrentUser()],
new ResolveInfo([])
new FakeResolveInfo()
);
};

Expand Down
7 changes: 4 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/CopyToStageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Versioned\GraphQL\Operations\CopyToStage;
use SilverStripe\Versioned\GraphQL\Types\CopyToStageInputType;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Versioned\Versioned;
use InvalidArgumentException;

Expand Down Expand Up @@ -67,7 +68,7 @@ public function testCopyToStage()
],
],
[ 'currentUser' => $member ],
new ResolveInfo([])
new FakeResolveInfo()
);
$recordLive = Versioned::get_by_stage(Fake::class, Versioned::LIVE)
->byID($record->ID);
Expand All @@ -93,7 +94,7 @@ public function testCopyToStage()
],
],
[ 'currentUser' => $member ],
new ResolveInfo([])
new FakeResolveInfo()
);
$recordLive = Versioned::get_by_stage(Fake::class, Versioned::LIVE)
->byID($record->ID);
Expand All @@ -110,7 +111,7 @@ public function testCopyToStage()
],
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
5 changes: 3 additions & 2 deletions tests/php/GraphQL/Legacy/Operations/PublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Versioned\GraphQL\Operations\Publish;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Versioned\Versioned;
use Exception;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => $member ],
new ResolveInfo([])
new FakeResolveInfo()
);
$result = Versioned::get_by_stage(Fake::class, Versioned::LIVE)
->byID($record->ID);
Expand All @@ -80,7 +81,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
7 changes: 4 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/ReadVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Versioned\GraphQL\Types\VersionedStage;
use SilverStripe\Versioned\GraphQL\Types\VersionSortType;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Versioned\Tests\VersionedTest\UnversionedWithField;

// GraphQL dependency is optional in versioned,
Expand Down Expand Up @@ -58,7 +59,7 @@ public function testItThrowsIfAppliedToAnUnversionedObject()
new UnversionedWithField(),
[],
['currentUser' => new Member()],
new ResolveInfo([])
new FakeResolveInfo()
);
}

Expand All @@ -79,7 +80,7 @@ public function testItThrowsIfYouCantReadStages()
new Fake(),
[],
['currentUser' => new Member()],
new ResolveInfo([])
new FakeResolveInfo()
);
}

Expand Down Expand Up @@ -110,7 +111,7 @@ public function testItReadsVersions()
$record,
[],
['currentUser' => $member],
new ResolveInfo([])
new FakeResolveInfo()
);

$this->assertInstanceOf(SS_List::class, $result);
Expand Down
3 changes: 2 additions & 1 deletion tests/php/GraphQL/Legacy/Operations/RollbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Versioned\GraphQL\Operations\Rollback;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeDataObjectStub;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;

// GraphQL dependency is optional in versioned,
// and this legacy implementation relies on existence of this class (in GraphQL v3)
Expand Down Expand Up @@ -85,7 +86,7 @@ protected function doMutation(DataObject $stub, $toVersion = 1, $member = null)
null,
$args,
[ 'currentUser' => $member ?: Security::getCurrentUser() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
5 changes: 3 additions & 2 deletions tests/php/GraphQL/Legacy/Operations/UnpublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Versioned\GraphQL\Operations\Unpublish;
use SilverStripe\Versioned\Tests\GraphQL\Fake\Fake;
use SilverStripe\Versioned\Tests\GraphQL\Fake\FakeResolveInfo;
use SilverStripe\Versioned\Versioned;
use Exception;

Expand Down Expand Up @@ -67,7 +68,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => $member ],
new ResolveInfo([])
new FakeResolveInfo()
);
$result = Versioned::get_by_stage(Fake::class, Versioned::LIVE)
->byID($record->ID);
Expand All @@ -83,7 +84,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}

0 comments on commit 41427f0

Please sign in to comment.