Challenge 2: Mount at a Custom Path With a Health Check — Possible Solution ==================================================================== import express from "express"; import { expressMiddleware } from "@apollo/server/express4"; const app = express(); const server = new ApolloServer({ typeDefs, resolvers }); await server.start(); // Plain ordinary REST route, defined just like in the Express courses — // nothing GraphQL-specific about this at all. app.get("/health", (req, res) => { res.json({ status: "ok" }); }); // GraphQL mounted at a custom path instead of the default "/graphql". app.use( "/api/graphql", express.json(), expressMiddleware(server, { async context({ req }) { return { userLoader: createUserLoader(pool) }; }, }) ); app.listen(4000); WHY THIS WORKS -------------- - app.use("/api/graphql", ...) is the ONLY change needed to relocate the GraphQL endpoint — the mount path passed to app.use() is just an ordinary Express routing decision, completely independent of anything inside the schema, resolvers, or context function. GraphQL doesn't care what URL path it's served from; the client just needs to be configured to send its queries to whatever path the server actually mounts it at. - app.get("/health", ...) is defined as a COMPLETELY separate, ordinary Express route, using the exact same app.get() pattern from the Express courses — this demonstrates directly that a GraphQL server doesn't have to be the ONLY thing an Express app serves. A single app can freely mix a GraphQL endpoint with conventional REST routes for things that don't need (or don't benefit from) GraphQL's query flexibility, like a simple health check a load balancer or monitoring tool might poll. - This is a very common real-world pattern: GraphQL for the application's actual data-fetching needs, plain REST for auxiliary concerns like health checks, webhooks, or file uploads — echoing Chapter 1's honest "REST still wins for certain things" framing, now shown living side-by-side with GraphQL in the same running server rather than as an either/or choice for the whole application.