- Install the bundle (more details)
composer require overblog/graphql-bundle
- Configure the bundle to accept
graphql
format (more details)
# config/packages/graphql.yaml
overblog_graphql:
definitions:
schema:
query: Query
mappings:
auto_discover: false
types:
-
- type: yaml
+ type: graphql
dir: "%kernel.project_dir%/config/graphql/types"
suffix: ~
-
Define schema using GraphQL schema language in files
config/graphql/types/*.graphql
-
Define schema Resolvers (more details)
<?php
// src/Resolver/MyResolverMap.php
namespace App\Resolver;
use Overblog\GraphQLBundle\Resolver\ResolverMap;
class MyResolverMap extends ResolverMap
{
protected function map()
{
// return your resolver map
}
}
- Test your schema using GraphiQL or with curl
curl 'http://127.0.0.1:8000/' \
-H 'Content-Type: application/json' \
--data-binary '{"query":"{ humans {id name direwolf {id name} } }","variables":{}}'
This is it!