Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI

on:
push:
pull_request:

jobs:
Expand Down Expand Up @@ -29,9 +28,6 @@ jobs:
- name: Install Symfony matrix dependencies
run: composer update --no-interaction --prefer-dist --with-all-dependencies symfony/*:${{ matrix.symfony-version }}

- name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon.dist

- name: Run PHPUnit
run: vendor/bin/phpunit -c phpunit.xml.dist --coverage-text

Expand All @@ -40,3 +36,6 @@ jobs:

- name: Fixture app type registry generation
run: php tests/fixture-app/bin/console flexible_graphql:generate-type-registry --env=test --no-interaction

- name: Run PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon.dist
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ Quick install [guide](docs/index.md)
```shell
bin/console list flexible_graphql
```

## Tests

Run tests

```
php vendor/bin/phpunit
```

## PHPStan

Run PHPStan

```
php vendor/bin/phpstan analyse -c phpstan.neon.dist
```
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"require": {
"php": "^8.3",
"axtiva/flexible-graphql-php": "^3.0",
"axtiva/flexible-graphql-php": "^3.0.1",
"symfony/console": "^6.4 | ^7.0 | ^8.0",
"symfony/config": "^6.4 | ^7.0 | ^8.0",
"symfony/dependency-injection": "^6.4 | ^7.0 | ^8.0",
Expand Down
5 changes: 5 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

ini_set('memory_limit', '1G');
11 changes: 10 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
parameters:
level: 6
bootstrapFiles:
- phpstan-bootstrap.php
parallel:
maximumNumberOfProcesses: 4
paths:
- src
- tests
excludePaths:
analyse:
- tests/fixture-app/var/*
- tests/fixture-app/var/cache/*
tmpDir: var/phpstan
ignoreErrors:
-
identifier: missingType.generics
paths:
- tests/fixture-app/var/generated/*
3 changes: 1 addition & 2 deletions src/Command/GenerateDirectiveResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#[AsCommand(name: 'flexible_graphql:generate-directive-resolver')]
class GenerateDirectiveResolverCommand extends Command
{
protected static ?string $defaultName = 'flexible_graphql:generate-directive-resolver';
private string $schemaFiles;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;

Expand All @@ -30,7 +29,7 @@ public function __construct(
$this->codeGeneratorBuilder = $codeGeneratorBuilder;
}

protected function configure()
protected function configure(): void
{
$this
->setDescription('generate executive directive resolver')
Expand Down
1 change: 0 additions & 1 deletion src/Command/GenerateFieldResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#[AsCommand(name: 'flexible_graphql:generate-field-resolver')]
class GenerateFieldResolverCommand extends Command
{
protected static ?string $defaultName = 'flexible_graphql:generate-field-resolver';
private string $schemaFiles;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;

Expand Down
1 change: 0 additions & 1 deletion src/Command/GenerateScalarResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#[AsCommand(name: 'flexible_graphql:generate-scalar-resolver')]
class GenerateScalarResolverCommand extends Command
{
protected static ?string $defaultName = 'flexible_graphql:generate-scalar-resolver';
private string $schemaFiles;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;

Expand Down
1 change: 0 additions & 1 deletion src/Command/GenerateTypeRegistryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#[AsCommand(name: 'flexible_graphql:generate-type-registry')]
class GenerateTypeRegistryCommand extends Command
{
protected static ?string $defaultName = 'flexible_graphql:generate-type-registry';
private string $schemaFiles;
private TypeRegistryGeneratorBuilderInterface $typeRegistryGeneratorBuilder;
private CodeGeneratorBuilderInterface $codeGeneratorBuilder;
Expand Down
23 changes: 17 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Axtiva\FlexibleGraphqlBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;
use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand All @@ -23,6 +25,7 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(self::NAME, 'array');

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$rootNode
Expand All @@ -36,7 +39,7 @@ public function getConfigTreeBuilder(): TreeBuilder
'namespace',
'App\GraphQL',
'Root namespace for generated code'
)->isRequired())
))
->append($this->addScalar(
'template_language_version',
'8.3',
Expand All @@ -46,13 +49,16 @@ public function getConfigTreeBuilder(): TreeBuilder
'dir',
'%kernel.project_dir%/src/GraphQL/',
'Root dir for generated code'
)->isRequired())
))
->end();

return $treeBuilder;
}

private function schemaType(): ScalarNodeDefinition
/**
* @return EnumNodeDefinition<null>
*/
private function schemaType(): EnumNodeDefinition
{
$treeBuilder = new TreeBuilder('schema_type', 'enum');

Expand All @@ -68,7 +74,10 @@ private function schemaType(): ScalarNodeDefinition
return $node;
}

private function operationType(): ScalarNodeDefinition
/**
* @return EnumNodeDefinition<null>
*/
private function operationType(): EnumNodeDefinition
{
$treeBuilder = new TreeBuilder('executor', 'enum');

Expand All @@ -84,7 +93,10 @@ private function operationType(): ScalarNodeDefinition
return $node;
}

