Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extensibility for easy integration of Apollo Federation PHP (v2) #1040

Open
wants to merge 34 commits into
base: 0.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e0c084
Ignore IDE configs
a-melnikov Jul 25, 2022
df90ef0
Define default configs by constant instead of static property
a-melnikov Jul 25, 2022
3d62d90
Update phpDoc
a-melnikov Jul 25, 2022
255bf3a
Make parsers configurable
a-melnikov Jul 25, 2022
7379447
Add documentation about parsers configuration
a-melnikov Jul 25, 2022
556e1fb
Allow plugin phpstan/extension-installer
a-melnikov Jul 25, 2022
ea13b32
Make GraphQLParser.php easy overridable.
a-melnikov Jul 25, 2022
c5eb2ca
Make ObjectNode.php config parsing better overridable.
a-melnikov Jul 25, 2022
0377048
Make ObjectTypeDefinition.php overridable
a-melnikov Jul 26, 2022
547f00c
Use base type enum
a-melnikov Jul 26, 2022
51ca461
Configure services autowiring
a-melnikov Jul 26, 2022
624fa15
Make TypeBuilder extendable
a-melnikov Jul 26, 2022
38b706e
Make TypesConfiguration and InheritanceProcessor extendable (dirty qu…
a-melnikov Jul 26, 2022
1a3665e
Split TypeBuilder for more flexibility & extensibility
a-melnikov Jul 27, 2022
9b13b9b
Use single source for all consumers of "GQL services" expression part
a-melnikov Jul 27, 2022
7da17db
Simplify generators services definition
a-melnikov Jul 27, 2022
b531be4
Fix misprint in tests
a-melnikov Jul 28, 2022
5c70a14
Fix parsing of callback of custom scalar type
a-melnikov Jul 28, 2022
e81e44d
Move TypeGeneratorOptions to the Model namespace
a-melnikov Jul 28, 2022
e1dc5a1
Move generator's Collection to the Model namespace
a-melnikov Jul 28, 2022
f00368d
Add stubs instead of moved models for backward compatibility
a-melnikov Jul 28, 2022
28e6902
Add phpDoc
a-melnikov Jul 28, 2022
23e5570
Describe returned data type
a-melnikov Jul 28, 2022
98ea0b9
Simplify extending of fields definition
a-melnikov Jul 29, 2022
a69993b
Extract parsing of interfaces
a-melnikov Aug 1, 2022
beaba14
Fix code style
a-melnikov Aug 4, 2022
0f0a096
Add phpDoc describing data types
a-melnikov Aug 4, 2022
e748140
Make code better extendable
a-melnikov Aug 4, 2022
a6c2a18
Fix tests namespaces
a-melnikov Aug 4, 2022
47fd027
Work around of parsing of "description" field of type extension nodes
a-melnikov Aug 4, 2022
515f86f
Fix PHPStan errors
a-melnikov Aug 5, 2022
cf99c9b
Fix extendability of schema builder
a-melnikov Aug 5, 2022
b19d6de
Change return type from \Closure to callable
a-melnikov Aug 8, 2022
3b25183
Fix using of array_key_exists with \ArrayObject
a-melnikov Aug 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
phpunit.xml
/build
/vendor
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Documentation
- [Errors handling](docs/error-handling/index.md)
- [Events](docs/events/index.md)
- [Profiler](docs/profiler/index.md)
- [Tune configuration](docs/tune_configuration.md)

Talks and slides to help you start
----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(
)
```
`TypeBuilder` here is a new service `Overblog\GraphQLBundle\Generator\TypeBuilder`, which is also used internally.
The rest of the arguments were moved into the separate class `Overblog\GraphQLBundle\Generator\TypeGeneratorOptions`
The rest of the arguments were moved into the separate class `Overblog\GraphQLBundle\Generator\Model\TypeGeneratorOptions`
with the following constructor signature:

```php
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
},
"bin-dir": "bin",
"sort-packages": true
},
Expand Down
22 changes: 22 additions & 0 deletions docs/tune_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Tune configuration
==================

Custom GraphQl configuration parsers
------------------------------------

You can configure custom GraphQl configuration parsers.
Your parsers MUST implement at least `\Overblog\GraphQLBundle\Config\Parser\ParserInterface`
and optionally `\Overblog\GraphQLBundle\Config\Parser\PreParserInterface` when required.

Default values will be applied when omitted.

