0
0
GraphQLquery~10 mins

Apollo Federation concepts in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a federated service with a key directive.

GraphQL
type Product @key(fields: "[1]") {
  id: ID!
  name: String
}
Drag options to blanks, or click blank then click option'
Aname
Bid
Csku
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-unique field like 'name' as the key.
Omitting the @key directive entirely.
2fill in blank
medium

Complete the code to extend a type from another federated service.

GraphQL
extend type User @key(fields: "[1]") {
  id: ID! @external
  reviews: [Review]
}
Drag options to blanks, or click blank then click option'
Aid
Bprofile
Cusername
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-key field in the @key directive.
Not marking the key field as @external.
3fill in blank
hard

Fix the error in the code by completing the directive to specify the field used for reference resolution.

GraphQL
type Review @key(fields: "[1]") {
  id: ID!
  body: String
  author: User @provides(fields: "username")
}
Drag options to blanks, or click blank then click option'
AauthorId
Breviewer
CuserId
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent or incorrect field name in @key.
Confusing @provides with @key directive usage.
4fill in blank
hard

Fill both blanks to correctly define a federated entity with a reference resolver.

GraphQL
extend type Product @key(fields: "[1]") {
  id: ID! @external
  price: Int
  weight: Int
}

const resolvers = {
  Product: {
    __resolveReference(product) {
      return [2];
    }
  }
};
Drag options to blanks, or click blank then click option'
Aid
Bproduct.id
Cproduct
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Returning only a field like product.id instead of the full product.
Using a wrong field name in the @key directive.
5fill in blank
hard

Fill all three blanks to define a federated schema with a service and a query that fetches an entity by key.

GraphQL
type Query {
  productById(id: ID!): Product
}

type Product @key(fields: "[1]") {
  id: ID!
  name: String
  price: Int
}

const resolvers = {
  Query: {
    productById(_, args) {
      return [2];
    }
  },
  Product: {
    __resolveReference(reference) {
      return [3];
    }
  }
};
Drag options to blanks, or click blank then click option'
Aid
Bproducts.find(p => p.id === args.id)
Cproducts.find(p => p.id === reference.id)
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names in the @key directive or resolvers.
Returning incomplete objects in __resolveReference.