diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..02206db --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +1.0.0 + +Improve ux for generated code + +- Upgrade base lib diff --git a/README.md b/README.md index 5202927..2e2cd21 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ Symfony bundle for Flexible Graphql PHP +- SDL first code generation +- Fast integration to any project without breaking changes +- Lazy loading on schema definition - Support symfony native opcache preload file generation # Setup diff --git a/composer.json b/composer.json index f6ab26e..be2632a 100644 --- a/composer.json +++ b/composer.json @@ -14,16 +14,17 @@ } }, "require": { - "php": ">=7.4", - "axtiva/flexible-graphql-php": "^0.2", - "axtiva/flexible-graphql-federation": "^0.2", - "axtiva/graphql-federation-extension": "^0.1", + "php": "^7.4 | ^8.0", + "axtiva/flexible-graphql-php": "^1.0", + "axtiva/flexible-graphql-federation": "^0.3", + "axtiva/graphql-federation-extension": "^1.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", "symfony/property-access": "^4.4 | ^5.0 | ^6.0" }, "require-dev": { - "symfony/console": "^4.4 | ^5.0 | ^6.0" + "symfony/console": "^4.4 | ^5.0 | ^6.0", + "phpunit/phpunit": "^9.5" } } diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..d3a5368 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,109 @@ +# axtiva/flexible-graphql-bundle + +# Get started + +## Example project + +Open example project [axtiva/example-integration/FlexibleGraphqlBundle](https://github.com/axtiva/example-integration/tree/master/FlexibleGraphqlBundle) + +## Composer install in your Symfony app + +``` +composer require axtiva/flexible-graphql-bundle +``` + +## Add bundle config + +Create bundle config: + +```yaml +# content of config/packages/flexible_graphql.yaml +flexible_graphql: + namespace: App\GraphQL # namespace where store GraphQL models and resolvers + dir: '%kernel.project_dir%/src/GraphQL/' # path where it will be they save files + schema_type: graphql # type of schema generation. Default is `graphql` or optional is `federation` for apollo federation support + schema_files: '%kernel.project_dir%/config/graphql/*.graphql' # path to graphql schema SDL files + enable_preload: false # use Symfony preload if it true + default_resolver: flexible_graphql.default_resolver # default resolver if it does not defined +``` + +## Run type registry code generation + +``` +bin/console flexible_graphql:generate-type-registry +``` + +## Create GraphQL Controller + +Here we use [symfony/psr-http-message-bridge](https://github.com/symfony/psr-http-message-bridge) +for convert Symfony request to psr Request with [nyholm/psr7](https://github.com/Nyholm/psr7) + +```php +typeRegistry = $typeRegistry; + $this->httpFactory = $httpFactory; + } + + #[Route('/graphql', name: 'graphql')] + public function index(Request $request): Response + { + $typeRegistry = $this->typeRegistry; + $schema = new Schema([ + 'query' => $typeRegistry->getType('Query'), + 'mutation' => $typeRegistry->getType('Mutation'), + 'typeLoader' => static function (string $typeName) use ($typeRegistry): Type { + return $typeRegistry->getType($typeName); + } + ]); + + $validationRules = array_merge( + GraphQL::getStandardValidationRules(), + [ + new Rules\QueryComplexity(PHP_INT_MAX), + ] + ); + + $debugFlag = DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE | DebugFlag::RETHROW_INTERNAL_EXCEPTIONS | DebugFlag::RETHROW_UNSAFE_EXCEPTIONS; + + $psrRequest = $this->httpFactory->createRequest($request); + $config = ServerConfig::create() + ->setContext(['user' => $this->getUser()]) + ->setSchema($schema) + ->setValidationRules($validationRules) + ->setQueryBatching(true) + ->setDebugFlag($debugFlag) + ; + + $server = new StandardServer($config); + $psrResponse = $server->executePsrRequest($psrRequest); + return new JsonResponse($psrResponse); + } +} +``` diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index dbe7b70..f52fa4d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -82,7 +82,7 @@ private function schemaFile(): ScalarNodeDefinition $node = $treeBuilder->getRootNode(); $node - ->info('Full path to schema sdl files like schema.graphql or glob template') + ->info('Full path to schema sdl files like /path/to/schema.graphql or glob template') ->defaultValue('%kernel.project_dir%/config/graphql/*.graphql') ->isRequired() ->end(); diff --git a/src/Resources/config/flexible_graphql.yaml b/src/Resources/config/flexible_graphql.yaml index 3b912b8..187ea10 100644 --- a/src/Resources/config/flexible_graphql.yaml +++ b/src/Resources/config/flexible_graphql.yaml @@ -2,6 +2,6 @@ flexible_graphql: namespace: App\GraphQL dir: '%kernel.project_dir%/src/GraphQL/' schema_type: graphql - schema_file: '%kernel.project_dir%/config/graphql/*.graphql' + schema_files: '%kernel.project_dir%/config/graphql/*.graphql' enable_preload: false default_resolver: flexible_graphql.default_resolver