Skip to content

Commit

Permalink
Merge pull request #359 from creative-commoners/pulls/1/webonyx
Browse files Browse the repository at this point in the history
MNT Compatibility with webonyx/graphql-php v14
  • Loading branch information
GuySartorelli authored Apr 13, 2022
2 parents fab7143 + 8d07dd2 commit 86ab749
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 21 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,
[]
);
}
}
4 changes: 2 additions & 2 deletions tests/php/GraphQL/Legacy/Extensions/ReadExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Extensions;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Resolvers\ApplyVersionFilters;
Expand All @@ -13,6 +12,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 +54,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());
}
}
4 changes: 2 additions & 2 deletions tests/php/GraphQL/Legacy/Extensions/ReadOneExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Extensions;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
Expand All @@ -13,6 +12,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 +60,7 @@ public function testReadOneExtensionAppliesFilters()
null,
$args,
['currentUser' => Security::getCurrentUser()],
new ResolveInfo([])
new FakeResolveInfo()
);
};

Expand Down
8 changes: 4 additions & 4 deletions tests/php/GraphQL/Legacy/Operations/CopyToStageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Operations;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
Expand All @@ -13,6 +12,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 +67,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 +93,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 +110,7 @@ public function testCopyToStage()
],
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/PublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Operations;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
Expand All @@ -12,6 +11,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 +63,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 +80,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
8 changes: 4 additions & 4 deletions tests/php/GraphQL/Legacy/Operations/ReadVersionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Schema\Schema;
Expand All @@ -15,6 +14,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 +58,7 @@ public function testItThrowsIfAppliedToAnUnversionedObject()
new UnversionedWithField(),
[],
['currentUser' => new Member()],
new ResolveInfo([])
new FakeResolveInfo()
);
}

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

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

$this->assertInstanceOf(SS_List::class, $result);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/GraphQL/Legacy/Operations/RollbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Operations;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use InvalidArgumentException;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
Expand All @@ -13,6 +12,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 +85,7 @@ protected function doMutation(DataObject $stub, $toVersion = 1, $member = null)
null,
$args,
[ 'currentUser' => $member ?: Security::getCurrentUser() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}
6 changes: 3 additions & 3 deletions tests/php/GraphQL/Legacy/Operations/UnpublishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\Versioned\Tests\GraphQL\Legacy\Operations;

use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\ResolveInfo;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\GraphQL\Manager;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
Expand All @@ -12,6 +11,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 +67,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 +83,7 @@ public function testPublish()
'ID' => $record->ID
],
[ 'currentUser' => new Member() ],
new ResolveInfo([])
new FakeResolveInfo()
);
}
}

0 comments on commit 86ab749

Please sign in to comment.