overblog / graphql-php-generator
GraphQL types generator
Installs: 500 406
Dependents: 1
Suggesters: 0
Security: 0
Stars: 29
Watchers: 12
Forks: 10
Open Issues: 1
Requires
- php: >=7.1
- webonyx/graphql-php: >=0.13
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpunit/phpunit: ^5.7.26 || ^6.0 || ^7.2
- symfony/expression-language: ^3.4
- symfony/filesystem: ^3.4
- symfony/process: ^3.4
- symfony/yaml: ^3.4
README
GraphQL PHP types generator...
Installation
composer require overblog/graphql-php-generator
Usage
<?php $loader = require __DIR__.'/vendor/autoload.php'; use GraphQL\Schema; use Overblog\GraphQLGenerator\Generator\TypeGenerator; use Symfony\Component\ExpressionLanguage\Expression; $configs = [ 'Character' => [ 'type' => 'interface', 'config' => [ 'description' => new Expression('\'A character\' ~ \' in the Star Wars Trilogy\''), 'fields' => [ 'id' => ['type' => 'String!', 'description' => 'The id of the character.'], 'name' => ['type' => 'String', 'description' => 'The name of the character.'], 'friends' => ['type' => '[Character]', 'description' => 'The friends of the character.'], 'appearsIn' => ['type' => '[Episode]', 'description' => 'Which movies they appear in.'], ], 'resolveType' => 'Overblog\\GraphQLGenerator\\Tests\\Resolver::resolveType', ], ], /*...*/ 'Query' => [ 'type' => 'object', 'config' => [ 'description' => 'A humanoid creature in the Star Wars universe or a faction in the Star Wars saga.', 'fields' => [ 'hero' => [ 'type' => 'Character', 'args' => [ 'episode' => [ 'type' => 'Episode', 'description' => 'If omitted, returns the hero of the whole saga. If provided, returns the hero of that particular episode.', ], ], 'resolve' => ['Overblog\\GraphQLGenerator\\Tests\\Resolver', 'getHero'], ], ], ], /*...*/ ], ]; $typeGenerator = new TypeGenerator('\\My\\Schema\\NP'); $classesMap = $typeGenerator->generateClasses($configs, __DIR__ . '/cache/types'); $loader->addClassMap($classesMap); $schema = new Schema(\My\Schema\NP\QueryType::getInstance());