nuwave / nuwave/lighthouse

Support multiple schemas

Open
#273 39 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

I have a situation where I need multiple GraphQL endpoints for various access controls.

For example, there could be a public endpoint for creating user account, a private endpoint protected by auth middleware, or a private endpoint for super-admin accounts also protected by auth:admin middleware.

It makes sense that each of these roles should have their own GraphQL schema but not a "god schema" that covers all.

Currently, I can achieve this by getting rid of the middleware in config/lighthouse.php and set middleware for each field using the @middleware directive directly. But I'm wondering if this is the best practice for designing a nice GraphQL schema?

Anyway, I think there are some use cases for having multiple schemas. How do you think?

Solution

The value of config/lighthouse.php could be an array in an array, which each element of the root array represents a schema setting.

return [
    [
        'route_name' => 'graphql',

        'route_enable_get' => true,

        'route'           => [
            'prefix'     => '',
            'middleware' => ['api'],
        ],
    ],
    [
        'route_name' => 'public-graphql',

        'route_enable_get' => false,

        'route'           => [
            'prefix'     => '',
            'middleware' => ['public-api'],
        ],
    ],
];

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with config/lighthouse.php and the existing GraphQL route and middleware configuration; the issue does not name implementation files or tests. Review how separate endpoint settings could be represented, then define completion as supporting multiple independently configured GraphQL schemas and routes without relying on field-level @middleware directives.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.