# GraphQL Federation

> [Though there is only one graph, the implementation of that graph should be **federated** across multiple teams.](https://principledgraphql.com/integrity#2-federated-implementation)

GraphQL federation is a process by which a single GraphQL server can take a microservice-like approach to splitting up
responsibility of resolving a GraphQL request to multiple GraphQL servers.

For more information on how Federation is implemented at The Orchard, please see the
[Federation section of the Architecture overview](../orchard/architecture.md#federation).

## Managed Federation

The Orchard uses the [Apollo Managed Federation
](https://www.apollographql.com/docs/federation/managed-federation/overview/) service for its Federated Graph. This
means that there is a centralized description of the entire graph on the Apollo Studio, and Apollo tracks analytics of
the clients of the graph. This lets us [validate](../orchard/schema/validation.md) that GraphQL schema changes can be
merged without causing issues for clients.

## Type Sharing Between Services

There are two main ways to share types between multiple GraphQL implementing services, Value Types and Entities:

### Value Types

This is when multiple services have the same type defined in them. These can be any GraphQL type. The types must be
defined equivalently in every service to be a valid Shared Value Type. You can check the [Apollo Documentation on Value
Types](https://www.apollographql.com/docs/federation/value-types/) for more information.

Examples within The Orchard's graph include:
 - LabelIdInput - An Input Type shared between many services
 - ProfileType - An Enum Type shared between many services
 - LabelId - An Object Type shared between many services

### Entities

This is where the power of GraphQL Federation comes in to play. Entities allow us to defined the base of a type in
one service, and then use it from other services - either by using it as the result for a field, or by extending it and
adding fields. Check the [Apollo Documentation on Entities](https://www.apollographql.com/docs/federation/entities/)
for more details.

### I Think I Need A New Service. What Should I Do

Firstly, check our list of services. The data you're after may fit into one or more of them already. 
Still here?  Duplicate and complete our [Compliance Form](https://docs.google.com/document/d/1M5OaDMRPe3K7rn_kztFo_O5uEq-GW8eocYrY1pDpeVo).
Then add it to the agenda of [the graph refinement weekly meeting](https://meet.google.com/cex-ustc-jxm)
