0
0
GraphQLquery~20 mins

GraphQL vs REST comparison - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL vs REST Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Key difference in data fetching between GraphQL and REST
Which statement best describes how GraphQL differs from REST in fetching data?
ABoth GraphQL and REST require multiple endpoints to fetch different data types.
BREST allows clients to request exactly the data they need in a single query, while GraphQL requires multiple endpoints.
CGraphQL allows clients to request exactly the data they need in a single query, while REST often requires multiple endpoints.
DGraphQL does not support querying data, only mutations, unlike REST.
Attempts:
2 left
💡 Hint
Think about how many requests are needed to get related data in each approach.
🧠 Conceptual
intermediate
2:00remaining
Handling versioning in GraphQL vs REST
How is API versioning typically handled differently in GraphQL compared to REST?
AREST uses explicit version numbers in the URL, while GraphQL encourages evolving the schema without versioning.
BGraphQL uses explicit version numbers in the URL, while REST evolves the schema without versions.
CBoth GraphQL and REST require version numbers in the URL for every change.
DNeither GraphQL nor REST support versioning.
Attempts:
2 left
💡 Hint
Consider how clients adapt to changes in each API style.
query_result
advanced
2:00remaining
GraphQL query result shape
Given this GraphQL query:
{ user(id: "1") { name, posts { title } } }

What is the expected shape of the JSON response?
A{"data": {"name": "Alice", "posts": [{"title": "Post 1"}, {"title": "Post 2"}]}}
B{"data": {"user": {"name": "Alice", "posts": [{"title": "Post 1"}, {"title": "Post 2"}]}}}
C{"user": {"name": "Alice", "posts": [{"title": "Post 1"}, {"title": "Post 2"}]}}
D{"data": {"user": {"name": "Alice"}}}
Attempts:
2 left
💡 Hint
GraphQL responses always wrap data inside a 'data' key.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL query
Which option contains a syntax error in the GraphQL query?
GraphQL
query { user(id: "1") { name posts { title } } }
Aquery { user(id: "1") { name, posts { title } } }
B} } } eltit { stsop ,eman { )"1" :di(resu { yreuq
Cquery { user(id: "1") { name posts { title } } }
D} } } eltit { stsop eman { )"1" :di(resu { yreuq
Attempts:
2 left
💡 Hint
Look for missing commas between fields.
optimization
expert
3:00remaining
Optimizing REST API calls compared to GraphQL
You have a REST API with endpoints /users and /posts. To get a user's name and their posts' titles, you must call both endpoints. How does GraphQL optimize this scenario?
AGraphQL duplicates data in each query to avoid multiple calls.
BGraphQL requires separate queries for user and posts, increasing network calls.
CGraphQL caches REST endpoints internally, so no optimization is needed.
DGraphQL allows fetching user name and posts titles in a single query, reducing network calls.
Attempts:
2 left
💡 Hint
Think about how many requests are needed in REST vs GraphQL for related data.