GraphQL ORM is a lightweight GraphQL ORM for PHP/Symfony, inspired by concepts from Doctrine ORM.
It allows you to map PHP objects to a GraphQL API using attributes, and provides repositories, a query builder, automatic hydration, relation handling, schema validation, and deep Symfony integration.
composer require hecht-a/graphql-ormRequirements: PHP 8.4+ and Symfony 7.4 or 8.x.
The bundle relies on the HTTP client service provided by FrameworkBundle (framework.http_client, enabled by default
when symfony/http-client is installed).
# config/packages/graphql_orm.yaml
graphql_orm:
endpoint: 'http://localhost:4000/graphql'
mapping:
entity:
dir: '%kernel.project_dir%/src/GraphQL/Entity'
namespace: App\GraphQL\Entity
repository:
dir: '%kernel.project_dir%/src/GraphQL/Repository'
namespace: App\GraphQL\Repositoryphp bin/console graphqlorm:make:entity Task$tasks = $taskRepository->findAll();
$qb = $taskRepository->createQueryBuilder();
$tasks = $qb
->select('id', 'title', 'user.name')
->where($qb->expr()->eq('status', 'active'))
->limit(10)
->getQuery()
->getResult();The documentation is published at https://hecht-a.github.io/graphql-orm/, and its pages live in docs/:
- Configuration
- Entity mapping
- Repositories
- Query Builder
- Pagination
- Dialects
- Schema validation
- Logging
- Profiler
- Events — metrics, tracing
- Hydration hooks —
#[BeforeHydrate],#[AfterHydrate] - Forms —
GraphqlEntityType, a choice among entities - Serializer — entities written without loading their lazy relations
- Doctrine — Doctrine entities referencing GraphQL entities
- Caching — result cache and second-level cache
- Several APIs — a manager for each API
- Console commands
- PHPStan rules — field names checked at analysis time
- Testing —
MockGraphqlServer, a GraphQL server for the tests of your application - Upgrading from 4.x
MIT, see LICENSE.