# Federation: Getting Started
Experimental: not enabled by default, not guaranteed to be stable.
Federation enables you to combine GraphQL services into a single unified data graph. Read more about the core concepts and motivation in the Apollo Federation docs (opens new window).
Lighthouse can act as a federation capable service as described in the Apollo Federation specification (opens new window) v2. It can not serve as a federation gateway (opens new window).
# Setup
Add the service provider to your config/app.php
:
'providers' => [
\Nuwave\Lighthouse\Federation\FederationServiceProvider::class,
],
# Publishing Your Schema
In order to generate a .graphql
schema file suitable for publishing, use the --federation
option of print-schema
.
php artisan lighthouse:print-schema --federation
# Apollo Federation v2
Support for Apollo Federation v2 is opt-in
and can be enabled by adding the following to your schema.
See the Apollo documentation on federated directives (opens new window) for the latest spec.
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: [
"@composeDirective"
"@extends"
"@external"
"@inaccessible"
"@interfaceObject"
"@key"
"@override"
"@provides"
"@requires"
"@shareable"
"@tag"
]
)
# Federated tracing
In order to use federated tracing, you need to enabled tracing
and set the driver to Nuwave\Lighthouse\Tracing\FederatedTracing\FederatedTracing::class
in your config/lighthouse.php
:
'tracing' => [
'driver' => Nuwave\Lighthouse\Tracing\FederatedTracing\FederatedTracing::class,
],
Note that federated tracing requires google/protobuf
to be installed (for better performance you can also install the protobuf
php extension).
# Unsupported features
Some features of the Apollo Federation specification are not supported by Lighthouse:
# Renaming directives
Renaming imported directives is not supported. You can only use the default names.
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: [{ name: "@key", as: "@uniqueKey" }, "@shareable"]
)
# Namespaced directives
Using directives from a namespace without an import is not supported. You should import the directive and use the default name.
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key"])
type Book @federation__shareable {
title: String!
}