0
0
GraphQLquery~20 mins

Why GraphQL exists - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why was GraphQL created?

GraphQL was introduced to solve some problems with traditional REST APIs. Which of the following best explains the main reason GraphQL exists?

ATo replace all databases with a new type of database technology.
BTo allow clients to request exactly the data they need in a single query, reducing over-fetching and under-fetching.
CTo make APIs slower but more secure by adding extra layers of encryption.
DTo force clients to always receive all data fields regardless of their needs.
Attempts:
2 left
💡 Hint

Think about how REST APIs sometimes send too much or too little data.

🧠 Conceptual
intermediate
2:00remaining
What problem does GraphQL solve compared to REST?

Which problem is GraphQL designed to solve that is common in REST APIs?

AClients often need to make multiple requests to different endpoints to get all required data.
BREST APIs cannot handle JSON data format.
CREST APIs always return data in XML format.
DREST APIs do not support authentication.
Attempts:
2 left
💡 Hint

Think about how many times a client might call a REST API to get related data.

query_result
advanced
2:00remaining
GraphQL query result shape

Given this GraphQL query requesting a user's name and their posts' titles, what will the result look like?

{ user(id: "1") { name posts { title } } }
A{"data": {"user": {"name": "Alice", "posts": [{"title": "Hello World"}, {"title": "GraphQL Rocks"}]}}}
B{"data": {"user": {"name": "Alice"}}}
C{"data": {"user": {"posts": [{"title": "Hello World"}]}}}
D{"error": "Field 'posts' not found"}
Attempts:
2 left
💡 Hint

The query asks for both name and posts with titles.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this GraphQL query

Which option contains a syntax error in this GraphQL query?

{ user(id: "1") { name posts { title } } }
A{ user(id: "1") { name, posts { title } } }
B{ user(id: 1) { name posts { title } } }
C{ user(id: "1") { name posts { title } }
D{ user(id: "1") { name posts { title } } }
Attempts:
2 left
💡 Hint

Check for missing brackets or commas.

optimization
expert
3:00remaining
Optimizing GraphQL queries to reduce data transfer

You have a GraphQL query fetching user details and their posts with comments. Which option best reduces data transfer by requesting only necessary fields?

{ user(id: "1") { id name posts { id title comments { id content } } } }
A{ user(id: "1") { id name posts { id title comments { id content author } } } }
B{ user(id: "1") { id name posts { id title comments { id content } } } }
C{ user(id: "1") { name posts { comments { content } } } }
D{ user(id: "1") { id name posts { title comments { content } } } }
Attempts:
2 left
💡 Hint

Only request fields you need to reduce data size.