PHPackages                             optigov/eloquent-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. [Database &amp; ORM](/categories/database)
4. /
5. optigov/eloquent-graphql

ActiveLibrary[Database &amp; ORM](/categories/database)

optigov/eloquent-graphql
========================

This package provides automatic creation of GraphQL types and fields from Eloquent models.

v3.2.1(1y ago)42.3k↓48%MITPHPPHP ^8.0CI passing

Since Sep 21Pushed 1y agoCompare

[ Source](https://github.com/optiGov/eloquent-graphql)[ Packagist](https://packagist.org/packages/optigov/eloquent-graphql)[ RSS](/packages/optigov-eloquent-graphql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (73)Used By (0)

eloquent-graphql
================

[](#eloquent-graphql)

This package automatically creates GraphQL types and fields with their resolvers for the `webonyx/graphql-php` library from Eloquent models. The package utilizes the PHP DocBlock annotations to determine the GraphQL types and fields. It supports pagination, filtering and ordering on properties returning multiple models using a query builder for optimal performance.

Installation
------------

[](#installation)

```
composer require optigov/eloquent-graphql
```

Usage
-----

[](#usage)

### Annotate your Models

[](#annotate-your-models)

In order to make fields available in GraphQL, annotate your Models with the `@property` annotation.

```
/**
 * @property int $id
 * @property string $name
 * @property Author $author
 * @property-read $created_at
 * @property-read $updated_at
 */
class Book {
    // ...
}
```

```
/**
 * @property int $id
 * @property string $first_name
 * @property string $last_name
 * @property Books[] $books
 * @property-read $created_at
 * @property-read $updated_at
 */
class Author {
    // ...
}
```

### Build your Schema

[](#build-your-schema)

Build your Schema using the `EloquentGraphQLService` class.

```
use App\Models\Book;
use App\Models\Author;
use GraphQL\Type\Schema;
use EloquentGraphQL\Services\EloquentGraphQLService;

$graphQLService = new EloquentGraphQLService();

$schema = new Schema([
    'query' => $graphQLService->query()
        ->view(Book::class)
        ->view(Author::class)
        ->all(Book::class)
        ->all(Author::class)
        ->build(),
    'mutation' => $graphQLService->mutation()
        ->create(Book::class)
        ->create(Author::class)
        ->update(Book::class)
        ->update(Author::class)
        ->delete(Book::class)
        ->delete(Author::class)
        ->build(),
]);
```

Go Further
----------

[](#go-further)

### Pagination

[](#pagination)

Use the `@paginate` annotation to paginate properties returning multiple models using a query builder - for example has many relations.

```
/**
 * ...
 * @property Books[] $books @paginate
 * ...
 */
class Author {
    // ...
}
```

### Filtering and Ordering

[](#filtering-and-ordering)

Use the `@filterable` and `@orderable` annotations to enable filtering and ordering on properties returning multiple models using a query builder - for example has many relations.

```
/**
 * ...
 * @property Books[] $books @paginate @filterable @orderable
 * ...
 */
class Author {
    // ...
}
```

### Custom Fields

[](#custom-fields)

You can add custom fields to your GraphQL types using the `field()` method.

```
$schema = new Schema([
    'query' => $graphQLService->query()
        ->view(Book::class)
        ->field('customField', [
            'type' => Type::string(),
            'resolve' => function ($root, $args) {
                return 'Hello World!';
            }
        ])
        ->build(),
]);
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance45

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Every ~7 days

Recently: every ~13 days

Total

72

Last Release

423d ago

Major Versions

v0.2.7 → v1.0.02023-10-09

v1.1.3 → v2.0.02023-11-28

v2.4.10 → v3.0.02024-09-20

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/52662462?v=4)[joonlabs](/maintainers/joonlabs)[@joonlabs](https://github.com/joonlabs)

---

Top Contributors

[![joonlabs](https://avatars.githubusercontent.com/u/52662462?v=4)](https://github.com/joonlabs "joonlabs (166 commits)")

---

Tags

apilaravelgraphqlormeloquentoptiGov

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/optigov-eloquent-graphql/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[mostafaznv/laracache

LaraCache is a customizable cache trait to cache queries on model's events

27246.8k1](/packages/mostafaznv-laracache)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3059.0k](/packages/matchory-elasticsearch)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[mostafaznv/nova-laracache

LaraCache Tool for Laravel Nova

103.8k](/packages/mostafaznv-nova-laracache)

PHPackages © 2026

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