Types can be define 3 different ways:
The configuration way
Creating this file extension .types.yml
in src/*Bundle/Resources/config/graphql or app/config/graphql.
See the different possible types:
You can also define custom dirs using config:
overblog_graphql:
definitions:
mappings:
# auto_discover: false # to disable bundles and root dir auto discover
types:
-
type: yaml # or graphql or annotation null
dir: "%kernel.root_dir%/.../mapping" # sub directories are also searched
# suffix: .types # use to change default file suffix
-
types: [yaml, graphql] # to include different types from the same dir
dir: "%kernel.root_dir%/.../mapping"
The PHP way
You can also declare PHP types (any subclass of GraphQL\Type\Definition\Type)
in src/*Bundle/GraphQL or app/GraphQL
they will be auto discover (thanks to auto mapping). Auto map classes are accessible by service id
(example: AppBundle\GraphQL\Type\DateTimeType), you can also alias a type by
implementing Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface
that returns an array of aliases.
here an example:
<?php
namespace App\GraphQL\Type;
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface;
use GraphQL\Type\Definition\ScalarType;
class DateTimeType extends ScalarType implements AliasedInterface
{
/**
* {[@inheritdoc](https://github.com/inheritdoc)}
*/
public static function getAliases(): array
{
return ['DateTime', 'Date'];
}
// ...
}
Here an example of how this can be done with DI autoconfigure:
services:
_defaults:
autoconfigure: true
App\Type\:
resource: '../src/Type'
Note:
autoconfigure or this bundle auto mapping, the
only access to type is FQCN (or aliases if implements the aliases interface).The service way
Creating a service tagged overblog_graphql.type
services:
AppBundle\GraphQL\Type\DateTime:
# only for sf < 3.3
#class: AppBundle\GraphQL\Type\DateTime
tags:
- { name: overblog_graphql.type, alias: DateTime }
How can I help you explore Laravel packages today?