Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
In the architecture of Apollo Server, what is the primary purpose of the
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Apollo Server pipeline. Include the setup and basic execution steps.
You are reviewing a Node Apollo Server 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 //
Forgetting that the context function runs on every single request, and doing expensive work inside it
// Wrong: does a full DB roundtrip on every request, even public queries
const contextFn = async ({ req }) => {
const settings = await db.settings.findOne(); // expensive, runs every time
return { user: await verifyJWT(req.headers.authorization), settings };
};
// Correct: only decode the token; let resolvers fetch what they actually need
const contextFn = async ({ req }) => ({
user: await verifyJWT(req.headers.authorization),
db
});The Solution //
Since Apollo calls the context function fresh for every incoming HTTP request (not once at server startup), placing an expensive operation there ā like re-parsing a large config file or making an unnecessary database round trip before knowing if the query even needs it ā multiplies that cost by your request volume. Keep the context function limited to cheap, per-request necessities like verifying a JWT and returning lightweight references (a db client, not a fresh connection).
The Error //
Throwing a plain JavaScript Error instead of GraphQLError, losing structured error codes
// Wrong: client can't distinguish this from a real server crash
throw new Error('Not authorized');
// Correct: explicit, machine-readable error code
throw new GraphQLError('Not authorized', { extensions: { code: 'UNAUTHENTICATED' } });The Solution //
throw new Error('Not authorized') reaches the client as a generic INTERNAL_SERVER_ERROR extension code, giving the frontend no reliable way to distinguish an auth failure from a genuine server bug. Use GraphQLError with an explicit extensions.code so clients can branch on error type (e.g. redirect to login on UNAUTHENTICATED) instead of string-matching the error message.