private function enablePreload(): ScalarNodeDefinition
/**
* @return BooleanNodeDefinition<null>
*/
private function enablePreload(): BooleanNodeDefinition
{
$treeBuilder = new TreeBuilder('enable_preload', 'boolean');

Expand All @@ -109,7 +121,6 @@ private function schemaFile(): ScalarNodeDefinition
$node
->info('Full path to schema sdl files like /path/to/schema.graphql or glob template')
->defaultValue('%kernel.project_dir%/config/graphql/*.graphql')
->isRequired()
->end();

return $node;
Expand Down
50 changes: 50 additions & 0 deletions src/DependencyInjection/FlexibleGraphqlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
use Axtiva\FlexibleGraphql\Builder\TypeRegistryGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\Generator\Config\CodeGeneratorConfigInterface;
use Axtiva\FlexibleGraphql\Generator\Config\Foundation\Psr4\CodeGeneratorConfig;
use Axtiva\FlexibleGraphql\Resolver\CustomScalarResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\DirectiveResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\FederationRepresentationResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\_EntitiesResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\ResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\_ServiceResolverInterface;
use Axtiva\FlexibleGraphql\Resolver\UnionResolveTypeInterface;
use Axtiva\FlexibleGraphqlBundle\Builder\ScopedTypeRegistryGeneratorBuilder;
use Axtiva\FlexibleGraphqlBundle\CacheWarmer\SchemaCacheWarmer;
use Axtiva\FlexibleGraphqlBundle\Command\GenerateDirectiveResolverCommand;
Expand Down Expand Up @@ -66,6 +71,9 @@ public function load(array $configs, ContainerBuilder $container): void
{
$yamlLoader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$yamlLoader->load('services.yaml');

$this->registerResolverAutoconfiguration($container);

$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
$this->config = $config;
$this->registerConfigGenerator($this->config, $container);
Expand All @@ -92,6 +100,48 @@ public function getAlias(): string
return Configuration::NAME;
}

private function registerResolverAutoconfiguration(ContainerBuilder $container): void
{
$container
->registerForAutoconfiguration(ResolverInterface::class)
->setPublic(true)
->addTag(self::RESOLVER_TAG)
->addTag(self::TYPE_REGISTRY_SERVICE_TAG);

$container
->registerForAutoconfiguration(DirectiveResolverInterface::class)
->setPublic(true)
->addTag(self::DIRECTIVE_RESOLVER_TAG)
->addTag(self::TYPE_REGISTRY_SERVICE_TAG);

$container
->registerForAutoconfiguration(CustomScalarResolverInterface::class)
->setPublic(true)
->addTag(self::SCALAR_RESOLVER_TAG)
->addTag(self::TYPE_REGISTRY_SERVICE_TAG);

$container
->registerForAutoconfiguration(UnionResolveTypeInterface::class)
->setPublic(true)
->addTag(self::UNION_TYPE_RESOLVER_TAG)
->addTag(self::TYPE_REGISTRY_SERVICE_TAG);

$container
->registerForAutoconfiguration(FederationRepresentationResolverInterface::class)
->setPublic(true)
->addTag(self::FEDERATION_REPRESENTATION_RESOLVER_TAG);

$container
->registerForAutoconfiguration(_ServiceResolverInterface::class)
->setPublic(true)
->addTag(self::_SERVICE_RESOLVER_TAG);

$container
->registerForAutoconfiguration(_EntitiesResolverInterface::class)
->setPublic(true)
->addTag(self::_ENTITIES_RESOLVER_TAG);
}

/**
* @param array<string, mixed> $config
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/DependencyInjection/FlexibleGraphqlExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Axtiva\FlexibleGraphql\Builder\Foundation\Psr\Container\TypeRegistryGeneratorBuilderAmphpV2;
use Axtiva\FlexibleGraphql\Builder\Foundation\Psr\Container\TypeRegistryGeneratorBuilderFederated;
use Axtiva\FlexibleGraphql\Builder\TypeRegistryGeneratorBuilderInterface;
use Axtiva\FlexibleGraphql\Resolver\ResolverInterface;
use Axtiva\FlexibleGraphqlBundle\Builder\ScopedTypeRegistryGeneratorBuilder;
use Axtiva\FlexibleGraphqlBundle\DependencyInjection\FlexibleGraphqlExtension;
use Axtiva\FlexibleGraphqlBundle\Resolver\DefaultResolver;
Expand Down Expand Up @@ -71,6 +72,18 @@ public function testTypeRegistryScopedLocatorWiring(): void
self::assertArrayHasKey(FlexibleGraphqlExtension::TYPE_REGISTRY_SERVICE_TAG, $defaultResolverDefinition->getTags());
}

public function testResolverAutoconfigurationAddsTypeRegistryServiceTag(): void
{
$container = $this->loadExtension('graphql', 'sync');

$autoconfigurations = $container->getAutoconfiguredInstanceof();
self::assertArrayHasKey(ResolverInterface::class, $autoconfigurations);

$resolverAutoconfiguration = $autoconfigurations[ResolverInterface::class];
self::assertArrayHasKey(FlexibleGraphqlExtension::TYPE_REGISTRY_SERVICE_TAG, $resolverAutoconfiguration->getTags());
self::assertArrayHasKey(FlexibleGraphqlExtension::RESOLVER_TAG, $resolverAutoconfiguration->getTags());
}

/**
* @return iterable<string, array{string, string, string, string|null}>
*/
Expand Down
Loading
Loading