You have a REST API endpoint /users/1 that returns user data with their posts. In GraphQL, you want to fetch the same data with one query.
Given this GraphQL query:
{ user(id: 1) { id name posts { id title } } }What is the expected JSON output?
GraphQL responses always wrap the result inside a data field matching the query shape.
The GraphQL response wraps the requested fields inside a data object. The query asks for user with id 1, their id, name, and posts with id and title. Option B matches this exactly.
Which statement best describes the difference between a GraphQL query and a REST API endpoint?
Think about flexibility in data retrieval.
GraphQL lets clients ask for exactly the fields they want, reducing over-fetching. REST endpoints return a fixed response shape, often requiring multiple calls for nested data.
Consider this GraphQL mutation intended to create a new user:
mutation {
createUser(name: "Bob", age: 30) {
id
name
}
}Which option shows the correct syntax to fix the error?
Check how arguments are passed in mutations.
Most GraphQL mutations expect a single input object argument. Option C correctly wraps the fields inside an input object. Option C is invalid if the schema requires an input object. Option C is missing a comma. Option C passes age as a string instead of an integer.
You have a REST endpoint /products returning all product details. Migrating to GraphQL, you want to optimize queries to fetch only product names and prices.
Which GraphQL query best achieves this?
Only request the fields you need.
Option A requests only name and price, minimizing data transfer and processing. Other options request extra fields, causing overfetching.
After migrating from REST to GraphQL, a query to fetch a user's email returns null even though the REST API returned the email correctly.
Given this GraphQL schema snippet:
type User {
id: ID!
name: String!
email: String
}And resolver code snippet:
user: (parent, args, context) => {
return database.findUserById(args.id);
}What is the most likely cause of the null email in the response?
Check what data the resolver returns from the database.
If the database query does not include the email field, the resolver returns a user object without email, so GraphQL returns null for that field. The schema marking email as nullable is correct to allow nulls if missing. The resolver has a return statement. If the client did not request email, it wouldn't appear at all.