-
Notifications
You must be signed in to change notification settings - Fork 100
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
- Loading branch information
discodingo
committed
Mar 8, 2024
1 parent
11a2600
commit 2f517a1
Showing
10 changed files
with
295 additions
and
26 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,18 @@ | ||
<?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,43 @@ | ||
<?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\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(prefetchMethod="prefetchContacts") | ||
*/ | ||
public function getContact(Company $company, array $contacts): ?Contact | ||
{ | ||
return $contacts[$company->name] ?? null; | ||
} | ||
|
||
public 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,31 @@ | ||
<?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.