PHPackages                             x-graphql/field-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. x-graphql/field-middleware

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

x-graphql/field-middleware
==========================

Adding custom logics before and after when resolving fields

0.2.0(2y ago)033.4k↓26.6%1MITPHPPHP &gt;=8.2

Since Mar 20Pushed 2y agoCompare

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

READMEChangelog (2)Dependencies (3)Versions (3)Used By (1)

Field Middleware
================

[](#field-middleware)

Adding custom logics before and after when resolving fields

[![unit tests](https://github.com/x-graphql/field-middleware/actions/workflows/unit_tests.yml/badge.svg)](https://github.com/x-graphql/field-middleware/actions/workflows/unit_tests.yml/badge.svg)[![codecov](https://camo.githubusercontent.com/410e1304f8f21d4191e29c7b8af90a5b7bf928bb816ef73dbc2697949bb551af/68747470733a2f2f636f6465636f762e696f2f67682f782d6772617068716c2f6669656c642d6d6964646c65776172652f67726170682f62616467652e7376673f746f6b656e3d6e744a5834515563566b)](https://codecov.io/gh/x-graphql/field-middleware)

Getting Started
---------------

[](#getting-started)

Install this package via [Composer](https://getcomposer.org)

```
composer require x-graphql/field-middleware
```

Usages
------

[](#usages)

Create your first middleware:

```
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Schema;
use XGraphQL\FieldMiddleware\MiddlewareInterface;

class MyMiddleware implements MiddlewareInterface {

    public function resolve(mixed $value, array $arguments, mixed $context, ResolveInfo $info, callable $next) : mixed {
        $firstName = $next($value, $arguments, $context, $info);

        return $firstName . ' Doe';
    }
}
```

Then let apply this middleware to schema:

```
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use XGraphQL\FieldMiddleware\FieldMiddleware;

$schema = new Schema([
  'query' => new ObjectType([
    'name' => 'Query',
    'fields' => [
      'name' => Type::string()
    ],
  ]),
]);

FieldMiddleware::apply($schema, [new MyMiddleware()]);

$result = GraphQL::executeQuery($schema, '{ name }', ['name' => 'John']);

var_dump($result->toArray());
```

Credits
-------

[](#credits)

Created by [Minh Vuong](https://github.com/vuongxuongminh)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

Total

2

Last Release

781d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8901d64a1059726b851dbdd91463ad1d3169f9dba6a2dcff11d05f97d9bccaea?d=identicon)[vuongxuongminh](/maintainers/vuongxuongminh)

---

Top Contributors

[![vuongxuongminh](https://avatars.githubusercontent.com/u/38932626?v=4)](https://github.com/vuongxuongminh "vuongxuongminh (12 commits)")

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/x-graphql-field-middleware/health.svg)

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

###  Alternatives

[league/event

Event package

1.6k141.6M184](/packages/league-event)[laragraph/utils

Utilities for using GraphQL with Laravel

2113.8M7](/packages/laragraph-utils)

PHPackages © 2026

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