Skip to content

Commit

Permalink
upgrade main lib
Browse files Browse the repository at this point in the history
  • Loading branch information
bpteam committed Mar 19, 2023
1 parent 80c3bff commit 8726fc3
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 126 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.0.0

- Upgrade base lib

1.0.5

- Upgrade base lib with bug fixing
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
},
"require": {
"php": "^7.4 | ^8.0",
"axtiva/flexible-graphql-php": "^1.1",
"axtiva/flexible-graphql-federation": "^1.0",
"axtiva/graphql-federation-extension": "^1.0.1",
"axtiva/flexible-graphql-php": "^2.0",
"symfony/config": "^4.4 | ^5.0 | ^6.0",
"symfony/dependency-injection": "^4.4 | ^5.0 | ^6.0",
"symfony/framework-bundle": "^4.4 | ^5.0 | ^6.0",
Expand Down
6 changes: 4 additions & 2 deletions src/CacheWarmer/SchemaCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Axtiva\FlexibleGraphqlBundle\CacheWarmer;

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\FederationExtension\FederationSchemaExtender;
use Axtiva\FlexibleGraphql\Utils\FederationV22SchemaExtender;
use Axtiva\FlexibleGraphql\Utils\SchemaBuilder;
use Axtiva\FlexibleGraphql\Builder\TypeRegistryGeneratorBuilderInterface;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
Expand Down Expand Up @@ -39,7 +39,9 @@ public function warmUp(string $cacheDir): array
$classes = [];
$schema = SchemaBuilder::build($this->schemaFiles);
if ($this->schemaType === 'federation') {
$schema = FederationSchemaExtender::build($schema);
foreach (SchemaBuilder::getSchemaAst($this->schemaFiles) as $ast) {
$schema = FederationV22SchemaExtender::build($schema, $ast);
}
}
$codeGenerator = $this->codeGeneratorBuilder->build();
foreach ($codeGenerator->generateAllTypes($schema) as $code){
Expand Down
5 changes: 0 additions & 5 deletions src/Command/GenerateDirectiveResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Axtiva\FlexibleGraphqlBundle\Command;

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\FederationExtension\FederationSchemaExtender;
use Axtiva\FlexibleGraphql\Utils\SchemaBuilder;
use GraphQL\Type\Definition\Directive;
use Symfony\Component\Console\Command\Command;
Expand All @@ -18,7 +17,6 @@ class GenerateDirectiveResolverCommand extends Command
{
protected static $defaultName = 'flexible_graphql:generate-directive-resolver';
private string $schemaFiles;
private string $schemaType;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;

public function __construct(
Expand All @@ -45,9 +43,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$io->title('Read schema SDL from ' . $this->schemaFiles);
$schema = SchemaBuilder::build($this->schemaFiles);
if ($this->schemaType === 'federation') {
$schema = FederationSchemaExtender::build($schema);
}
$codeGenerator = $this->codeGeneratorBuilder->build();
/** @var Directive $directive */
$directiveName = $input->getArgument('directive_name');
Expand Down
5 changes: 0 additions & 5 deletions src/Command/GenerateFieldResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Axtiva\FlexibleGraphqlBundle\Command;

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\FederationExtension\FederationSchemaExtender;
use Axtiva\FlexibleGraphql\Utils\SchemaBuilder;
use GraphQL\Type\Definition\ObjectType;
use Symfony\Component\Console\Command\Command;
Expand All @@ -18,7 +17,6 @@ class GenerateFieldResolverCommand extends Command
{
protected static $defaultName = 'flexible_graphql:generate-field-resolver';
private string $schemaFiles;
private string $schemaType;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;

public function __construct(
Expand Down Expand Up @@ -46,9 +44,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$io->title('Read schema SDL from ' . $this->schemaFiles);
$schema = SchemaBuilder::build($this->schemaFiles);
if ($this->schemaType === 'federation') {
$schema = FederationSchemaExtender::build($schema);
}
$codeGenerator = $this->codeGeneratorBuilder->build();
$typeName = $input->getArgument('type_name');
$fieldName = $input->getArgument('field_name');
Expand Down
4 changes: 0 additions & 4 deletions src/Command/GenerateScalarResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Axtiva\FlexibleGraphqlBundle\Command;

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\FederationExtension\FederationSchemaExtender;
use Axtiva\FlexibleGraphql\Utils\SchemaBuilder;
use GraphQL\Type\Definition\CustomScalarType;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -45,9 +44,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$io->title('Read schema SDL from ' . $this->schemaFiles);
$schema = SchemaBuilder::build($this->schemaFiles);
if ($this->schemaType === 'federation') {
$schema = FederationSchemaExtender::build($schema);
}
$codeGenerator = $this->codeGeneratorBuilder->build();
/** @var CustomScalarType $scalar */
$scalarName = $input->getArgument('custom_scalar_name');
Expand Down
4 changes: 0 additions & 4 deletions src/Command/GenerateTypeRegistryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Axtiva\FlexibleGraphqlBundle\Command;

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\FederationExtension\FederationSchemaExtender;
use Axtiva\FlexibleGraphql\Utils\SchemaBuilder;
use Axtiva\FlexibleGraphql\Builder\TypeRegistryGeneratorBuilderInterface;
use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -46,9 +45,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io = new SymfonyStyle($input, $output);
$io->title('Read schema SDL from ' . $this->schemaFiles);
$schema = SchemaBuilder::build($this->schemaFiles);
if ($this->schemaType === 'federation') {
$schema = FederationSchemaExtender::build($schema);
}
$codeGenerator = $this->codeGeneratorBuilder->build();
foreach ($codeGenerator->generateAllTypes($schema) as $code) {
$io->writeln($code->getFilename());
Expand Down
81 changes: 29 additions & 52 deletions src/DependencyInjection/FlexibleGraphqlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,19 @@

use Axtiva\FlexibleGraphql\Builder\CodeGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\Builder\Foundation\CodeGeneratorBuilder;
use Axtiva\FlexibleGraphql\Federation\Generator\Config\FederationRepresentationResolverGeneratorConfigInterface;
use Axtiva\FlexibleGraphql\Federation\Generator\Config\Foundation\Psr4\FederationRepresentationResolverGeneratorConfig;
use Axtiva\FlexibleGraphql\Federation\Generator\Model\FederationRepresentationResolverGeneratorInterface;
use Axtiva\FlexibleGraphql\Federation\Generator\Model\Foundation\Psr4\_EntitiesResolverGenerator;
use Axtiva\FlexibleGraphql\Federation\Generator\Model\Foundation\Psr4\_ServiceResolverGenerator;
use Axtiva\FlexibleGraphql\Federation\Generator\Model\Foundation\Psr4\FederationRepresentationResolverGenerator;
use Axtiva\FlexibleGraphql\Federation\Resolver\_EntitiesResolverInterface;
use Axtiva\FlexibleGraphql\Federation\Resolver\_ServiceResolverInterface;
use Axtiva\FlexibleGraphql\Builder\Foundation\CodeGeneratorBuilderFederated;
use Axtiva\FlexibleGraphql\Builder\Foundation\Psr\Container\TypeRegistryGeneratorBuilder;
use Axtiva\FlexibleGraphql\Builder\Foundation\Psr\Container\TypeRegistryGeneratorBuilderFederated;
use Axtiva\FlexibleGraphql\Builder\TypeRegistryGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\Federation\Resolver\Foundation\Query\_EntitiesResolver;
use Axtiva\FlexibleGraphql\Federation\Resolver\Foundation\Query\_ServiceResolver;
use Axtiva\FlexibleGraphql\Generator\Config\CodeGeneratorConfigInterface;
use Axtiva\FlexibleGraphql\Generator\Config\FieldResolverGeneratorConfigInterface;
use Axtiva\FlexibleGraphql\Generator\Config\Foundation\Psr4\CodeGeneratorConfig;
use Axtiva\FlexibleGraphql\Generator\Config\Foundation\Psr4\FieldResolverGeneratorConfig;
use Axtiva\FlexibleGraphql\Resolver\_EntitiesResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\_ServiceResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\CustomScalarResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\DirectiveResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\FederationRepresentationResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\ResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\UnionResolveTypeInterface;
use Axtiva\FlexibleGraphql\Federation\Resolver\FederationRepresentationResolverInterface;
use Axtiva\FlexibleGraphqlBundle\CacheWarmer\SchemaCacheWarmer;
use Axtiva\FlexibleGraphqlBundle\Command\GenerateDirectiveResolverCommand;
use Axtiva\FlexibleGraphqlBundle\Command\GenerateFieldResolverCommand;
Expand Down Expand Up @@ -163,50 +155,35 @@ private function registerConfigGenerator(array $config, ContainerBuilder $contai

private function registerTypeRegistryGenerator(array $config, ContainerBuilder $container): void
{
$container->register(TypeRegistryGeneratorBuilderInterface::class)
->setClass(TypeRegistryGeneratorBuilder::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));
$container->setAlias(
'flexible_graphql.type_registry_generator.builder',
TypeRegistryGeneratorBuilderInterface::class
);
if ($config['schema_type'] === Configuration::SCHEMA_TYPE_FEDERATION) {
$container->register(TypeRegistryGeneratorBuilderInterface::class)
->setClass(TypeRegistryGeneratorBuilderFederated::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));
$container->setAlias(
'flexible_graphql.type_registry_generator.builder',
TypeRegistryGeneratorBuilderFederated::class
);
} else {
$container->register(TypeRegistryGeneratorBuilderInterface::class)
->setClass(TypeRegistryGeneratorBuilder::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));
$container->setAlias(
'flexible_graphql.type_registry_generator.builder',
TypeRegistryGeneratorBuilderInterface::class
);
}
}

private function registerCodeGenerator(array $config, ContainerBuilder $container): void
{
$codeGenerator = $container->register(CodeGeneratorBuilderInterface::class)
->setClass(CodeGeneratorBuilder::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));

if ($config['schema_type'] === Configuration::SCHEMA_TYPE_FEDERATION) {
$container->register(FieldResolverGeneratorConfigInterface::class)
->setClass(FieldResolverGeneratorConfig::class)
$container->register(CodeGeneratorBuilderInterface::class)
->setClass(CodeGeneratorBuilderFederated::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));

$container->register(_EntitiesResolverGenerator::class)
->setArgument('$config', new Reference(FieldResolverGeneratorConfigInterface::class));
$codeGenerator->addMethodCall('addFieldResolverGenerator', [
new Reference(_EntitiesResolverGenerator::class),
]);

$container->register(_ServiceResolverGenerator::class)
->setArgument('$config', new Reference(FieldResolverGeneratorConfigInterface::class));
$codeGenerator->addMethodCall('addFieldResolverGenerator', [
new Reference(_ServiceResolverGenerator::class),
]);

$container->register(FederationRepresentationResolverGeneratorConfigInterface::class)
->setClass(FederationRepresentationResolverGeneratorConfig::class)
} else {
$container->register(CodeGeneratorBuilderInterface::class)
->setClass(CodeGeneratorBuilder::class)
->setArgument('$config', new Reference(CodeGeneratorConfigInterface::class));
$container->register(FederationRepresentationResolverGeneratorInterface::class)
->setClass(FederationRepresentationResolverGenerator::class)
->setArgument(
'$config',
new Reference(FederationRepresentationResolverGeneratorConfigInterface::class)
);
$codeGenerator->addMethodCall('addModelGenerator', [
new Reference(FederationRepresentationResolverGeneratorInterface::class),
]);
}
}

Expand Down Expand Up @@ -259,7 +236,7 @@ private function registerRepresentationResolver(array $config, ContainerBuilder
foreach ($services as $serviceId) {
$definition = $container->getDefinition($serviceId);
$reflection = $container->getReflectionClass($serviceId, false);
if ($reflection && $reflection->isSubclassOf(_EntitiesResolver::class)) {
if ($reflection && $reflection->isSubclassOf(_EntitiesResolverInterface::class)) {
$definition->setArguments($representations);
}
}
Expand All @@ -270,7 +247,7 @@ private function registerRepresentationResolver(array $config, ContainerBuilder
foreach ($services as $serviceId) {
$definition = $container->getDefinition($serviceId);
$reflection = $container->getReflectionClass($serviceId, false);
if ($reflection && $reflection->isSubclassOf(_ServiceResolver::class)) {
if ($reflection && $reflection->isSubclassOf(_ServiceResolverInterface::class)) {
$schema = '';
foreach (glob($config['schema_files']) as $fsElement) {
if (is_file($fsElement)) {
Expand Down
10 changes: 0 additions & 10 deletions src/Exception/FederationObjectNotFound.php

This file was deleted.

10 changes: 0 additions & 10 deletions src/Exception/RepresentationDoesNotHaveTypeNameField.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Exception/RepresentationResolverDoesNotFound.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Exception/SchemaParserException.php

This file was deleted.

1 change: 0 additions & 1 deletion src/FlexibleGraphqlBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Axtiva\FlexibleGraphqlBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class FlexibleGraphqlBundle extends Bundle
Expand Down

0 comments on commit 8726fc3

Please sign in to comment.