Integrating GraphQL with an HTTP Server
In production Node.js applications, GraphQL often needs to coexist with other HTTP routes and middleware.
For example, an application may expose:
GET /health
POST /webhooks/payment
GET /metrics
POST /graphql
GraphQL is therefore one part of the HTTP application rather than necessarily being the entire application.
The integration layer is responsible for concerns such as:
- HTTP request handling
- CORS
- authentication middleware
- request IDs
- compression
- body parsing where appropriate
- rate limiting
- health checks
- metrics
- GraphQL request handling
A typical architecture is:
Node HTTP Server
├── /health
├── /metrics
├── /webhooks
└── /graphql
↓
Apollo Server
This separation is useful because webhooks and health endpoints often have requirements that differ from GraphQL operations.
For example, a payment webhook may require verification of the provider's signature against the raw request body, while GraphQL requests usually use JSON parsing. Applying identical middleware blindly to every route can introduce subtle bugs.
- GraphQL can coexist with ordinary HTTP endpoints.
- The HTTP layer can handle cross-cutting infrastructure concerns.
- Different endpoints may require different middleware behavior.
- Webhook verification may require special raw-body handling.
Why might a production Node.js application expose both `/health` and `/graphql`?