Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is Apollo Federation in GraphQL?
Apollo Federation is a way to combine multiple GraphQL services into one unified graph, allowing teams to build and maintain parts of the graph independently.
Click to reveal answer
beginner
What is a @key directive in Apollo Federation?
The @key directive marks a field or set of fields as the unique identifier for an entity in a subgraph, so it can be referenced and resolved across services.
Click to reveal answer
intermediate
Explain the role of the @extends directive in Apollo Federation.
The @extends directive is used to indicate that a type or field is extending an entity defined in another subgraph, allowing services to add fields to shared types.
Click to reveal answer
intermediate
What does the @external directive do in Apollo Federation?
The @external directive marks a field as owned by another subgraph, so the current subgraph can reference it but does not provide its value.
Click to reveal answer
beginner
How does Apollo Gateway work in Apollo Federation?
Apollo Gateway acts as a single entry point that composes the subgraphs' schemas into one federated schema and routes incoming queries to the appropriate subgraphs.
Click to reveal answer
What is the purpose of the @key directive in Apollo Federation?
ATo define query resolvers
BTo extend types from other subgraphs
CTo mark fields as owned externally
DTo mark fields as unique identifiers for entities
✗ Incorrect
The @key directive identifies the unique fields that represent an entity across subgraphs.
Which component composes multiple subgraphs into a single schema in Apollo Federation?
AApollo Server
BGraphQL Client
CApollo Gateway
DApollo Studio
✗ Incorrect
Apollo Gateway combines subgraphs into one federated schema and routes queries.
What does the @external directive indicate?
AField is owned by another subgraph
BField is a unique key
CField is deprecated
DField is a query root
✗ Incorrect
The @external directive marks fields that belong to other subgraphs.
How do subgraphs share and extend types in Apollo Federation?
AUsing <code>@extends</code> directive
BUsing <code>@key</code> directive
CUsing <code>@external</code> directive
DUsing <code>@deprecated</code> directive
✗ Incorrect
The @extends directive allows subgraphs to add fields to types defined elsewhere.
What is the main benefit of Apollo Federation?
ACaches all queries on the client
BEnables multiple teams to build parts of a graph independently
CAutomatically generates database schemas
DReplaces REST APIs completely
✗ Incorrect
Apollo Federation allows independent teams to develop and deploy parts of a unified graph.
Describe how Apollo Federation allows multiple GraphQL services to work together as one.
Think about how different teams can build parts and how they connect.
You got /4 concepts.
Explain the roles of the @key, @extends, and @external directives in Apollo Federation.
Focus on how these directives help share and extend types.
You got /3 concepts.
Practice
(1/5)
1. What is the primary purpose of Apollo Federation in GraphQL?
easy
A. To replace REST APIs with GraphQL
B. To create a new database schema
C. To combine multiple GraphQL services into a single API
D. To optimize SQL queries automatically
Solution
Step 1: Understand Apollo Federation's role
Apollo Federation is designed to combine multiple GraphQL services into one unified API.
Step 2: Compare options
Options B, C, and D describe unrelated tasks. Only To combine multiple GraphQL services into a single API correctly describes Apollo Federation's purpose.
Final Answer:
To combine multiple GraphQL services into a single API -> Option C
Quick Check:
Apollo Federation = combine services [OK]
Hint: Federation = combining services into one API [OK]
Common Mistakes:
Confusing Federation with database schema design
Thinking Federation replaces REST APIs directly
Assuming Federation optimizes SQL queries
2. Which of the following is the correct syntax to mark a unique identifier for an entity in Apollo Federation?
easy
A. type User @unique(fields: "id") { id: ID! name: String }
B. type User @key(fields: "id") { id: ID! name: String }
C. type User @id(fields: "id") { id: ID! name: String }
D. type User @primary(fields: "id") { id: ID! name: String }
Solution
Step 1: Recall the directive for unique identifiers
In Apollo Federation, the @key directive marks the unique identifier fields for an entity.
Step 2: Check syntax correctness
type User @key(fields: "id") { id: ID! name: String } uses @key(fields: "id"), which is the correct syntax. Other options use incorrect directives.
Final Answer:
type User @key(fields: "id") { id: ID! name: String } -> Option B
Quick Check:
@key directive = unique ID marker [OK]
Hint: Use @key to mark unique entity IDs [OK]
Common Mistakes:
Using @unique or @id instead of @key
Missing quotes around field names
Confusing @key with database primary key syntax
3. Given the following schema in a federated service:
extend type Product @key(fields: "upc") { upc: String @external price: Int }
What does the extend type keyword do here?
medium
A. Adds the price field to an existing Product type from another service
B. Removes the upc field from Product type
C. Defines a new Product type with fields upc and price
D. Creates a local copy of Product type without federation
Solution
Step 1: Understand 'extend type' in Apollo Federation
The extend type keyword adds fields to a type defined in another service.
Step 2: Analyze the example
The Product type is extended to add the price field, while upc is marked as external, meaning it comes from the original service.
Final Answer:
Adds the price field to an existing Product type from another service -> Option A
Quick Check:
extend type = add fields to existing type [OK]
Hint: extend type adds fields to existing types [OK]
Common Mistakes:
Thinking extend type creates a new type
Confusing @external with local fields
Assuming extend type removes fields
4. Identify the error in this federated schema snippet:
type Review @key(fields: "id") { id: ID! body: String author: User }
Assuming User is defined in another service, what is missing?
medium
A. The User type should be imported explicitly
B. The author field should be marked with @external
C. The author field should be marked with @provides or @requires
D. The Review type should use extend keyword
Solution
Step 1: Understand referencing external entities
In Apollo Federation, to reference an entity type like User from another service, the schema must explicitly extend that type with its @key directive: extend type User @key(fields: "id") { id: ID! }.
Step 2: Analyze the snippet
The Review type references User via author: User but lacks the required extend declaration for User, which is necessary for the gateway to know this service can resolve User.
Final Answer:
The User type should be imported explicitly -> Option A
Quick Check:
Reference entities -> extend type @key [OK]
Hint: Extend referenced entities with @key [OK]
Common Mistakes:
Marking author field with @provides or @requires
Marking author field as @external
Using extend keyword for Review type
5. You have two services: Accounts defining type User @key(fields: "id") { id: ID! name: String } and Reviews extending User with extend type User @key(fields: "id") { id: ID! reviews: [Review] }. How does Apollo Federation resolve the User entity across these services?
hard
A. It requires manual merging of User data in the gateway
B. It duplicates User types separately in each service
C. It ignores the extend type and uses only the Accounts User type
D. It merges User types by matching the @key field 'id' across services
Solution
Step 1: Understand @key usage in federation
The @key directive identifies the unique field used to match entities across services.
Step 2: Analyze entity resolution
Apollo Federation merges types with the same @key field by matching their unique identifiers, combining fields from both services.
Final Answer:
It merges User types by matching the @key field 'id' across services -> Option D