-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update apollo-federation-php with latest schema changes (#346)
- Loading branch information
1 parent
452d03f
commit 98c28f9
Showing
16 changed files
with
395 additions
and
34 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Data; | ||
|
||
use GraphQL\Utils\Utils; | ||
|
||
class CaseStudy | ||
{ | ||
public string $caseNumber; | ||
|
||
public string $description; | ||
|
||
public function __construct(array $data) | ||
{ | ||
Utils::assign($this, $data); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,12 +7,37 @@ | |
use function array_filter; | ||
use function array_values; | ||
|
||
class DataSource | ||
class DataSource | ||
{ | ||
private static array $users = []; | ||
private static array $productResearch = []; | ||
private static array $products = []; | ||
private static array $deprecatedProducts = []; | ||
|
||
public static function init(): void | ||
{ | ||
self::$users = [ | ||
new User([ | ||
'email' => '[email protected]', | ||
'name' => 'Jane Smith', | ||
]), | ||
]; | ||
|
||
self::$productResearch = [ | ||
new ProductResearch([ | ||
'study' => new CaseStudy([ | ||
'caseNumber' => '1234', | ||
'description' => 'Federation Study', | ||
]), | ||
]), | ||
new ProductResearch([ | ||
'study' => new CaseStudy([ | ||
'caseNumber' => '1235', | ||
'description' => 'Studio Study', | ||
]), | ||
]), | ||
]; | ||
|
||
self::$products = [ | ||
new Product([ | ||
'id' => 'apollo-federation', | ||
|
@@ -27,6 +52,14 @@ public static function init(): void | |
'variation' => 'platform', | ||
]), | ||
]; | ||
|
||
self::$deprecatedProducts = [ | ||
new DeprecatedProduct([ | ||
'sku' => 'apollo-federation-v1', | ||
'package' => '@apollo/federation-v1', | ||
'reason' => 'Migrate to Federation V2', | ||
]), | ||
]; | ||
} | ||
|
||
public static function findProduct(string $id) { | ||
|
@@ -55,4 +88,38 @@ public static function findProductBySkuAndVariation(string $sku, string $variati | |
|
||
return array_values($productsFound)[0] ?? null; | ||
} | ||
} | ||
|
||
public static function findDeprecatedProductBySkuAndPackage(string $sku, string $package) { | ||
$deprecatedProductsFound = array_filter( | ||
self::$deprecatedProducts, | ||
static fn (DeprecatedProduct $product): bool => $product->sku === $sku && $product->package === $package | ||
); | ||
|
||
return array_values($deprecatedProductsFound)[0] ?? null; | ||
} | ||
|
||
public static function findProductResearch(string $caseNumber) { | ||
$researchFound = array_filter( | ||
self::$productResearch, | ||
static fn (ProductResearch $research): bool => $research->study->caseNumber === $caseNumber | ||
); | ||
return array_values($researchFound)[0] ?? null; | ||
} | ||
|
||
public static function findResearchForProduct(string $productId) { | ||
$researchFound = array_filter( | ||
self::$productResearch, | ||
static fn (ProductResearch $research): bool => ($research->study->caseNumber === '1234' && $productId === 'apollo-federation') || ($research->study->caseNumber === '1235' && $productId === 'apollo-studio') | ||
); | ||
return array_values($researchFound) ?? []; | ||
} | ||
|
||
public static function findUser(string $email) { | ||
$usersFound = array_filter( | ||
self::$users, | ||
static fn (User $user): bool => $user->email === $email | ||
); | ||
|
||
return array_values($usersFound)[0] ?? null; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Data; | ||
|
||
use GraphQL\Utils\Utils; | ||
|
||
class DeprecatedProduct | ||
{ | ||
public string $sku; | ||
|
||
public string $package; | ||
|
||
public string $reason; | ||
|
||
public function __construct(array $data) | ||
{ | ||
Utils::assign($this, $data); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Data; | ||
|
||
use GraphQL\Utils\Utils; | ||
|
||
class ProductResearch | ||
{ | ||
public CaseStudy $study; | ||
|
||
public string $outcome; | ||
|
||
public function __construct(array $data) | ||
{ | ||
Utils::assign($this, $data); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Data; | ||
|
||
use GraphQL\Utils\Utils; | ||
|
||
class User | ||
{ | ||
public string $email; | ||
|
||
public string $name; | ||
|
||
public int $totalProductsCreated; | ||
|
||
public int $yearsOfEmployment; | ||
|
||
public function __construct(array $data) | ||
{ | ||
Utils::assign($this, $data); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Type; | ||
|
||
use GraphQL\Compatibility\Types; | ||
use GraphQL\Type\Definition\ObjectType; | ||
|
||
class CaseStudyType extends ObjectType { | ||
public function __construct() | ||
{ | ||
parent::__construct([ | ||
'name' => 'CaseStudy', | ||
'fields' => [ | ||
'caseNumber' => [ 'type' => Types::nonNull(Types::id()) ], | ||
'description' => [ 'type' => Types::string() ] | ||
] | ||
]); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GraphQL\Compatibility\Type; | ||
|
||
use GraphQL\Compatibility\Types; | ||
use GraphQL\Compatibility\Data\DeprecatedProduct; | ||
use GraphQL\Compatibility\Data\DataSource; | ||
|
||
use Apollo\Federation\Types\EntityObjectType; | ||
|
||
class DeprecatedProductType extends EntityObjectType { | ||
public function __construct() | ||
{ | ||
parent::__construct([ | ||
'name' => 'DeprecatedProduct', | ||
'keyFields' => ['sku package'], | ||
'fields' => [ | ||
'sku' => [ 'type' => Types::nonNull(Types::string()) ], | ||
'package' => [ 'type' => Types::nonNull(Types::string()) ], | ||
'reason' => [ 'type' => Types::string() ], | ||
'createdBy' => [ | ||
'type' => Types::user(), | ||
'provides' => 'totalProductsCreated', | ||
'resolve' => static fn (): array => [ | ||
'email' => '[email protected]', | ||
'totalProductsCreated' => 1337, | ||
] | ||
], | ||
], | ||
'__resolveReference' => function ($ref) { | ||
$sku = $ref['sku']; | ||
$package = $ref['package']; | ||
|
||
if ($sku !== null && $package !== null) { | ||
return DataSource::findDeprecatedProductBySkuAndPackage($sku, $package); | ||
} | ||
}, | ||
'isTypeOf' => function ($value) { | ||
if ($value instanceof DeprecatedProduct) { | ||
return true; | ||
} | ||
}, | ||
]); | ||
} | ||
|
||
static function getVariation(string $variation): array { | ||
return [ 'id' => $variation ]; | ||
} | ||
} |
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
Oops, something went wrong.