Skip to content

Commit dbd3cee

Browse files
committed
Pass context to AdapterInterface::newQuery()
1 parent cda345d commit dbd3cee

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/Adapter/AdapterInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Tobyz\JsonApiServer\Adapter;
1313

14+
use Tobyz\JsonApiServer\Context;
1415
use Tobyz\JsonApiServer\Schema\Attribute;
1516
use Tobyz\JsonApiServer\Schema\HasMany;
1617
use Tobyz\JsonApiServer\Schema\HasOne;
@@ -27,7 +28,7 @@ interface AdapterInterface
2728
*
2829
* @return mixed
2930
*/
30-
public function newQuery();
31+
public function newQuery(Context $context);
3132

3233
/**
3334
* Manipulate the query to only include resources with the given IDs.

src/Adapter/EloquentAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
1919
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany;
2020
use InvalidArgumentException;
21+
use Tobyz\JsonApiServer\Context;
2122
use Tobyz\JsonApiServer\Schema\Attribute;
2223
use Tobyz\JsonApiServer\Schema\HasMany;
2324
use Tobyz\JsonApiServer\Schema\HasOne;
@@ -49,7 +50,7 @@ public function newModel()
4950
return $this->model->newInstance();
5051
}
5152

52-
public function newQuery()
53+
public function newQuery(Context $context)
5354
{
5455
return $this->model->query();
5556
}

src/Endpoint/Concerns/FindsResources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait FindsResources
2626
private function findResource(ResourceType $resource, string $id, Context $context)
2727
{
2828
$adapter = $resource->getAdapter();
29-
$query = $adapter->newQuery();
29+
$query = $adapter->newQuery($context);
3030

3131
run_callbacks($resource->getSchema()->getListeners('scope'), [$query, $context]);
3232

src/Endpoint/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function handle(Context $context): ResponseInterface
5757
throw new ForbiddenException;
5858
}
5959

60-
$query = $adapter->newQuery();
60+
$query = $adapter->newQuery($context);
6161

6262
run_callbacks($schema->getListeners('listing'), [$query, $context]);
6363
run_callbacks($schema->getListeners('scope'), [$query, $context]);

0 commit comments

Comments
 (0)