Given this GraphQL schema and mocked resolver, what will be the output of the query?
type Query {
user(id: ID!): User
}
type User {
id: ID!
name: String
age: Int
}
// Mock resolver for user
const mocks = {
Query: () => ({
user: (_parent, args) => ({
id: args.id,
name: "Alice",
age: 30
})
})
};
query {
user(id: "123") {
id
name
age
}
}const mocks = { Query: () => ({ user: (_parent, args) => ({ id: args.id, name: "Alice", age: 30 }) }) };
Look at how the id is returned from the args in the resolver.
The mocked resolver returns the user object with id taken from the query argument id. So the output includes "id": "123" along with the fixed name and age.
Identify the option that contains a syntax error in the mocked resolver definition.
Check the arrow function syntax and object return syntax carefully.
Option B uses curly braces without a return statement inside the arrow function, so it does not return an object but a block, causing a syntax error or unexpected behavior.
You have many similar resolvers returning user data with different IDs. Which approach optimizes mocking these resolvers efficiently?
Think about how to reuse code and handle dynamic input.
Using a generic resolver that reads the id argument and returns corresponding data dynamically avoids repetitive code and scales better.
Given this mocked resolver snippet, why does the email field return null in the query result?
const mocks = {
User: () => ({
id: "1",
name: "Eve"
})
};
query {
user(id: "1") {
id
name
email
}
}Check which fields the mock resolver explicitly returns.
Mocked resolvers return null for any fields not explicitly defined in the mock. Since email is missing, it returns null.
Choose the best explanation for why developers use mocked resolvers during GraphQL API development.
Think about development workflow and decoupling frontend from backend.
Mocking resolvers allows frontend developers to work with expected data shapes without waiting for backend implementation, speeding up development and testing.