0
0
GraphQLquery~20 mins

Apollo Federation concepts in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Apollo Federation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of Apollo Federation?
Apollo Federation allows multiple GraphQL services to work together as one. What is its main goal?
ATo combine multiple GraphQL services into a single graph for clients to query seamlessly
BTo convert SQL databases into GraphQL schemas
CTo cache GraphQL queries on the client side automatically
DTo replace REST APIs with a single GraphQL service
Attempts:
2 left
💡 Hint
Think about how multiple teams can build parts of a graph independently.
query_result
intermediate
2:00remaining
What is the output of this federated query?
Given two services: Product service with type Product { id, name } and Review service extending Product with { reviews }, what is the result of querying { product(id: "1") { id name reviews { body } } }?
GraphQL
query {
  product(id: "1") {
    id
    name
    reviews {
      body
    }
  }
}
A{ "data": { "product": { "id": "1", "name": null, "reviews": [] } } }
B{ "data": { "product": { "id": "1", "name": "Table", "reviews": [{ "body": "Great!" }] } } }
C{ "errors": [{ "message": "Field 'reviews' not found on type 'Product'" }] }
D{ "data": { "product": null } }
Attempts:
2 left
💡 Hint
Remember that Review service extends Product to add reviews.
📝 Syntax
advanced
2:00remaining
Which SDL snippet correctly defines an entity in Apollo Federation?
Choose the correct way to define a Product entity with a key field 'id' in Apollo Federation SDL.
GraphQL
type Product {
  id: ID!
  name: String
}
A
type Product @key(fields: "id") {
  id: ID!
  name: String
}
B
extend type Product @key(fields: "id") {
  id: ID! @external
  name: String
}
C
type Product @entity(fields: "id") {
  id: ID!
  name: String
}
D
type Product @key(id) {
  id: ID!
  name: String
}
Attempts:
2 left
💡 Hint
The @key directive marks the primary key field for the entity.
optimization
advanced
2:00remaining
How does Apollo Gateway optimize resolving entities across services?
Apollo Gateway receives a query that requires data from multiple services. How does it optimize fetching entities?
AIt caches all data indefinitely to avoid any network calls
BIt sends separate requests for each field to each service
CIt batches entity requests by keys to minimize network calls to subgraphs
DIt merges all schemas into one and queries only one service
Attempts:
2 left
💡 Hint
Think about how to reduce repeated calls for the same entity.
🔧 Debug
expert
3:00remaining
Why does this federated query fail with an error?
Given two services: User service defines type User @key(fields: "id") { id: ID! name: String }, and Order service extends User with extend type User @key(fields: "id") { id: ID! orders: [Order] }, a query requests user { id name orders { id } }. The error says: "Cannot query field 'orders' on type 'User'". What is the cause?
AThe User service must define the 'orders' field, not the Order service
BThe query is missing the @external directive on the 'id' field in the Order service
CThe 'orders' field must be marked as @requires(fields: "id") in the Order service
DThe User type in the gateway schema does not include the 'orders' field because the Order service did not properly extend the User entity
Attempts:
2 left
💡 Hint
Check how the User type is extended and if the gateway schema includes the extension.