# Understanding Apollo Federation Type Extensions in the Ruby World

DevFeed: [Understanding Apollo Federation Type Extensions in the Ruby World](<https://devfeed.tech/articles/understanding-apollo-federation-type-extensions-in-the-ruby-world-20049.md>)

Original publisher: [Read original article](<https://technology.doximity.com/articles/understanding-apollo-federation-type-extensions-in-the-ruby-world>)

Author: Doximity

Published: 2022-09-09T09:11:00Z

Content type: tutorial

Language: en

Sources: [Doximity](<https://devfeed.tech/sources/doximity.md>)

Topics: [GraphQL](<https://devfeed.tech/topics/graphql.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [apollo](<https://devfeed.tech/tags/apollo.md>), [apollo-federation](<https://devfeed.tech/tags/apollo-federation.md>), [build](<https://devfeed.tech/tags/build.md>), [code](<https://devfeed.tech/tags/code.md>), [distributed](<https://devfeed.tech/tags/distributed.md>), [extension](<https://devfeed.tech/tags/extension.md>), [graph](<https://devfeed.tech/tags/graph.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [ruby](<https://devfeed.tech/tags/ruby.md>)

## AI overview

A tutorial on Apollo Federation type extensions in Ruby. It explains how entities are identified across subgraphs, why another subgraph may extend an entity, and how the query planner resolves fields supplied by the extending subgraph.

## Source excerpt

Type extensions in Apollo Federation are perhaps one of the most confusing concepts to translate into code. This article covers the importance of type extensions in a distributed graph as well as how to implement them properly using the Apollo Federation Ruby implementation (NOTE: code snippets below use Federation v1 and apollo-federation ~> 2.0) Covering the basics In Apollo Federation we have the concept of entities, which are nothing more than GraphQL types with special annotations to declare how to identify them across subgraphs uniquely. Think about them as primary keys in a database schema. Such entities may be referenced from other subgraphs, and in order for that to work you need a type extension. Why should I care about a type extension? The main selling point for Apollo Federation is the ability to build a distributed graph with the separation of concerns in mind. There are times, however, when an entity declared by one subgraph may need to be used by another subgraph. Imagine an orders subgraph that declares an Order type and a users subgraph that declares a User type. You may want your User entity to return a list of orders made by the logged-in user but you don't want any orders knowledge to leak into the users domain. The way to do that is via a User type extension performed by the orders subgraph. What does a type extension look like? Again, let's use users and orders subgraphs as an example here. The users subgraph declares a User entity that looks like this: # code below lives in the users subgraph class User < BaseObject key fields: :id field :id, ID, null: false field :username, String, null: false field :name, String, null: false end Because the type includes this special key annotation, Apollo Federation knowns 1) that field id represents its "primary key", and 2) that users is the authoritative subgraph for User. In order to define the field orders for the type User we declare a User type extension from the orders subgraph: # code below lives