Challenge - 5 Problems
REST vs GraphQL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Understanding REST API request methods
Which HTTP method is typically used in REST APIs to update an entire resource?
Attempts:
2 left
💡 Hint
Think about which method replaces the whole resource.
✗ Incorrect
In REST, PUT is used to update or replace an entire resource. POST is usually for creating, GET for reading, and DELETE for removing.
❓ component_behavior
intermediate2:00remaining
GraphQL query response shape
Given a GraphQL query requesting only the
name and age fields of a user, what will the response JSON look like?Express
query { user(id: "1") { name age } }Attempts:
2 left
💡 Hint
GraphQL responses always wrap data inside a 'data' key.
✗ Incorrect
GraphQL responses wrap the requested data inside a data object. Only the requested fields appear. Here, name and age are included, but not id.
📝 Syntax
advanced2:00remaining
Express route for REST vs GraphQL
Which Express route setup correctly handles a GraphQL POST request at '/graphql'?
Express
const express = require('express'); const app = express(); // Which option is correct?
Attempts:
2 left
💡 Hint
GraphQL queries and mutations are usually sent via POST requests.
✗ Incorrect
GraphQL servers typically accept POST requests at a single endpoint, often '/graphql'. Using app.post matches this pattern.
❓ state_output
advanced1:30remaining
REST API response status codes
What HTTP status code should a REST API return after successfully deleting a resource?
Attempts:
2 left
💡 Hint
The response usually has no body after deletion.
✗ Incorrect
After a successful deletion, REST APIs commonly return 204 No Content to indicate success without a response body.
🔧 Debug
expert2:30remaining
Debugging GraphQL query error in Express
An Express server with GraphQL returns an error:
Cannot read property 'data' of undefined. Which code snippet is the likely cause?Express
app.post('/graphql', async (req, res) => { const result = await graphql(schema, req.body.query); res.json(result.data); });
Attempts:
2 left
💡 Hint
Check if the promise resolves correctly and if the result is defined before accessing properties.
✗ Incorrect
The error occurs because result might be undefined if the promise rejects or the call fails. The code should handle errors and check if result exists before accessing result.data.