PHPackages                             toppynl/graphql-federation - 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. toppynl/graphql-federation

ActiveLibrary[API Development](/categories/api)

toppynl/graphql-federation
==========================

GraphQL Federation v2 subgraph support for webonyx/graphql-php

v0.2.0(2mo ago)061MITPHP &gt;=8.1

Since May 1Compare

[ Source](https://github.com/toppynl/graphql-federation)[ Packagist](https://packagist.org/packages/toppynl/graphql-federation)[ RSS](/packages/toppynl-graphql-federation/feed)WikiDiscussions Synced 3w ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

toppynl/graphql-federation
==========================

[](#toppynlgraphql-federation)

GraphQL Federation v2 subgraph support for webonyx/graphql-php.

[![CI](https://github.com/toppynl/graphql-federation/actions/workflows/ci.yml/badge.svg)](https://github.com/toppynl/graphql-federation/actions/workflows/ci.yml)

What it does
------------

[](#what-it-does)

This library decorates any `webonyx/graphql-php` `Schema` with the full set of Federation v2 plumbing — `_service`, `_entities`, the `_Entity` union, all 11 Federation v2 directives, and the correct `extend schema @link(...)` SDL header — so that a PHP service can join a WunderGraph Cosmo (or Apollo Router) federation graph as a spec-compliant subgraph. It is framework-agnostic: no Symfony, Laravel, or any other framework is required.

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

[](#requirements)

- PHP 8.1+
- `webonyx/graphql-php` ^15.0

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

[](#installation)

```
composer require toppynl/graphql-federation
```

Quick start
-----------

[](#quick-start)

```
use Toppynl\GraphQLFederation\FederatedSchemaBuilder;

$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withReferenceResolver('Product', 'id', function (array $rep): array {
        return ProductRepository::findById($rep['id']);
    })
    ->build();

// $fedSchema->schema is a standard webonyx Schema — pass it to GraphQL::executeQuery() as normal
$result = GraphQL::executeQuery($fedSchema->schema, $query, rootValue: null, contextValue: $context);
```

`FederatedSchemaBuilder::from()` accepts an existing `webonyx/graphql-php` `Schema`. `build()` returns a `FederatedSchema` value object whose `->schema` property is a standard `Schema` ready for execution.

Multiple keys
-------------

[](#multiple-keys)

Pass an array of field names to register multiple `@key` directives on a single entity:

```
$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withReferenceResolver('Product', ['id', 'sku'], function (array $rep): array {
        return isset($rep['sku'])
            ? ProductRepository::findBySku($rep['sku'])
            : ProductRepository::findById($rep['id']);
    })
    ->build();
```

Non-resolvable stubs
--------------------

[](#non-resolvable-stubs)

Use `withEntityKey()` when this subgraph contributes fields to an entity that is owned (and resolved) by another subgraph:

```
$fedSchema = FederatedSchemaBuilder::from($schema)
    ->withEntityKey('Order', 'id', resolvable: false)
    ->build();
```

This emits `@key(fields: "id", resolvable: false)` in the SDL without requiring a local reference resolver.

What gets injected automatically
--------------------------------

[](#what-gets-injected-automatically)

- `_service { sdl }` query field
- `_entities(representations: [_Any!]!)` query field
- `_Entity` union (all resolvable entity types)
- `_Any` scalar
- `FieldSet` scalar
- `_Service` type
- All 11 Federation v2 directive definitions (see below)
- `extend schema @link(url: "https://specs.apollo.dev/federation/v2.x", ...)` header in SDL

Federation v2 directives supported
----------------------------------

[](#federation-v2-directives-supported)

`@key`, `@external`, `@requires`, `@provides`, `@shareable`, `@inaccessible`, `@override`, `@tag`, `@composeDirective`, `@interfaceObject`, `@link`

API Platform v3 / Symfony
-------------------------

[](#api-platform-v3--symfony)

For Symfony projects using API Platform v3, see [`toppynl/api-platform-federation`](https://github.com/toppynl/api-platform-federation) for a bundle that wires this library into the API Platform stack automatically.

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance83

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

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

Total

2

Last Release

84d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/239d9adcbadfaac1e3ce531c1b81d87e378c3395b9c10bef5bfddb1637c07c9d?d=identicon)[Swahjak](/maintainers/Swahjak)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/toppynl-graphql-federation/health.svg)

```
[![Health](https://phpackages.com/badges/toppynl-graphql-federation/health.svg)](https://phpackages.com/packages/toppynl-graphql-federation)
```

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k11.8M118](/packages/nuwave-lighthouse)[thecodingmachine/graphqlite

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

5733.3M48](/packages/thecodingmachine-graphqlite)[overblog/graphql-bundle

This bundle provides tools to build a GraphQL server in your Symfony App.

8028.4M39](/packages/overblog-graphql-bundle)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[aimeos/ai-admin-graphql

Aimeos Admin GraphQL API extension

1.0k110.7k7](/packages/aimeos-ai-admin-graphql)[pimcore/data-hub

Pimcore Datahub

1361.4M12](/packages/pimcore-data-hub)

PHPackages © 2026

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