-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from moufmouf/fix_prefetch_cache
Fixing prefetch cache
- Loading branch information
Showing
10 changed files
with
154 additions
and
13 deletions.
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Context; | ||
|
||
use SplObjectStorage; | ||
use TheCodingMachine\GraphQLite\PrefetchBuffer; | ||
use TheCodingMachine\GraphQLite\QueryField; | ||
|
||
/** | ||
* A context class that should be passed to the Webonyx executor. | ||
*/ | ||
class Context implements ContextInterface, ResetableContextInterface | ||
{ | ||
/** @var SplObjectStorage */ | ||
private $prefetchBuffers; | ||
|
||
public function __construct() | ||
{ | ||
$this->prefetchBuffers = new SplObjectStorage(); | ||
} | ||
|
||
/** | ||
* Returns the prefetch buffer associated to the field $field. | ||
* (the buffer is created on the fly if it does not exist yet). | ||
*/ | ||
public function getPrefetchBuffer(QueryField $field): PrefetchBuffer | ||
{ | ||
if ($this->prefetchBuffers->offsetExists($this)) { | ||
$prefetchBuffer = $this->prefetchBuffers->offsetGet($this); | ||
} else { | ||
$prefetchBuffer = new PrefetchBuffer(); | ||
$this->prefetchBuffers->offsetSet($this, $prefetchBuffer); | ||
} | ||
|
||
return $prefetchBuffer; | ||
} | ||
|
||
public function reset(): void | ||
{ | ||
$this->prefetchBuffers = new SplObjectStorage(); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Context; | ||
|
||
use TheCodingMachine\GraphQLite\PrefetchBuffer; | ||
use TheCodingMachine\GraphQLite\QueryField; | ||
|
||
/** | ||
* A context class that should be passed to the Webonyx executor. | ||
*/ | ||
interface ContextInterface | ||
{ | ||
/** | ||
* Returns the prefetch buffer associated to the field $field. | ||
* (the buffer is created on the fly if it does not exist yet). | ||
*/ | ||
public function getPrefetchBuffer(QueryField $field): PrefetchBuffer; | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Context; | ||
|
||
/** | ||
* Contexts implementing this interface can be reseted. | ||
*/ | ||
interface ResetableContextInterface | ||
{ | ||
public function reset(): void; | ||
} |
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
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
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