PHPackages                             stefanorg/graphql-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. [API Development](/categories/api)
4. /
5. stefanorg/graphql-middleware

ActiveLibrary[API Development](/categories/api)

stefanorg/graphql-middleware
============================

GraphQL Middleware for container interop

131083PHPCI failing

Since Jun 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/stefanorg/graphql-middleware)[ Packagist](https://packagist.org/packages/stefanorg/graphql-middleware)[ RSS](/packages/stefanorg-graphql-middleware/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

GraphQL Psr7 Middleware
=======================

[](#graphql-psr7-middleware)

This is a graphql middleware implementation, based on [Youshido/GraphQL](https://github.com/Youshido/GraphQL) graphql pure php implementation.

Using middleware
----------------

[](#using-middleware)

```
use GraphQLMiddleware\Execution\Processor;
use App\GraphQL\MySchema;
use GraphQLMiddleware\GraphQLMiddleware;

...
...

//instantiate the graphql schema
$schema = new MySchema();

//get your container implementing container-interop
$container = get_your_container;

//init processor
$processor = new Processor($container, $schema);
$graphqlMiddleware = new GraphQLMiddleware($processor)

$app->pipe("/graphql", $graphqlMiddleware)

```

If your container support factories you can use those provided.

As an example if you use zend `expressive` you can take advantage of the configuration package provided using the [`configuration manager`](https://docs.zendframework.com/zend-expressive/cookbook/modular-layout/)

```
$configManager = new ConfigManager([
    GraphQLMiddleware\ModuleConfig::class,
    new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
]);

```

Interacting with the graphql middleware
---------------------------------------

[](#interacting-with-the-graphql-middleware)

For every request made to `/graphql` URI or containing `Content-Type: application/graphql` header. At moment only the `GET` and `POST` method are supported.

Factories
---------

[](#factories)

- `Schema\SchemaFactory` Factory to instantiate the schema object from an array, class or from the container
- `Execution\ProcessorFactory` Factory to instantiate the graphql processor, with the `ContainerAwareInterface` ability to let you write your resolver class with the ability to pull service directly from the container.
- `Resolver\ContainerAwareResoverFactory` Factory to automatically inject the container inside you resolver class

Container aware fields
----------------------

[](#container-aware-fields)

You can write your schema making the fields aware of the container, this way you can retrive a container reference directly from the field and pull from the container any deps you need to `resolve` the field logic.

Suppose we have a `TodoField` and we are implementing a mutation `AddTodoField`to store that todo in our backend

```
