Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Where is the standard architectural location to attach your Database ORM instances (like Prisma or Mongoose) so that all GraphQL resolvers can access them without requiring messy global imports in every file?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Data Base Integration pipeline. Include the setup and basic execution steps.
You are reviewing a Node Data Base Integration 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 //
Opening a new database connection inside the context function on every request
// Wrong: opens a brand new connection on every request
context: () => ({ models: connectToDatabase() })
// Correct: connect once at startup, reuse the same models in every request
const models = await connectToDatabase();
const server = new ApolloServer({ typeDefs, resolvers, context: () => ({ models }) });The Solution //
Apollo Server calls the context function once per incoming request. If context: () => ({ models: connectToDatabase() }) actually opens a fresh connection each time instead of reusing an existing pool, the database gets hammered with new connection overhead on every single GraphQL request, quickly exhausting the connection limit under real traffic. Initialize the database connection/pool once at server startup, and only pass the already-connected models into context.
The Error //
Forgetting to return the Promise from a resolver
// Wrong: DB call happens but its result is discarded
getUser: (parent, { id }, { models }) => {
models.User.findById(id); // missing 'return'
}
// Correct
getUser: (parent, { id }, { models }) => {
return models.User.findById(id);
}The Solution //
A resolver that calls an async database method but doesn't return its result (or forgets 'return' in a block-bodied arrow function) leaves GraphQL with nothing to await ā the field resolves to null or undefined even though the database call actually succeeded. Every resolver must explicitly return the value or Promise it produces.