-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix prefetching the same GQL type for batch request (#658)
* Fix prefetching the same GQL type for batch request * Fix phpstan errors * Fix after pull master and resolving conflicts * Fix cs * Fix phpstan * Bring back ResolveInfo|null instead of ?ResolveInfo * fix cs
- Loading branch information
Showing
10 changed files
with
290 additions
and
25 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
17 changes: 17 additions & 0 deletions
17
tests/Fixtures/Integration/Controllers/CompanyController.php
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Controllers; | ||
|
||
use TheCodingMachine\GraphQLite\Annotations\Query; | ||
use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Company; | ||
|
||
class CompanyController | ||
{ | ||
#[Query] | ||
public function getCompany(string $id): Company | ||
{ | ||
return new Company('Company'); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Models; | ||
|
||
use TheCodingMachine\GraphQLite\Annotations\Type; | ||
|
||
#[Type] | ||
class Company | ||
{ | ||
public function __construct( | ||
public readonly string $name | ||
) { | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Types; | ||
|
||
use TheCodingMachine\GraphQLite\Annotations\ExtendType; | ||
use TheCodingMachine\GraphQLite\Annotations\Field; | ||
use TheCodingMachine\GraphQLite\Annotations\Prefetch; | ||
use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Company; | ||
use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Contact; | ||
|
||
#[ExtendType(class:Company::class)] | ||
class CompanyType | ||
{ | ||
|
||
#[Field] | ||
public function getName(Company $company): string | ||
{ | ||
return $company->name; | ||
} | ||
|
||
#[Field] | ||
public function getContact( | ||
Company $company, | ||
#[Prefetch('prefetchContacts')] | ||
array $contacts | ||
): ?Contact { | ||
return $contacts[$company->name] ?? null; | ||
} | ||
|
||
public static function prefetchContacts(array $companies): array | ||
{ | ||
$contacts = []; | ||
|
||
foreach ($companies as $company) { | ||
$contacts[$company->name] = new Contact('Kate'); | ||
} | ||
|
||
return $contacts; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Types; | ||
|
||
use TheCodingMachine\GraphQLite\Annotations\ExtendType; | ||
use TheCodingMachine\GraphQLite\Annotations\Field; | ||
use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Post; | ||
|
||
#[ExtendType(class:Post::class)] | ||
class PostType | ||
{ | ||
#[Field] | ||
public function getId(Post $post): int | ||
{ | ||
return (int) $post->id; | ||
} | ||
|
||
#[Field] | ||
public function getTitle(Post $post): string | ||
{ | ||
return $post->title; | ||
} | ||
} |
Oops, something went wrong.