<commit_before>---
title: Federation specification
description: For implementing federation in other languages
---

> This content is meant for developers adding federation support to alternative GraphQL servers, and for anyone curious about the inner workings of federation. It is not needed to use or understand federation when using Apollo Server.

To make a GraphQL service federation capable, it needs the following:

* Implementation of the federation schema specification
* Implementation of stub type generation for references
* Implementation of request resolving for entities.
* Support for fetching service capabilities

## Federation schema specification

Federated services will need to implement the following additions to the schema to allow the gateway to use the service for execution:

```graphql
scalar _Any
scalar _FieldSet

# a union of all types that use the @key directive
union _Entity

type _Service {
  sdl: String
}

extend type Query {
  _entities(representations: [_Any!]!): [_Entity]!
  _service: _Service!
}

directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITON
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT

# this is an optional directive discussed below
directive @extends on OBJECT<commit_msg>Fix directive spelling information (#2747)<commit_after>---
title: Federation specification
description: For implementing federation in other languages
---

> This content is meant for developers adding federation support to alternative GraphQL servers, and for anyone curious about the inner workings of federation. It is not needed to use or understand federation when using Apollo Server.

To make a GraphQL service federation capable, it needs the following:

* Implementation of the federation schema specification
* Implementation of stub type generation for references
* Implementation of request resolving for entities.
* Support for fetching service capabilities

## Federation schema specification

Federated services will need to implement the following additions to the schema to allow the gateway to use the service for execution:

```graphql
scalar _Any
scalar _FieldSet

# a union of all types that use the @key directive
union _Entity

type _Service {
  sdl: String
}

extend type Query {
  _entities(representations: [_Any!]!): [_Entity]!
  _service: _Service!
}

directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT

# this is an optional directive discussed below
directive @extends on OBJECT
{'fraction_non_alphanumeric': 0.05007418397626113, 'fraction_numerical': 0.001483679525222552, 'mean_word_length': 5.530266343825666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601159', 'n_tokens_mistral': 699, 'n_tokens_neox': 649, 'n_words': 335}