PHPackages                             rahuljayaraman/doctrine-graphql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. rahuljayaraman/doctrine-graphql

ActiveLibrary[API Development](/categories/api)

rahuljayaraman/doctrine-graphql
===============================

Use Doctrine entities as GraphQL types

v0.1.0(8y ago)136.6k1[6 issues](https://github.com/rahuljayaraman/doctrine-graphql/issues)PHPPHP &gt;=5.3.0

Since Jul 27Pushed 7y ago5 watchersCompare

[ Source](https://github.com/rahuljayaraman/doctrine-graphql)[ Packagist](https://packagist.org/packages/rahuljayaraman/doctrine-graphql)[ RSS](/packages/rahuljayaraman-doctrine-graphql/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (2)Used By (0)

### WARNING: This repo is just an experiment &amp; is not maintained. Please use at your own risk. Suggest using  instead

[](#warning-this-repo-is-just-an-experiment--is-not-maintained-please-use-at-your-own-risk-suggest-using-httpsgithubcomecodevgraphql-doctrine-instead)

Doctrine GraphQL Mapper
-----------------------

[](#doctrine-graphql-mapper)

*Builds GraphQL types out of doctrine entities*

### Installation

[](#installation)

```
$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar require rahuljayaraman/doctrine-graphql

```

### Requirements

[](#requirements)

PHP &gt;=5.4

### Overview

[](#overview)

The mapper builds GraphQL types out of doctrine entities. It's built on top of [webonyx/graphql-php](webonyx/graphql-php) and maps doctrine entities to an [ObjectType](http://webonyx.github.io/graphql-php/type-system/object-types/) graph at runtime.

Here's an example. Consider the following schema

```
Employee
│
└───Company (getCompanies)
|
└───User (getUser)

```

We can extract the type for Employee by using

```
Mapper::extractType(Employee::class)
```

[Associations](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html) are recursively extracted as well. So `$employee->getCompanies()` would return [ListOf](http://webonyx.github.io/graphql-php/type-system/lists-and-nonnulls/) Type Company &amp; `$employee->getUser()` would return Type User

#### NOTE: This library is not responsible for any of your GraphQL setup like setting up routes, root nodes etc.

[](#note-this-library-is-not-responsible-for-any-of-your-graphql-setup-like-setting-up-routes-root-nodes-etc)

### TODO

[](#todo)

- [Support 'Relay Cursor Connections' ](https://github.com/rahuljayaraman/doctrine-graphql/issues/2)
- [Remove Doctrine coupling](https://github.com/rahuljayaraman/doctrine-graphql/issues/4)
- [Allow wrapping getter code](https://github.com/rahuljayaraman/doctrine-graphql/issues/3)

### Usage

[](#usage)

#### Setup

[](#setup)

Setup accepts 3 args. Doctrine's EntityManager, a setter method &amp; a getter method to a type store (a data structure which stores types).

```
//Setup code, I use this in a laravel service provider
use RahulJayaraman\DoctrineGraphQL\Mapper;
use Doctrine\ORM\EntityManager;

Mapper::setup(
    app(EntityManager::class),
    function ($typeName, $type) {
        Cache::add($type, $typeName);
    },
    function ($typeName) {
        return Cache::get($typeName);
    }
);
```

`Cache` above could be replaced by any store. Eg. using [Folkloreatelier/laravel-graphql](https://github.com/Folkloreatelier/laravel-graphql)'s store

```
use Folklore\GraphQL\Support\Facades\GraphQL;

Mapper::setup(
    app(EntityManager::class),
    function ($typeName, $type) {
        GraphQL::addType($type, $typeName);
    },
    function ($typeName) {
        return GraphQL::type($typeName);
    }
);
```

#### Extract type

[](#extract-type)

To extract the type

```
Mapper::extractType(Entity::class);
```

We could place it [here](https://github.com/Folkloreatelier/laravel-graphql#creating-a-query) if using with [Folkloreatelier/laravel-graphql](https://github.com/Folkloreatelier/laravel-graphql).

```
public function type()
{
   return Mapper::extractType(Entity::class);
}
```

#### Default resolver

[](#default-resolver)

For now, given a field name, say `fieldName`, the mapper will look for a `getFieldName` getter method on the entity. There are plans to allow customization here.

#### Register additional fields

[](#register-additional-fields)

For registering additional fields, one can use the RegisterField annotation.

RegisterField accepts `name`, `type` and `args`.

`name` accepts a string.

`type` accepts either an [internal type](https://github.com/webonyx/graphql-php#internal-types) or any of the extracted entities.

`args` accepts an array of tuples in the form of `{{string, type}}`

Here's an example

```
use RahulJayaraman\DoctrineGraphQL\Annotations\RegisterField;

/**
 * getEmployee
 *
 * @RegisterField(name="CustomName" type="Employee", args={{"slug", "string"}})
 */
public function getEmployee($slug)
{
    return ...
}
```

#### Blacklist fields

[](#blacklist-fields)

Fields can be blacklisted using the BlacklistField annotation. Here's an example.

```
use RahulJayaraman\DoctrineGraphQL\Annotations\BlacklistField;

/**
 * @var string
 * @ORM\Column(type="string")
 * @BlacklistField()
 */
private $password;
```

### Complementary Tools

[](#complementary-tools)

- [Use GraphQL with Laravel 5](https://github.com/Folkloreatelier/laravel-graphql)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance11

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3260d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/019053c61dd996a424edb176f5c9a292caa9d4022c52e8bb08504d8f965a74d0?d=identicon)[rahul.jayaraman](/maintainers/rahul.jayaraman)

---

Top Contributors

[![rahuljayaraman](https://avatars.githubusercontent.com/u/1269539?v=4)](https://github.com/rahuljayaraman "rahuljayaraman (43 commits)")[![shinderohitt](https://avatars.githubusercontent.com/u/1011044?v=4)](https://github.com/shinderohitt "shinderohitt (3 commits)")

### Embed Badge

![Health badge](/badges/rahuljayaraman-doctrine-graphql/health.svg)

```
[![Health](https://phpackages.com/badges/rahuljayaraman-doctrine-graphql/health.svg)](https://phpackages.com/packages/rahuljayaraman-doctrine-graphql)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M717](/packages/sylius-sylius)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1175.2k](/packages/rcsofttech-audit-trail-bundle)[api-skeletons/doctrine-orm-graphql

GraphQL Type Driver for Doctrine ORM

125.5k1](/packages/api-skeletons-doctrine-orm-graphql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
