Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
In a traditional REST architecture, you might have multiple endpoints like `/users` and `/posts`. How many URL endpoints does a standard GraphQL API expose to the frontend?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a GraphQL with Node.js pipeline. Include the setup and basic execution steps.
You are reviewing a GraphQL with Node.js pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
The N+1 query problem in nested resolvers
// Wrong: fires one query per user in the list
const resolvers = {
User: { posts: (user) => db.posts.findByUserId(user.id) }
};
// Correct: DataLoader batches all pending .load() calls into one query
const postLoader = new DataLoader(async (userIds) => {
const posts = await db.posts.findByUserIds(userIds);
return userIds.map(id => posts.filter(p => p.userId === id));
});
const resolvers = {
User: { posts: (user) => postLoader.load(user.id) }
};The Solution //
A naive resolver for user.posts that runs a separate database query for every single user in a list (1 query for the users, then N more queries, one per user, for their posts) devastates performance as list size grows. Batch and cache these lookups per-request with a DataLoader so all the posts for every user in the list are fetched in a single query.
The Error //
Assuming an HTTP 200 response means the GraphQL request succeeded
const res = await fetch('/graphql', { method: 'POST', body: JSON.stringify({ query }) });
const { data, errors } = await res.json();
if (errors) {
// Must check this explicitly ā res.ok is true even here
console.error('GraphQL errors:', errors);
}The Solution //
GraphQL servers conventionally return HTTP 200 even when a query partially or fully fails ā errors are reported inside an 'errors' array alongside whatever 'data' could still be resolved. Client code that only checks response.ok (or a REST-style status code) will silently miss real errors buried in the response body.