PHPackages                             ysll233/graphql-laravel5 - 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. [Framework](/categories/framework)
4. /
5. ysll233/graphql-laravel5

ActiveProject[Framework](/categories/framework)

ysll233/graphql-laravel5
========================

Laravel5 wrapper for PHP GraphQL

v1.15.8(7y ago)030MITPHPPHP &gt;=5.5.9

Since Mar 27Pushed 7y agoCompare

[ Source](https://github.com/Ysll233/graphql-laravel)[ Packagist](https://packagist.org/packages/ysll233/graphql-laravel5)[ RSS](/packages/ysll233-graphql-laravel5/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (24)Used By (0)

Laravel GraphQL
===============

[](#laravel-graphql)

[![Latest Stable Version](https://camo.githubusercontent.com/0169144623818e8a58d199cb3d5b0d246ecccced18155c534b0b38643e5041aa/68747470733a2f2f706f7365722e707567782e6f72672f726562696e672f6772617068716c2d6c61726176656c2f762f737461626c65)](https://packagist.org/packages/rebing/graphql-laravel)[![License](https://camo.githubusercontent.com/d87eb1a0fa4a1b11555d255a6e9d341f20de6983e951730f3246a61d8f93abbc/68747470733a2f2f706f7365722e707567782e6f72672f726562696e672f6772617068716c2d6c61726176656c2f6c6963656e7365)](https://packagist.org/packages/rebing/graphql-laravel)

Uses Facebook GraphQL with Laravel 5. It is based on the PHP implementation [here](https://github.com/webonyx/graphql-php). You can find more information about GraphQL in the [GraphQL Introduction](http://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html) on the [React](http://facebook.github.io/react) blog or you can read the [GraphQL specifications](https://facebook.github.io/graphql/). This is a work in progress.

This package is compatible with Eloquent models or any other data source.

- Allows creating **queries** and **mutations** as request endpoints
- Custom **middleware** can be defined for each query/mutation
- Queries return **types**, which can have custom **privacy** settings.
- The queried fields will have the option to be retrieved **dynamically** from the database with the help of the `SelectFields` class.

It offers following features and improvements over the original package by [Folklore](https://github.com/Folkloreatelier/laravel-graphql):

- Per-operation authorization
- Per-field callback defining its visibility (e.g. hiding from unauthenticated users)
- `SelectFields` abstraction available in `resolve()`, allowing for advanced eager loading and thus dealing with n+1 problems
- Pagination support
- Server-side support for [query batching](https://blog.apollographql.com/batching-client-graphql-queries-a685f5bcd41b)

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

[](#installation)

#### Dependencies:

[](#dependencies)

- [Laravel 5.x](https://github.com/laravel/laravel)
- [GraphQL PHP](https://github.com/webonyx/graphql-php)

#### Installation:

[](#installation-1)

**1.** Require the package via Composer

```
composer require rebing/graphql-laravel
```

**2.** Laravel 5.5+ will autodiscover the package, for older versions add the following service provider

```
Rebing\GraphQL\GraphQLServiceProvider::class,
```

and alias

```
'GraphQL' => 'Rebing\GraphQL\Support\Facades\GraphQL',
```

in your `config/app.php` file.

**3.** Publish the configuration file

```
$ php artisan vendor:publish --provider="Rebing\GraphQL\GraphQLServiceProvider"
```

**4.** Review the configuration file

```
config/graphql.php

```

Usage
-----

[](#usage)

- [Schemas](#schemas)
- [Creating a query](#creating-a-query)
- [Creating a mutation](#creating-a-mutation)
- [Adding validation to mutation](#adding-validation-to-mutation)
- [File uploads](#file-uploads)

##### Advanced Usage

[](#advanced-usage)

- [Authorization](docs/advanced.md#authorization)
- [Privacy](docs/advanced.md#privacy)
- [Query variables](docs/advanced.md#query-variables)
- [Custom field](docs/advanced.md#custom-field)
- [Eager loading relationships](docs/advanced.md#eager-loading-relationships)
- [Type relationship query](docs/advanced.md#type-relationship-query)
- [Pagination](docs/advanced.md#pagination)
- [Batching](docs/advanced.md#batching)
- [Enums](docs/advanced.md#enums)
- [Unions](docs/advanced.md#unions)
- [Interfaces](docs/advanced.md#interfaces)
- [Input Object](docs/advanced.md#input-object)
- [JSON Columns](docs/advanced.md#json-columns)

### Schemas

[](#schemas)

Schemas are required for defining GraphQL endpoints. You can define multiple schemas and assign different **middleware** to them, in addition to the global middleware. For example:

```
'schema' => 'default_schema',

'schemas' => [
    'default' => [
        'query' => [
            'example_query' => ExampleQuery::class,
        ],
        'mutation' => [
            'example_mutation'  => ExampleMutation::class,
        ],
    ],
    'user' => [
        'query' => [
            'profile' => App\GraphQL\Query\ProfileQuery::class
        ],
        'mutation' => [

        ],
        'middleware' => ['auth'],
    ],
],
```

### Creating a query

[](#creating-a-query)

First you need to create a type. The Eloquent Model is only required, if specifying relations.

> **Note:** The `selectable` key is required, if it's a non-database field or not a relation

```
