PHPackages                             yakovenko/laravel-lighthouse-graphql-multi-schema - 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. yakovenko/laravel-lighthouse-graphql-multi-schema

ActiveLibrary[API Development](/categories/api)

yakovenko/laravel-lighthouse-graphql-multi-schema
=================================================

A Laravel package that provides multi-schema support for Lighthouse GraphQL.

v2.2.3(2mo ago)1562.5k↑44.8%3MITPHPPHP ^8

Since Aug 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/as-yakovenko/laravel-lighthouse-graphql-multi-schema)[ Packagist](https://packagist.org/packages/yakovenko/laravel-lighthouse-graphql-multi-schema)[ RSS](/packages/yakovenko-laravel-lighthouse-graphql-multi-schema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (17)Used By (0)

Lighthouse GraphQL Multi-Schema
===============================

[](#lighthouse-graphql-multi-schema)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f848fe26781d66fe041671fabb0af7c720c7ab2ffc273b70bbc82c610e8e94e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79616b6f76656e6b6f2f6c61726176656c2d6c69676874686f7573652d6772617068716c2d6d756c74692d736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yakovenko/laravel-lighthouse-graphql-multi-schema)[![Total Downloads](https://camo.githubusercontent.com/0441076a95b931258d83f1f3a38baee4e0691cd10327a199a755c7cda05d9b8a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79616b6f76656e6b6f2f6c61726176656c2d6c69676874686f7573652d6772617068716c2d6d756c74692d736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yakovenko/laravel-lighthouse-graphql-multi-schema)[![License](https://camo.githubusercontent.com/e5d287fa4dfa55f87ca8a105b9fc7f5d64c287cf45af39457abaf10dc8e8c8aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f79616b6f76656e6b6f2f6c61726176656c2d6c69676874686f7573652d6772617068716c2d6d756c74692d736368656d612e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

`yakovenko/laravel-lighthouse-graphql-multi-schema` is a Laravel package that provides multi-schema support for Lighthouse GraphQL. It allows you to manage multiple GraphQL schemas within a single Laravel application, streamlining development and extending functionality.

Why use this package?
---------------------

[](#why-use-this-package)

Managing multiple GraphQL schemas in a single Laravel application can quickly become complex.

This package is useful when:

- You need API versioning (v1, v2, v3)
- You separate admin and public APIs
- You build modular or domain-driven architectures

It provides a clean, scalable, and production-ready solution for handling multiple schemas with Laravel Lighthouse.

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

[](#installation)

### Requirements

[](#requirements)

- PHP : ^8
- Laravel : ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0
- Nuwave Lighthouse : ^6.0

### 🚀 What's New

[](#-whats-new)

#### v2.2.0

[](#v220)

- **Multi-Schema IDE Helper**: Generate IDE helper files for individual schemas
- **Multi-Schema Validation**: Validate GraphQL schemas with detailed error reporting
- Full compatibility with standard Lighthouse commands
- Schema isolation and safe file generation

#### v2.0.0

[](#v200)

- Full support for **Laravel Octane** and **long-lived workers** (Swoole, RoadRunner, etc).
    *See [release notes](https://github.com/as-yakovenko/laravel-lighthouse-graphql-multi-schema/releases/tag/v2.0.0) for technical details.*

### Install the Package

[](#install-the-package)

You can install the package using Composer:

```
composer require yakovenko/laravel-lighthouse-graphql-multi-schema
```

**Publish Configuration**

After installing the package, you need to publish the configuration file by running the following command:

```
php artisan lighthouse-multi-schema:publish-config
```

This will create a configuration file named `lighthouse-multi-schema.php` in the config/ directory, where you can set up your GraphQL schemas.

**Configuration**

In the config/lighthouse-multi-schema.php file, you can define your schemas and their settings. Here's an example configuration:

```
return [
    'multi_schemas' => [
        'schema1' => [
            'route_uri'           => '/schema1-graphql',
            'route_name'          => 'schema1-graphql',
            'schema_path'         => base_path("graphql/schema1.graphql"),
            'schema_cache_path'   => env('LIGHTHOUSE_SCHEMA1_CACHE_PATH', base_path("bootstrap/cache/schema1-schema.php")),
            'schema_cache_enable' => env('LIGHTHOUSE_SCHEMA1_CACHE_ENABLE', false),
            'middleware' => [
                // Always set the `Accept: application/json` header.
                Nuwave\Lighthouse\Http\Middleware\AcceptJson::class,

                // Logs in a user if they are authenticated. In contrast to Laravel's 'auth'
                // middleware, this delegates auth and permission checks to the field level.
                Nuwave\Lighthouse\Http\Middleware\AttemptAuthentication::class,

                // Apply your custom middleware here.
                // For example:
                // App\Http\Middleware\ExampleSchemaMiddleware::class,
            ]
        ],
        'schema2' => [
            'route_uri'           => '/schema2-graphql',
            'route_name'          => 'schema2-graphql',
            'schema_path'         => base_path("graphql/schema2.graphql"),
            'schema_cache_path'   => env('LIGHTHOUSE_SCHEMA2_CACHE_PATH', base_path("bootstrap/cache/schema2-schema.php")),
            'schema_cache_enable' => env('LIGHTHOUSE_SCHEMA2_CACHE_ENABLE', false),
            'middleware' => [ ... ]
        ],
        // Add additional schemas as needed
    ],
];
```

**Middleware Support**

You can now add middleware specific to each GraphQL schema, allowing you to apply different middleware configurations based on the schema being used. Specify the middleware classes in the middleware array for each schema, and they will be applied to the corresponding routes.

**CSRF exceptions Laravel ^11**

To disable CSRF verification for your GraphQL routes in Laravel 11, update `bootstrap/app.php` with the following configuration:

```
