PHPackages                             phps-cans/psr7-middleware-graphql - 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. phps-cans/psr7-middleware-graphql

ActiveLibrary[API Development](/categories/api)

phps-cans/psr7-middleware-graphql
=================================

This package contains a http-interop middleware implementation to handle graphql request

v0.2.0(7y ago)1528.7k7[2 issues](https://github.com/phps-cans/psr7-middleware-graphql/issues)MITPHPPHP &gt;=7.1

Since Sep 4Pushed 7y ago5 watchersCompare

[ Source](https://github.com/phps-cans/psr7-middleware-graphql)[ Packagist](https://packagist.org/packages/phps-cans/psr7-middleware-graphql)[ Docs](https://github.com/phps-cans/psr7-middleware-graphql)[ RSS](/packages/phps-cans-psr7-middleware-graphql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (5)Used By (0)

[PSR 15](https://github.com/http-interop/http-middleware) compliant middleware to handle graphql
================================================================================================

[](#psr-15-compliant-middleware-to-handle-graphql)

This package is currently under development. This package use the [official package of graphql's integration](https://github.com/webonyx/graphql-php) to handle Graphql Request.

This middleware is executed if the `content-type` of the request is `application/graphql` or if the configured URL is reached (by default it is /graphql) This middleware use the [`StandardServer`](http://webonyx.github.io/graphql-php/executing-queries/#using-server) to handle request. It is free to you to create the schema and the server. This middleware expect that JSON has already been decoded (by example with [`Psr7Middlewares\Middleware\Payload`](https://github.com/oscarotero/psr7-middlewares/blob/master/src/Middleware/Payload.php))

Easy use:
---------

[](#easy-use)

To be able to use this package easily we recommend you to use:

- [ServiceProvider](https://github.com/container-interop/service-provider)
- [stratigility-harmony](https://github.com/thecodingmachine/stratigility-harmony)
- [Middleware List](https://github.com/thecodingmachine/middleware-list-universal-module)
- [Universal payload](https://github.com/phps-cans/psr7-middlewares-payload-universal-module)
- [Graphql Tools](https://github.com/phps-cans/harmony-graphql-tool)

This way, the zend-stratigility server is ready to use, JSON body are automatically parsed, middleware are piped, the StandardServer and Schema are automatically created.

Using ServiceProvider
---------------------

[](#using-serviceprovider)

We recommend to use [stratigility-harmony](https://github.com/thecodingmachine/stratigility-harmony) to automatically configure your stratigility's server.

This package provide a [ServiceProvider](https://github.com/container-interop/service-provider) by default (src/ServiceProvider/DefaultServiceProvider.php). It expect the `StandardServer` to be registered in the container under the name `GraphQL\Server\StandardServer`. If you use [Middleware List](https://github.com/thecodingmachine/middleware-list-universal-module), it update the queue using the constant `MiddlewareOrder::ROUTER_EARLY`.

using any http-interop compilant Middleware pipe
------------------------------------------------

[](#using-any-http-interop-compilant-middleware-pipe)

This example is based on [zend-stratigility](https://github.com/zendframework/zend-stratigility) middleware pipe:

```
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
use PsCs\Psr7\Middleware\Graphql\WebonyxGraphqlMiddleware;
use GraphQL\Server\StandardServer;
use GraphQL\Type\Schema;
use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\Type;
use Psr7Middlewares\Middleware\Payload;
use Zend\Stratigility\Middleware\NotFoundHandler;
use Zend\Diactoros\Response;
use Zend\Stratigility\NoopFinalHandler;

// Create fields
$field = FieldDefinition::create([
            "name" => "billPerYear",
            "type" => Type::string(),
            'args'    => [
                'id' => Type::nonNull(Type::id())
            ],
            "resolve" => function($rootValue, $args) {
                return "success on ".$args["id"];
            }

        ]);
//create the schema
$schema = new Schema([
            "query" => new ObjectType([
                'name'   => 'Query',
                'fields' => [
                    $field
                ]
            ])
        ]);
$defaultUri = '/graphql';
$debug = false;
// create the standardServer of webonyx
$standardServer = new StandardServer(["schema" => $schema]);
// let instantiate our php server
$pipe = new MiddlewarePipe();
// Register the middleware which decode JSON body
$pipe->pipe(new \Psr7Middlewares\Middleware\Payload());
/* Instantiate and register our middleware
Params are:
- $standardServer : webonyx's graphql server: [`StandardServer`](http://webonyx.github.io/graphql-php/executing-queries/#using-server)
- $defaultUri = This middleware will be executed for each request matching the default URI and for each request having the content-type set to "application/graphql"
- $debug = IF false, minimal error will be reported (as specified in [handling error](http://webonyx.github.io/graphql-php/error-handling/). The value of $debug must be the same as specified in [`$debug`](http://webonyx.github.io/graphql-php/error-handling/#debugging-tools)

**/
$pipe->pipe(new WebonyxGraphqlMiddleware($standardServer, $defaultUri, $debug));
// Add the notFoundHandler
$pipe->pipe(new NotFoundHandler(new Response()));
// Instantiate our server
$server = Server::createServer($pipe, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// let tell to the server that we are ready
$server->listen(new NoopFinalHandler());
```

Feel free to report any issues.

TODO
----

[](#todo)

- Write unit testing
- Allow formmating errors

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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 ~153 days

Total

4

Last Release

2712d ago

PHP version history (2 changes)0.1.x-devPHP &gt;=5.5.0

0.2.x-devPHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![Ngob](https://avatars.githubusercontent.com/u/2749238?v=4)](https://github.com/Ngob "Ngob (7 commits)")[![moufmouf](https://avatars.githubusercontent.com/u/1290952?v=4)](https://github.com/moufmouf "moufmouf (1 commits)")

---

Tags

middlewaregraphqlpsr7psr15middlewares

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phps-cans-psr7-middleware-graphql/health.svg)

```
[![Health](https://phpackages.com/badges/phps-cans-psr7-middleware-graphql/health.svg)](https://phpackages.com/packages/phps-cans-psr7-middleware-graphql)
```

###  Alternatives

[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[league/route

Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

6633.1M116](/packages/league-route)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)[yiisoft/yii-middleware

Yii Middleware

21151.3k1](/packages/yiisoft-yii-middleware)[mezzio/mezzio-authentication-oauth2

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

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

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

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