```yaml
overblog_graphql:
# ...
parsers:
yaml: 'Overblog\GraphQLBundle\Config\Parser\YamlParser'
graphql: 'Overblog\GraphQLBundle\Config\Parser\GraphQLParser'
annotation: 'Overblog\GraphQLBundle\Config\Parser\AnnotationParser'
attribute: 'Overblog\GraphQLBundle\Config\Parser\AttributeParser'
# ...
```
268 changes: 24 additions & 244 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/Config/CustomScalarTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@

class CustomScalarTypeDefinition extends TypeDefinition
{
public const CONFIG_NAME = '_custom_scalar_config';

public static function getName(): string
{
return static::CONFIG_NAME;
}

public function getDefinition(): ArrayNodeDefinition
{
/** @var ArrayNodeDefinition $node */
$node = self::createNode('_custom_scalar_config');
$node = self::createNode(static::CONFIG_NAME);

/** @phpstan-ignore-next-line */
$node
Expand Down
9 changes: 8 additions & 1 deletion src/Config/EnumTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

class EnumTypeDefinition extends TypeDefinition
{
public const CONFIG_NAME = '_enum_config';

public static function getName(): string
{
return static::CONFIG_NAME;
}

public function getDefinition(): ArrayNodeDefinition
{
/** @var ArrayNodeDefinition $node */
$node = self::createNode('_enum_config');
$node = self::createNode(static::CONFIG_NAME);

/** @phpstan-ignore-next-line */
$node
Expand Down
9 changes: 8 additions & 1 deletion src/Config/InputObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@

class InputObjectTypeDefinition extends TypeDefinition
{
public const CONFIG_NAME = '_input_object_config';

public static function getName(): string
{
return static::CONFIG_NAME;
}

public function getDefinition(): ArrayNodeDefinition
{
/** @var ArrayNodeDefinition $node */
$node = self::createNode('_input_object_config');
$node = self::createNode(static::CONFIG_NAME);

/** @phpstan-ignore-next-line */
$node
Expand Down
9 changes: 8 additions & 1 deletion src/Config/InterfaceTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@

class InterfaceTypeDefinition extends TypeWithOutputFieldsDefinition
{
public const CONFIG_NAME = '_interface_config';

public static function getName(): string
{
return static::CONFIG_NAME;
}

public function getDefinition(): ArrayNodeDefinition
{
/** @var ArrayNodeDefinition $node */
$node = self::createNode('_interface_config');
$node = self::createNode(static::CONFIG_NAME);

/** @phpstan-ignore-next-line */
$node
Expand Down
11 changes: 9 additions & 2 deletions src/Config/ObjectTypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@

class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition
{
public const CONFIG_NAME = '_object_config';

public static function getName(): string
{
return static::CONFIG_NAME;
}

public function getDefinition(): ArrayNodeDefinition
{
$builder = new TreeBuilder('_object_config', 'array');
$builder = new TreeBuilder(static::CONFIG_NAME, 'array');

/** @var ArrayNodeDefinition $node */
$node = $builder->getRootNode();

/** @phpstan-ignore-next-line */
$node
->children()
->append($this->validationSection(self::VALIDATION_LEVEL_CLASS))
->append($this->validationSection(static::VALIDATION_LEVEL_CLASS))
->append($this->nameSection())
->append($this->outputFieldsSection())
->append($this->fieldsBuilderSection())
Expand Down
3 changes: 2 additions & 1 deletion src/Config/Parser/GraphQL/ASTConverter/CustomScalarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use GraphQL\Language\AST\Node;
use Overblog\GraphQLBundle\Enum\TypeEnum;
use RuntimeException;

class CustomScalarNode implements NodeInterface
Expand All @@ -19,7 +20,7 @@ public static function toConfig(Node $node): array
];

return [
'type' => 'custom-scalar',
'type' => TypeEnum::CUSTOM_SCALAR,
'config' => $config,
];
}
Expand Down
9 changes: 6 additions & 3 deletions src/Config/Parser/GraphQL/ASTConverter/DescriptionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@

use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\StringValueNode;
use GraphQL\Language\AST\TypeExtensionNode;
use function trim;

class DescriptionNode implements NodeInterface
{
public static function toConfig(Node $node): array
{
if ($node instanceof TypeExtensionNode) {
return [];
}

return ['description' => self::cleanAstDescription($node->description)];
}

Expand All @@ -21,8 +26,6 @@ private static function cleanAstDescription(?StringValueNode $description): ?str
return null;
}

$description = trim($description->value);

return empty($description) ? null : $description;
return trim($description->value) ?: null;
}
}
3 changes: 2 additions & 1 deletion src/Config/Parser/GraphQL/ASTConverter/EnumNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use GraphQL\Language\AST\Node;
use Overblog\GraphQLBundle\Enum\TypeEnum;

class EnumNode implements NodeInterface
{
Expand All @@ -28,7 +29,7 @@ public static function toConfig(Node $node): array
$config['values'] = $values;

return [
'type' => 'enum',
'type' => TypeEnum::ENUM,
'config' => $config,
];
}
Expand Down
17 changes: 15 additions & 2 deletions src/Config/Parser/GraphQL/ASTConverter/FieldsNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InputValueDefinitionNode;
use GraphQL\Language\AST\Node;
use GraphQL\Utils\AST;

Expand All @@ -17,7 +19,7 @@ public static function toConfig(Node $node, string $property = 'fields'): array
$fieldConfig = TypeNode::toConfig($definition) + DescriptionNode::toConfig($definition);

if (!empty($definition->arguments)) {
$fieldConfig['args'] = self::toConfig($definition, 'arguments');
$fieldConfig['args'] = static::toConfig($definition, 'arguments');
}

if (!empty($definition->defaultValue)) {
Expand All @@ -29,10 +31,21 @@ public static function toConfig(Node $node, string $property = 'fields'): array
$fieldConfig['deprecationReason'] = $directiveConfig['deprecationReason'];
}

$config[$definition->name->value] = $fieldConfig;
$config[$definition->name->value] = static::extendFieldConfig($fieldConfig, $definition);
}
}

return $config;
}

/**
* @param array<string,mixed> $fieldConfig
* @param FieldDefinitionNode|InputValueDefinitionNode $fieldDefinition
*
* @return array<string,mixed>
*/
protected static function extendFieldConfig(array $fieldConfig, Node $fieldDefinition): array
{
return $fieldConfig;
}
}
4 changes: 3 additions & 1 deletion src/Config/Parser/GraphQL/ASTConverter/InputObjectNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use Overblog\GraphQLBundle\Enum\TypeEnum;

class InputObjectNode extends ObjectNode
{
protected const TYPENAME = 'input-object';
protected const TYPENAME = TypeEnum::INPUT_OBJECT;
}
4 changes: 3 additions & 1 deletion src/Config/Parser/GraphQL/ASTConverter/InterfaceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use Overblog\GraphQLBundle\Enum\TypeEnum;

class InterfaceNode extends ObjectNode
{
protected const TYPENAME = 'interface';
protected const TYPENAME = TypeEnum::INTERFACE;
}
3 changes: 3 additions & 0 deletions src/Config/Parser/GraphQL/ASTConverter/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

interface NodeInterface
{
/**
* @return array<string,mixed>
*/
public static function toConfig(Node $node): array;
}
49 changes: 42 additions & 7 deletions src/Config/Parser/GraphQL/ASTConverter/ObjectNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,63 @@
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use Overblog\GraphQLBundle\Enum\TypeEnum;

class ObjectNode implements NodeInterface
{
protected const TYPENAME = 'object';
protected const TYPENAME = TypeEnum::OBJECT;

/**
* @param ObjectTypeDefinitionNode $node
*
* @return array<string,mixed>
*/
public static function toConfig(Node $node): array
{
$config = DescriptionNode::toConfig($node) + [
return [
'type' => static::TYPENAME,
'config' => static::parseConfig($node),
];
}

/**
* @param ObjectTypeDefinitionNode $node
*
* @return array<string,mixed>
*/
protected static function parseConfig(Node $node): array
{
$config = DescriptionNode::toConfig($node) + static::parseFields($node);
$config += static::parseInterfaces($node);

return $config;
}

/**
* @return array{fields: array<string,mixed> }
*/
protected static function parseFields(Node $node): array
{
return [
'fields' => FieldsNode::toConfig($node),
];
}

if (!empty($node->interfaces)) {
/**
* @return array<string,array<string>>
*/
protected static function parseInterfaces(Node $node): array
{
$config = [];
if (isset($node->interfaces) && !empty($node->interfaces)) {
$interfaces = [];
foreach ($node->interfaces as $interface) {
$interfaces[] = TypeNode::astTypeNodeToString($interface);
}
$config['interfaces'] = $interfaces;
}

return [
'type' => static::TYPENAME,
'config' => $config,
];
return $config;
}
}
3 changes: 2 additions & 1 deletion src/Config/Parser/GraphQL/ASTConverter/UnionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter;

use GraphQL\Language\AST\Node;
use Overblog\GraphQLBundle\Enum\TypeEnum;

class UnionNode implements NodeInterface
{
Expand All @@ -21,7 +22,7 @@ public static function toConfig(Node $node): array
}

return [
'type' => 'union',
'type' => TypeEnum::UNION,
'config' => $config,
];
}
Expand Down
Loading