0
0
Expressframework~20 mins

REST vs GraphQL awareness in Express - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
REST vs GraphQL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding REST API request methods
Which HTTP method is typically used in REST APIs to update an entire resource?
APUT
BPOST
CGET
DDELETE
Attempts:
2 left
💡 Hint
Think about which method replaces the whole resource.
component_behavior
intermediate
2: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 } }
A{"data": {"user": {"name": "Alice"}}}
B{"user": {"name": "Alice", "age": 30}}
C{"data": {"user": {"id": "1", "name": "Alice", "age": 30}}}
D{"data": {"user": {"name": "Alice", "age": 30}}}
Attempts:
2 left
💡 Hint
GraphQL responses always wrap data inside a 'data' key.
📝 Syntax
advanced
2: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?
Aapp.post('/graphql', (req, res) => { res.send('GraphQL endpoint'); });
Bapp.get('/graphql', (req, res) => { res.send('GraphQL endpoint'); });
Capp.delete('/graphql', (req, res) => { res.send('GraphQL endpoint'); });
Dapp.put('/graphql', (req, res) => { res.send('GraphQL endpoint'); });
Attempts:
2 left
💡 Hint
GraphQL queries and mutations are usually sent via POST requests.
state_output
advanced
1:30remaining
REST API response status codes
What HTTP status code should a REST API return after successfully deleting a resource?
A200 OK
B201 Created
C204 No Content
D404 Not Found
Attempts:
2 left
💡 Hint
The response usually has no body after deletion.
🔧 Debug
expert
2: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);
});
AThe 'graphql' function returns a promise resolving to an object with 'data' property, so this code is correct.
BThe 'graphql' function returns a promise resolving to an object with 'data' and 'errors', but the code should check if 'result' is defined before accessing 'result.data'.
CThe 'graphql' function returns a promise resolving to an object with 'data' and 'errors', but if 'result' is undefined, accessing 'result.data' causes the error.
DThe 'graphql' function returns an object with 'data' nested inside 'result', so accessing 'result.data' is correct.
Attempts:
2 left
💡 Hint
Check if the promise resolves correctly and if the result is defined before accessing properties.