tutorial

Monitoring Apollo GraphQL Server with Vigilmon

Apollo Server has no built-in uptime dashboard. Here's how to monitor your Apollo GraphQL API, track resolver health, and catch schema errors before users do — using Vigilmon.

Apollo Server powers thousands of production GraphQL APIs, but it ships with no built-in uptime monitoring. A crashed server, a misconfigured schema, or a slow resolver returns a 200 response with an error body — and your users hit it first. Vigilmon gives you HTTP uptime checks, endpoint health probes, and alerting so you know about Apollo Server failures before your users do.

What You'll Set Up

  • HTTP uptime monitor for the GraphQL endpoint
  • Health check endpoint returning server and schema status
  • Introspection probe to detect schema load failures
  • Cron heartbeat for subscription gateway processes
  • SSL certificate monitoring for production domains

Prerequisites

  • Apollo Server 4+ (Express, standalone, or framework integration)
  • A running GraphQL API accessible over HTTP/HTTPS
  • A free Vigilmon account

Step 1: Add a Health Check Endpoint

Apollo Server's GraphQL endpoint (/graphql) accepts POST requests with a query body. A plain HTTP GET to /graphql returns a 400 or redirect — not useful for uptime monitoring. Add a dedicated /health route that Vigilmon can probe with a simple GET:

Apollo Server 4 with Express

import express from 'express';
import { ApolloServer } from '@apollo/server';
import { expressMiddleware } from '@apollo/server/express4';

const app = express();
const server = new ApolloServer({ typeDefs, resolvers });

await server.start();

// Health check — probed by Vigilmon every minute
app.get('/health', (req, res) => {
  res.json({
    status: 'ok',
    schema: server.schema ? 'loaded' : 'missing',
    uptime: process.uptime(),
  });
});

app.use('/graphql', express.json(), expressMiddleware(server));
app.listen(4000);

Apollo Server 4 Standalone

import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';

const server = new ApolloServer({ typeDefs, resolvers });
const { url } = await startStandaloneServer(server, {
  listen: { port: 4000 },
  context: async ({ req }) => {
    // Add a health check path via middleware if needed
    if (req.url === '/health') {
      return { health: true };
    }
    return {};
  },
});

For standalone mode, use Express integration (above) so you can add the /health route cleanly.


Step 2: Probe the GraphQL Endpoint with a Lightweight Query

The most reliable way to verify Apollo Server is actually resolving queries — not just listening on a port — is to send a real GraphQL query as part of your health check:

app.get('/health', async (req, res) => {
  try {
    // Execute a minimal introspection query via Apollo's executeOperation
    const result = await server.executeOperation({
      query: '{ __typename }',
    });

    const hasErrors = result.body.kind === 'single' && result.body.singleResult.errors?.length > 0;

    if (hasErrors) {
      return res.status(503).json({ status: 'error', detail: 'schema execution failed' });
    }

    res.json({ status: 'ok', uptime: process.uptime() });
  } catch (err) {
    res.status(503).json({ status: 'error', detail: err.message });
  }
});

{ __typename } is the smallest valid GraphQL query — it touches the schema parser and execution engine without hitting any resolver or database.


Step 3: Add the Vigilmon Monitor

  1. Log in to vigilmon.online and click Add Monitor.
  2. Set Type to HTTP / HTTPS.
  3. Enter your health check URL: https://api.yourdomain.com/health
  4. Set Check interval to 1 minute.
  5. Set Expected HTTP status to 200.
  6. Click Save.

For the GraphQL endpoint itself, add a second monitor using a POST request:

  1. Click Add MonitorHTTP / HTTPS.
  2. Set Method to POST.
  3. Set URL to https://api.yourdomain.com/graphql.
  4. Add header Content-Type: application/json.
  5. Set Request body to {"query":"{ __typename }"}.
  6. Set Expected HTTP status to 200.
  7. Click Save.

This second monitor catches cases where the /health endpoint is healthy but the GraphQL middleware is broken.


Step 4: Monitor SSL Certificate Expiry

If Apollo Server is behind a TLS-terminating proxy (nginx, Caddy, AWS ALB), add an SSL monitor:

  1. Open the HTTP monitor for your API.
  2. Enable Monitor SSL certificate.
  3. Set Alert when certificate expires in less than 21 days.
  4. Click Save.

For federated Apollo setups with a gateway and subgraphs on separate domains, add one SSL monitor per domain.


Step 5: Heartbeat for Subscription Servers

Apollo Subscriptions (WebSocket or SSE) run as a long-lived server process. If the subscription process crashes, clients silently lose real-time updates — there's no HTTP endpoint that fails. Use a Vigilmon cron heartbeat:

  1. In Vigilmon, click Add MonitorCron Heartbeat.
  2. Set the expected ping interval (e.g. 5 minutes).
  3. Copy the heartbeat URL.
  4. In your subscription server, ping Vigilmon on a timer:
import https from 'https';

// Ping every 4 minutes (before the 5-minute window expires)
setInterval(() => {
  https.get('https://vigilmon.online/heartbeat/YOUR_KEY').on('error', () => {});
}, 4 * 60 * 1000);

If the subscription server process dies, the pings stop, and Vigilmon alerts after the interval elapses.


Step 6: Configure Alerts

  1. Go to Alert Channels in Vigilmon and add Slack, email, or webhook.
  2. Set Consecutive failures before alert to 2 — Apollo Server restarts under process managers like PM2 take a few seconds.
  3. Use Maintenance windows during schema deployments to avoid alert noise:
# Pause monitoring during Apollo Server restarts
curl -X POST https://vigilmon.online/api/maintenance \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"monitor_id": "YOUR_MONITOR_ID", "duration_minutes": 3}'

# Deploy / restart Apollo Server
pm2 restart apollo

Summary

| Monitor | Target | What It Catches | |---|---|---| | Health endpoint | /health | Process crash, schema load failure | | GraphQL POST | /graphql with { __typename } | Middleware failure, resolver panic | | SSL certificate | API domain | TLS cert expiry | | Cron heartbeat | Subscription server | WebSocket process crash |

Apollo Server's flexibility — standalone, Express, Fastify, federated — means you choose where uptime monitoring goes. With Vigilmon watching the health endpoint and sending a real GraphQL probe every minute, you catch crashes, schema errors, and cold-start failures before any user's query fails.

Monitor your app with Vigilmon

Free plan — 5 monitors, no credit card required. Up and running in 60 seconds.

Start free →