-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: entity type customization, type loader support (#33)
* feat: entity type customization, type loader support * feat: lazy union type loading * Update README.md Co-authored-by: Tom Carrio <[email protected]> * fix: type docs updating --------- Co-authored-by: Tom Carrio <[email protected]>
- Loading branch information
Showing
8 changed files
with
291 additions
and
56 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
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Apollo\Federation\Types; | ||
|
||
use GraphQL\Type\Definition\CustomScalarType; | ||
|
||
/** | ||
* Simple representation of an agnostic scalar value. | ||
*/ | ||
class AnyType extends CustomScalarType | ||
{ | ||
public function __construct() | ||
{ | ||
$config = [ | ||
'name' => self::getTypeName(), | ||
'serialize' => function ($value) { | ||
return $value; | ||
} | ||
]; | ||
parent::__construct($config); | ||
} | ||
|
||
public static function getTypeName(): string | ||
{ | ||
return '_Any'; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Apollo\Federation\Types; | ||
|
||
use GraphQL\Type\Definition\UnionType; | ||
|
||
/** | ||
* The union of all entities defined within this schema. | ||
*/ | ||
class EntityUnionType extends UnionType | ||
{ | ||
|
||
/** | ||
* @param array|callable $entityTypes all entity types or a callable to retrieve them | ||
*/ | ||
public function __construct($entityTypes) | ||
{ | ||
$config = [ | ||
'name' => self::getTypeName(), | ||
'types' => is_callable($entityTypes) | ||
? fn () => array_values($entityTypes()) | ||
: array_values($entityTypes) | ||
|
||
]; | ||
parent::__construct($config); | ||
} | ||
|
||
public static function getTypeName(): string | ||
{ | ||
return '_Entity'; | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Apollo\Federation\Types; | ||
|
||
use Apollo\Federation\Utils\FederatedSchemaPrinter; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
use GraphQL\Type\Schema; | ||
|
||
/** | ||
* The type of the service definition required for federated schemas. | ||
*/ | ||
class ServiceDefinitionType extends ObjectType | ||
{ | ||
|
||
/** | ||
* @param Schema $schema - the schemas whose SDL should be printed. | ||
*/ | ||
public function __construct(Schema $schema) | ||
{ | ||
$config = [ | ||
'name' => self::getTypeName(), | ||
'fields' => [ | ||
'sdl' => [ | ||
'type' => Type::string(), | ||
'resolve' => fn () => FederatedSchemaPrinter::doPrint($schema) | ||
] | ||
] | ||
]; | ||
parent::__construct($config); | ||
} | ||
|
||
public static function getTypeName(): string | ||
{ | ||
return '_Service'; | ||
} | ||
} |
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.