-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: GraphQLContext with access to current HTTP Request
Adds a custom `GraphQLContext` that is available in all resolvers and allows access to the current HTTP Request. Example:: 'resolve' => function ($value, array $args, GraphQLContext $context) { $baseUri = $context->getHttpRequest()->getBaseUri(); },
- Loading branch information
1 parent
b4d3b5a
commit 5dbbcfc
Showing
4 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
namespace Wwwision\GraphQL; | ||
|
||
use Neos\Flow\Http\Request as HttpRequest; | ||
|
||
/** | ||
* A custom context that will be accessible to all resolvers | ||
*/ | ||
final class GraphQLContext | ||
{ | ||
/** | ||
* @var HttpRequest | ||
*/ | ||
private $httpRequest; | ||
|
||
/** | ||
* @param HttpRequest $httpRequest | ||
*/ | ||
public function __construct(HttpRequest $httpRequest) | ||
{ | ||
$this->httpRequest = $httpRequest; | ||
} | ||
|
||
/** | ||
* @return HttpRequest | ||
*/ | ||
public function getHttpRequest() | ||
{ | ||
return $this->httpRequest; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace Wwwision\GraphQL\Tests\Unit; | ||
|
||
use Neos\Flow\Http\Request; | ||
use Neos\Flow\Tests\UnitTestCase; | ||
use Wwwision\GraphQL\GraphQLContext; | ||
|
||
class GraphQLContextTest extends UnitTestCase | ||
{ | ||
|
||
/** | ||
* @var GraphQLContext | ||
*/ | ||
private $graphQLContext; | ||
|
||
/** | ||
* @var Request|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $mockHttpRequest; | ||
|
||
public function setUp() | ||
{ | ||
$this->mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); | ||
$this->graphQLContext = new GraphQLContext($this->mockHttpRequest); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getHttpRequestReturnsTheSpecifiedRequestInstance() | ||
{ | ||
$this->assertSame($this->mockHttpRequest, $this->graphQLContext->getHttpRequest()); | ||
} | ||
} |