Skip to content

Commit 33ff292

Browse files
committed
WIP
Signed-off-by: Tobias Oitzinger <[email protected]>
1 parent 0f02995 commit 33ff292

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Laravel/Eloquent/State/LinksHandler.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Illuminate\Contracts\Foundation\Application;
2222
use Illuminate\Database\Eloquent\Builder;
2323
use Illuminate\Database\Eloquent\Model;
24+
use ApiPlatform\Metadata\GraphQl\Operation;
2425

2526
/**
2627
* @implements LinksHandlerInterface<Model>
@@ -67,7 +68,7 @@ public function handleLinks(Builder $builder, array $uriVariables, array $contex
6768
}
6869
}
6970

70-
if (!$linkedOperation) {
71+
if (!$linkedOperation instanceof Operation) {
7172
return $builder;
7273
}
7374

@@ -86,6 +87,13 @@ public function handleLinks(Builder $builder, array $uriVariables, array $contex
8687
return $this->buildQuery($builder, $newLink, $uriVariables[$newLink->getIdentifiers()[0]]);
8788
}
8889

90+
/**
91+
* @param Builder<Model> $builder
92+
* @param Link $link
93+
* @param mixed $identifier
94+
* @return Builder<Model> $builder
95+
* @throws \Illuminate\Contracts\Container\BindingResolutionException
96+
*/
8997
private function buildQuery(Builder $builder, Link $link, mixed $identifier): Builder
9098
{
9199
if ($to = $link->getToProperty()) {
@@ -94,6 +102,7 @@ private function buildQuery(Builder $builder, Link $link, mixed $identifier): Bu
94102

95103
if ($from = $link->getFromProperty()) {
96104
$relation = $this->application->make($link->getFromClass());
105+
97106
return $builder->getModel()->where($relation->{$from}()->getQualifiedForeignKeyName(), $identifier);
98107
}
99108

src/Metadata/Resource/ResourceMetadataCollection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Metadata\CollectionOperationInterface;
1818
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
1919
use ApiPlatform\Metadata\Operation;
20+
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
2021

2122
/**
2223
* @extends \ArrayObject<int, ApiResource>
@@ -35,7 +36,7 @@ public function __construct(private readonly string $resourceClass, array $input
3536
parent::__construct($input);
3637
}
3738

38-
public function getOperation(?string $operationName = null, bool $forceCollection = false, bool $httpOperation = false, bool $forceGraphQl = false): Operation
39+
public function getOperation(?string $operationName = null, bool $forceCollection = false, bool $httpOperation = false, bool $forceGraphQl = false): Operation|GraphQlOperation
3940
{
4041
$operationName ??= '';
4142
$cachePrefix = ($forceCollection ? self::FORCE_COLLECTION : '').($httpOperation ? self::HTTP_OPERATION : '');

0 commit comments

Comments
 (0)