PHPackages                             xaddax/webonyx-psr15-middleware - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. xaddax/webonyx-psr15-middleware

ActiveComposer-plugin[HTTP &amp; Networking](/categories/http)

xaddax/webonyx-psr15-middleware
===============================

PSR-15 middleware for webonyx/graphql-php

v15.5.0(9mo ago)01.5k↓50%1MITPHPPHP ^8.3 || ^8.4CI passing

Since Aug 15Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/xaddax/webonyx-psr15-middleware)[ Packagist](https://packagist.org/packages/xaddax/webonyx-psr15-middleware)[ RSS](/packages/xaddax-webonyx-psr15-middleware/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (15)Versions (22)Used By (1)

PSR-15 GraphQL Middleware
=========================

[](#psr-15-graphql-middleware)

A framework-agnostic PSR-15 middleware for handling GraphQL requests using webonyx/graphql-php.

[![codecov](https://camo.githubusercontent.com/5f804ddde525639120de1cc1ef2c75b9f903da29032c13c23c0fa45f37ad932e/68747470733a2f2f636f6465636f762e696f2f67682f7861646461782f7765626f6e79782d70737231352d6d6964646c65776172652f67726170682f62616467652e7376673f746f6b656e3d4c5653475a3746465052)](https://codecov.io/gh/xaddax/webonyx-psr15-middleware)

Features
--------

[](#features)

- PSR-15 compliant middleware
- Framework agnostic
- Schema caching support
- Request preprocessing capabilities
- Flexible response handling
- Operation-specific resolvers with dependency injection support
- Resolver documentation

Documentation
-------------

[](#documentation)

- [Configuration](docs/configuration.md)
- [Request Preprocessing](docs/request-preprocessing.md)
- [Response Handling](docs/response-handling.md)
- [Resolvers](docs/resolvers.md)

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

[](#installation)

```
composer require xaddax/webonyx-psr15-middleware
```

Requirements
------------

[](#requirements)

- PHP 8.3+
- PSR-7 implementation (e.g., nyholm/psr7)
- PSR-17 HTTP factories implementation
- PSR-6 cache implementation (optional, e.g., symfony/cache)

Basic Usage
-----------

[](#basic-usage)

```
use GraphQL\Server\ServerConfig;
use GraphQL\Type\Schema;
use Nyholm\Psr7\Factory\Psr17Factory;
use GraphQL\Middleware\Factory\GraphQLMiddlewareFactory;

// Create PSR-17 factories
$psr17Factory = new Psr17Factory();

// Configure your GraphQL schema and server
$serverConfig = new ServerConfig();
$serverConfig->setSchema($schema);

// Create the middleware factory
$middlewareFactory = new GraphQLMiddlewareFactory(
    serverConfig: $serverConfig,
    responseFactory: $psr17Factory,
    streamFactory: $psr17Factory
);

// Create and add the middleware to your application
$middleware = $middlewareFactory->createMiddleware();
```

Schema Generation
-----------------

[](#schema-generation)

The library includes support for generating schemas from .graphql files:

```
use GraphQL\Middleware\Config\DefaultConfiguration;
use GraphQL\Middleware\Factory\GeneratedSchemaFactory;

// Configure schema generation
$schemaConfig = new DefaultConfiguration([
    'schema' => [
        'directories' => [__DIR__ . '/schema'],
        'parser_options' => [],
    ],
    'cache' => [
        'enabled' => true,
        'directory' => __DIR__ . '/cache',
    ],
]);

// Create schema factory
$schemaFactory = new GeneratedSchemaFactory($schemaConfig);
$schema = $schemaFactory->createSchema();
```

Framework Integration
---------------------

[](#framework-integration)

### Slim 4

[](#slim-4)

```
use Slim\Factory\AppFactory;

$app = AppFactory::create();
$app->add($middlewareFactory->createMiddleware());
```

### Mezzio

[](#mezzio)

```
use Mezzio\Application;

$app = new Application();
$app->pipe($middlewareFactory->createMiddleware());
```

### Laravel

[](#laravel)

```
use Illuminate\Support\ServiceProvider;

class GraphQLServiceProvider extends ServiceProvider
{
    public function boot()
    {
        $middleware = $this->app->make(GraphQLMiddlewareFactory::class)
            ->createMiddleware();

        $this->app['router']->middleware('graphql', $middleware);
    }
}
```

Request Preprocessing
---------------------

[](#request-preprocessing)

You can add authentication/authorization by implementing the `RequestPreprocessorInterface`:

```
use GraphQL\Middleware\RequestPreprocessorInterface;

class AuthPreprocessor implements RequestPreprocessorInterface
{
    public function process(ServerRequestInterface $request): ServerRequestInterface
    {
        $token = $request->getHeaderLine('Authorization');
        if (!$this->isValidToken($token)) {
            throw new UnauthorizedException('Invalid token');
        }

        return $request;
    }
}

// Add to middleware factory
$middlewareFactory = new GraphQLMiddlewareFactory(
    serverConfig: $serverConfig,
    responseFactory: $psr17Factory,
    streamFactory: $psr17Factory,
    requestPreprocessor: new AuthPreprocessor()
);
```

Development
-----------

[](#development)

### Code Quality

[](#code-quality)

The project uses PHP\_CodeSniffer for coding standards and PHPStan for static analysis.

To check coding standards:

```
composer cs-check
```

To automatically fix coding standards:

```
composer cs-fix
```

To run static analysis:

```
composer stan
```

To run all checks (coding standards, static analysis, and tests):

```
composer check
```

### Testing

[](#testing)

To run the test suite:

```
composer test
```

Examples
--------

[](#examples)

Check the `examples/` directory for complete working examples with different frameworks:

- `examples/slim/` - Slim 4 integration
- `examples/mezzio/` - Mezzio integration
- `examples/laravel/` - Laravel integration

License
-------

[](#license)

MIT License. See LICENSE file for details.

==========================

To use the middleware in Laminas Mezzio, configure the factories

in `config/autoload/dependencies.global.php`

```
return [
    'dependencies' => [
        'factories'  => [
            \GraphQL\Server\StandardServer::class => \Xaddax\GraphQL\Factory\StandardServerFactory::class,
            \GraphQL\Middleware\GraphQLMiddleware::class => \Xaddax\GraphQL\Factory\GraphQLMiddlewareFactory::class,
        ],
    ],
];
```

Add configuration in `config/autoload/graphql.global.php`

```
return [
    'graphQL' => [
        'middleware' => [
            'allowedHeaders' => [
                'application/graphql',
                'application/json',
            ],
        ],
        'schema' => \Path\To\Schema::class, // optional, defaults to webonyx Schema
        'schemaConfig' => [], // optional, if not configured expected in Schema class constructor
        'server' => \Path\To\Server::class, // not yet implemented, defaults to webonyx StandardServer
        'serverConfig' => [
            'context' => \GraphQL\Context\TokenContext::class
            'schema' => \Path\To\Your\Schema::class,
        ],
    ],
];
```

see the [WebOnyx Server Configuration Documentation](https://webonyx.github.io/graphql-php/executing-queries/#server-configuration-options) for the full options for the server config.

You'll need to set up the route. In `config/routes.php`

```
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
    $app->post('/graphql', \GraphQL\Middleware\GraphQLMiddleware::class, 'graphql');
};
```

Schema Definition Language
--------------------------

[](#schema-definition-language)

You can also use a Schema Definition Language as discussed [in the webonyx documentation](https://webonyx.github.io/graphql-php/schema-definition-language/).

In `config/autoload/graphql.global.php` change the schema in the `serverConfig` to `generatedSchema`

```
return [
    'graphQL' => [
        'serverConfig' => [
            'schema' => 'generatedSchema',
        ],
    ],
];
```

Then inside of the `graphQL` config add the `generatedSchema` configuration

```
return [
    'graphQL' => [
        'generatedSchema' => [
            'parserOptions' => [
                'experimentalFragmentVariables' => true, // to parse fragments
                'noLocation' => false, // default, set true for development
            ],
            'cache' => [
                'alwaysEnabled' => false, // default, set to true to cache when the system cache is not enabled
                'directoryChangeFilename' => 'directory-change-cache.php', // default
                'schemaCacheFilename' => 'schema-cache.php', // default
            ],
            'schemaDirectories' => [
                '/full/path/to/schema-directory-1',
                '/full/path/to/schema-directory-2',
            ],
        ],
    ],
];
```

See [the documentation](https://webonyx.github.io/graphql-php/class-reference/#graphqllanguageparser) for `parserOptions`

The cached data is stored in `data/cache/graphql`.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance56

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity89

Battle-tested with a long release history

 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 ~126 days

Recently: every ~21 days

Total

21

Last Release

294d ago

Major Versions

v0.9.1 → v1.0.02024-07-24

v1.2.0 → 15.0.02025-04-10

PHP version history (6 changes)v0.1PHP &gt;=7.1

v0.5.0PHP &gt;=7.1 || ^8.0

v0.7.0PHP ^8.0

v1.0.0PHP ^8.2

v1.1.1PHP ^8.3

v1.2.0PHP ^8.3 || ^8.4

### Community

Maintainers

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

---

Top Contributors

[![iampersistent](https://avatars.githubusercontent.com/u/16964?v=4)](https://github.com/iampersistent "iampersistent (50 commits)")

---

Tags

psr-7middlewaregraphqlpsr-15webonyx

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xaddax-webonyx-psr15-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/xaddax-webonyx-psr15-middleware/health.svg)](https://phpackages.com/packages/xaddax-webonyx-psr15-middleware)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)

PHPackages © 2026

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