Containers

Internal to the classes used in this library, PSR-11 containers are used. You can set values in the containers using container->set($id, $value);. If a value already exists for the $id then it will be overwritten.

Containers will execute any Closure found when getting from itself and pass the container to the closure as the only argument. This provides a basic method for using factories. Once a factory has executed the result will replace the factory so later requests will just get the composed object.

There are two containers you should be aware of if you intened to extend this library.

Type Manager

The TypeManager stores all the GraphQL types created or used in the library. If you want to specify your own type for a field you’ll need to add your custom type to the container.

1<?php
2
3use ApiSkeletons\Doctrine\GraphQL\Driver;
4use ApiSkeletons\Doctrine\GraphQL\Type\TypeManager;
5use GraphQL\Type\Definition\Type;
6
7$driver = new Driver($this->getEntityManager());
8$driver->get(TypeManager::class)
9    ->set('customtype', fn() => Type::string());

Custom Types

For instance, if your schema has a timestamp type, that data type is not suppored by default in this library. But adding the type is just a matter of creating a new Timestamp type (modifying the DateTime class is uncomplicated) then adding the type to the type manager.

1$driver->get(TypeManager::class)
2    ->set('timestamp', fn() => new Type\Timestamp());

Hydrator Factory

The HydratorFactory stores hydrator strategies, filter classes, naming strategy classes, and all the generated hydrators.

1<?php
2
3use ApiSkeletons\Doctrine\GraphQL\Driver;
4use ApiSkeletons\Doctrine\GraphQL\Hydrator\HydratorFactory;
5
6$driver = new Driver($this->getEntityManager());
7$driver->get(HydratorFactory::class)
8    ->set('customstrategy', fn() => new CustomStrategy());

This is documentation for API-Skeletons/doctrine-graphql. Please add your ★ star to the project.

Authored by API Skeletons.