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 an entity reference in GraphQL?
An entity reference is a way to uniquely identify an object across services in a federated GraphQL setup, allowing different services to share and resolve the same entity.
Click to reveal answer
beginner
How do you mark a type as an entity in GraphQL federation?
You add the @key directive to the type, specifying one or more fields that uniquely identify the entity.
Click to reveal answer
intermediate
What is the purpose of the _entities field in a federated GraphQL schema?
The _entities field allows querying multiple entities by their references, resolving them to their full data from the appropriate service.
Click to reveal answer
intermediate
Explain how entity references help in a microservices architecture using GraphQL.
Entity references let different microservices own parts of the data but still link and fetch complete entities by their unique keys, enabling a unified API.
Click to reveal answer
beginner
What directive is used to specify the fields that form the unique key for an entity?
The @key directive is used to specify the unique identifying fields of an entity in GraphQL federation.
Click to reveal answer
Which directive marks a GraphQL type as an entity for federation?
A@key
B@entity
C@reference
D@unique
✗ Incorrect
The @key directive marks a type as an entity by specifying its unique identifying fields.
What is the purpose of the _entities field in a federated GraphQL schema?
ATo query multiple entities by their references
BTo list all types in the schema
CTo define new types
DTo delete entities
✗ Incorrect
The _entities field allows querying multiple entities by their references to fetch full data.
In GraphQL federation, what does an entity reference usually contain?
AThe entire entity data
BThe unique key fields of the entity
COnly the entity's type name
DThe service URL
✗ Incorrect
An entity reference contains the unique key fields that identify the entity.
Why are entity references important in a microservices GraphQL architecture?
AThey encrypt data between services
BThey speed up database queries
CThey allow services to share and resolve the same entity data
DThey replace REST APIs
✗ Incorrect
Entity references enable different services to share and resolve the same entity data across the federated schema.
Which of the following is NOT true about entity references?
AThey rely on the @key directive
BThey are used to fetch full entity data
CThey uniquely identify an entity across services
DThey store the entire entity data locally
✗ Incorrect
Entity references do not store the entire entity data locally; they only contain unique identifiers.
Describe what an entity reference is and how it works in GraphQL federation.
Think about how different services share data about the same object.
You got /4 concepts.
Explain why entity references are useful in a microservices environment using GraphQL.
Consider how multiple teams manage parts of data but want a single API.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of entity references in GraphQL?
easy
A. To create mutations for updating data
B. To define scalar types like Int and String
C. To connect one type to another and fetch related data
D. To write raw SQL queries inside GraphQL
Solution
Step 1: Understand entity references
Entity references link one GraphQL type to another, allowing related data to be fetched together.
Step 2: Compare options
Only To connect one type to another and fetch related data describes connecting types and fetching related data, which is the purpose of entity references.
Final Answer:
To connect one type to another and fetch related data -> Option C
Quick Check:
Entity references = connect types [OK]
Hint: Entity references link types to get related info fast [OK]
Common Mistakes:
Confusing entity references with scalar type definitions
Thinking entity references are for mutations
Assuming entity references are raw SQL queries
2. Which of the following is the correct way to define an entity reference in a GraphQL schema?
easy
A. type Book { author: Boolean }
B. type Book { author: String }
C. type Book { author: Int }
D. type Book { author: Author }
Solution
Step 1: Identify entity reference syntax
Entity references use another type's name as the field type, e.g., author: Author.
Step 2: Check options
Only type Book { author: Author } uses a type name (Author) as a field type, correctly defining an entity reference.
Final Answer:
type Book { author: Author } -> Option D
Quick Check:
Entity reference = field with another type name [OK]
Hint: Use type names, not scalars, for entity references [OK]
Common Mistakes:
Using scalar types instead of type names for references
Confusing field names with types
Missing curly braces in type definitions
3. Given the schema:
type Author { id: ID! name: String! } type Book { id: ID! title: String! author: Author }
What will the query { book { title author { name } } } return if the book's title is "GraphQL Guide" and the author's name is "Alice"?
medium
A. {"book": {"title": "GraphQL Guide", "author": "Alice"}}
B. {"book": {"title": "GraphQL Guide", "author": {"name": "Alice"}}}
C. {"book": {"title": "GraphQL Guide", "author": null}}
D. SyntaxError
Solution
Step 1: Understand the query structure
The query requests the book's title and the nested author's name, matching the schema's entity reference.
Step 2: Predict the output
The response will include the book title and an object for author with the name field, as in {"book": {"title": "GraphQL Guide", "author": {"name": "Alice"}}}.
Final Answer:
{"book": {"title": "GraphQL Guide", "author": {"name": "Alice"}}} -> Option B