Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Because GraphQL utilizes a single POST `/graphql` endpoint, where is the most appropriate place to write the logic that checks if a user has the
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Authentication in GraphQL pipeline. Include the setup and basic execution steps.
You are reviewing a Node Authentication in GraphQL 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 //
Trying to protect the whole schema with an Express auth middleware in front of /graphql
// Wrong: blocks login/register too
app.post('/graphql', authMiddleware, graphqlHandler);
// Correct: identify the user in context, let resolvers decide
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => ({ user: verifyToken(req.headers.authorization) })
});The Solution //
Because GraphQL exposes a single POST endpoint, a blanket authMiddleware blocks public mutations like login and register along with everything else. Authentication must happen inside the Apollo context function (to extract and verify the user), while authorization is enforced per-resolver or via a schema directive ā never as a route-level gate.
The Error //
Assuming a rejected field silently disappears instead of erroring the whole response
// Hides the field without failing the whole query
email: (parent, args, context) => {
if (context.user?.role === 'ADMIN') return parent.email;
return null; // field must be nullable in the schema
}The Solution //
Throwing inside a nested resolver (e.g. the email field resolver) doesn't just null out that one field by default ā GraphQL's error propagation bubbles a thrown error up and can null out the entire parent object unless the field is nullable. Return null for fields you want to hide from unauthorized users, and reserve throwing an AuthenticationError for top-level operations that should fail entirely.