PHPackages                             uniben/laravelgraphqlable - 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. uniben/laravelgraphqlable

ActiveLibrary

uniben/laravelgraphqlable
=========================

A quick and easy way to build prototype GraphQL queries and mutations for your Laravel models and controllers.

244[4 issues](https://github.com/UniBen/laravel-graphqlable/issues)PHPCI failing

Since Feb 20Pushed 5y agoCompare

[ Source](https://github.com/UniBen/laravel-graphqlable)[ Packagist](https://packagist.org/packages/uniben/laravelgraphqlable)[ RSS](/packages/uniben-laravelgraphqlable/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

LaravelGraphQLable
==================

[](#laravelgraphqlable)

Quick start guide
-----------------

[](#quick-start-guide)

Simply add the GraphQLable trait to your models or the GraphQL macro to your routes to add them to your schema. fields are automatically mapped to graphql types or can be configured to use a custom graphql field map for models and routes.

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

[](#installation)

Via Composer

```
$ composer require uniben/laravelgraphqlable
```

Usage
-----

[](#usage)

### Models, GraphQL Types and controllers

[](#models-graphql-types-and-controllers)

#### Types

[](#types)

LaravelGraphQLable automatically generates GraphQL Types by searching for models which use the `GraphQLQueryableTrait`

Simply add the `GraphQLQueryableTrait` trait to your model and query the graphql endpoint at `/graphql`. LaravelGraphQLable also comes shipped with graphql-playground which you can access at `/graphql-playrgound`

You may customise what properties, methods and relations your grapql model type exposes using the method `graphQLQueryable`, `graphQLMutatable` and `graphQLRelations`.

##### Exposing fields for your graphql type

[](#exposing-fields-for-your-graphql-type)

```
public static function graphQLQueryable() {
    return [
        'id',
        'created_at',
        'updated_at'
    ];
}
```

Note: Relations you add to the graphQLRelations array must use the `GraphQLQueryableTrait`

You may also declare mutations for your model using `graphQLMutatable`. Simply override the public static method and return an array of strings which reference methods that should be included as mutations for the type.

##### Exposing type mutations

[](#exposing-type-mutations)

```
public static function graphQLMutatable(): array {
    return [
        'sayHello'
    ]
}

public function sayHello() {
    return $this->name . ' says hello!';
}
```

##### Exposing relations for your graphql type

[](#exposing-relations-for-your-graphql-type)

```
public static function graphQLRelations(): array {
    return [
        'page'
    ];
}

public function page() {
    $this->hasOne(Page::class);
}
```

##### Changing the default GraphQL Type name

[](#changing-the-default-graphql-type-name)

The default name the GraphQL type uses is the pluralised version of the model name.

E.g:

```
class User {
    use GraphQLQueryableTrait;
}
```

Generates a GraphQL Type called Users.

An example graphql User model query may look something like this:

```
query { Users { id, name, created_at }}

```

### Controllers

[](#controllers)

You may declare special routes in your web.php file or api.php file which return a model that uses the `GraphQLQueryableTrait`

#### Adding a query to the GraphQL schema via a controller

[](#adding-a-query-to-the-graphql-schema-via-a-controller)

##### The route

[](#the-route)

```
Route::any('sayHello', 'UsersController@sayHello')->graphQL(App\User::class, 'query');
```

What's happening there?

First we define a route using the regular Laravel method.

```
Route::get('sayHello', 'UsersController@sayHello')
```

We then use the GraphQL query macro which tells LaravelGraphQLable to add this controller method (or closure) to our GraphQLSchema

```
...->graphQL(App\User::class, 'query');
```

For the first parameter we provide the class path of the GraphQL Type we wish to return. In the example above we reference a Laravel model which uses the `GraphQLQueryableTrait`

We do not need to retrieve the type for the model. As long as it uses the trait, it is done automatically.

For the second parameter, we specify if the type should be a query or mutation.

##### Overriding a controller type name

[](#overriding-a-controller-type-name)

A route which uses the graphQL macro generates a graphQL type which has a default name of {controller}{Method}{Type} (If your controller name has the word Controller as the suffix it is removed)

If you want to override the default name generated for your type, simply add the name macro to your route.

```
->graphQL(...)->name('SayHello');
```

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ben Watson](https://github.com/uniben)
- [All Contributors](../../contributors%5D)

License
-------

[](#license)

license. Please see the [license file](license.md) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/fcd9d328ee65e191579e2185a68a531b36fbdcb750d1b24fc06ea79f3facee97?d=identicon)[Uniben](/maintainers/Uniben)

---

Top Contributors

[![blwsh](https://avatars.githubusercontent.com/u/32358483?v=4)](https://github.com/blwsh "blwsh (26 commits)")[![blwatson](https://avatars.githubusercontent.com/u/11888168?v=4)](https://github.com/blwatson "blwatson (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

### Embed Badge

![Health badge](/badges/uniben-laravelgraphqlable/health.svg)

```
[![Health](https://phpackages.com/badges/uniben-laravelgraphqlable/health.svg)](https://phpackages.com/packages/uniben-laravelgraphqlable)
```

PHPackages © 2026

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