tutorial

Monitoring GraphQL Yoga Server with Vigilmon

GraphQL Yoga is a batteries-included GraphQL server — but it needs external uptime monitoring. Here's how to add health checks, track server status, and get alerts when your Yoga API goes down.

GraphQL Yoga is a full-featured GraphQL server built on top of the Fetch API, running natively on Node.js, Bun, Deno, and edge runtimes. Its flexibility is excellent — but flexibility means you own the uptime story. A process crash, a plugin failure, or an SSL renewal lapse won't alert you on its own. Vigilmon gives you per-endpoint uptime checks, certificate monitoring, and alerting to keep your GraphQL Yoga server production-ready.

What You'll Set Up

  • HTTP uptime monitor for the GraphQL endpoint
  • Dedicated /health route integrated with Yoga's plugin system
  • GraphQL query probe to verify execution engine health
  • SSL certificate alerts for production domains
  • Heartbeat for background event consumers

Prerequisites

  • GraphQL Yoga 3+ (Node.js, Bun, or Deno)
  • A running Yoga server accessible over HTTP/HTTPS
  • A free Vigilmon account

Step 1: Add a Health Check Route

GraphQL Yoga's createYoga() handles the /graphql path by default. Add a separate /health route at the HTTP server layer so Vigilmon can probe with a plain GET:

Node.js with HTTP

import { createServer } from 'http';
import { createYoga } from 'graphql-yoga';

const yoga = createYoga({ typeDefs, resolvers });

const server = createServer((req, res) => {
  if (req.url === '/health' && req.method === 'GET') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ status: 'ok', uptime: process.uptime() }));
    return;
  }
  yoga(req, res);
});

server.listen(4000);

Node.js with Express

import express from 'express';
import { createYoga } from 'graphql-yoga';

const app = express();
const yoga = createYoga({ typeDefs, resolvers });

app.get('/health', (req, res) => {
  res.json({ status: 'ok', uptime: process.uptime() });
});

app.use('/graphql', yoga);
app.listen(4000);

Bun

import { createYoga } from 'graphql-yoga';

const yoga = createYoga({ typeDefs, resolvers });

Bun.serve({
  port: 4000,
  fetch(req) {
    const url = new URL(req.url);
    if (url.pathname === '/health') {
      return new Response(JSON.stringify({ status: 'ok' }), {
        headers: { 'Content-Type': 'application/json' },
      });
    }
    return yoga.fetch(req);
  },
});

Step 2: Use Yoga's Plugin System for Richer Health Checks

GraphQL Yoga has a powerful plugin API. Create a health check plugin that verifies the schema is loaded and execution works:

import { createYoga, createSchema } from 'graphql-yoga';

let schemaReady = false;

const healthPlugin = {
  onSchemaChange() {
    schemaReady = true;
  },
};

const yoga = createYoga({
  schema: createSchema({ typeDefs, resolvers }),
  plugins: [healthPlugin],
});

// Health route checks schema state
app.get('/health', (req, res) => {
  if (!schemaReady) {
    return res.status(503).json({ status: 'error', detail: 'schema not ready' });
  }
  res.json({ status: 'ok', schema: 'ready', uptime: process.uptime() });
});

This catches cases where the schema failed to build — Yoga will still start but resolve nothing.


Step 3: Add Vigilmon Monitors

Monitor 1: Health Endpoint

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

Monitor 2: GraphQL Execution Probe

GraphQL Yoga returns HTTP 200 even for execution errors, so verify with a real query POST:

  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. Optionally set Response must contain to "data" to verify the response is a valid GraphQL response.
  8. Click Save.

Step 4: SSL Certificate Monitoring

GraphQL Yoga is often deployed behind a reverse proxy (Caddy, nginx, Traefik) that handles TLS. Add a certificate monitor so you're alerted before Let's Encrypt renewal failures cause downtime:

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

If your Yoga server runs on multiple subdomains (e.g. a federated setup with separate subgraph servers), add one SSL monitor per domain.


Step 5: Heartbeat for Subscriptions and Workers

GraphQL Yoga supports subscriptions via SSE (Server-Sent Events) out of the box. If the subscription process is separate, monitor it with a heartbeat:

  1. In Vigilmon, click Add MonitorCron Heartbeat.
  2. Set the expected ping interval (e.g. 5 minutes).
  3. Copy the heartbeat URL.
  4. Add a recurring ping in your server:
// Ping Vigilmon every 4 minutes from the Yoga process
const HEARTBEAT_URL = 'https://vigilmon.online/heartbeat/YOUR_KEY';

setInterval(async () => {
  try {
    await fetch(HEARTBEAT_URL);
  } catch {
    // non-fatal — Vigilmon will alert if pings stop
  }
}, 4 * 60 * 1000);

For Deno or Bun environments, fetch is a global — no imports needed.


Step 6: Alert Channel Setup

  1. Go to Alert Channels in Vigilmon and add Slack, email, or PagerDuty.
  2. Set Consecutive failures before alert to 2 — a single failed probe during a hot reload is normal.
  3. Silence alerts during planned maintenance:
# Pause before restarting Yoga server
curl -X POST https://vigilmon.online/api/maintenance \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"monitor_id": "YOUR_MONITOR_ID", "duration_minutes": 3}'

# Restart
pm2 restart graphql-yoga
# or: bun run start

Summary

| Monitor | Target | What It Catches | |---|---|---| | Health endpoint | /health | Process crash, schema build failure | | GraphQL POST | /graphql with { __typename } | Execution engine failure, middleware error | | SSL certificate | API domain | TLS cert expiry | | Cron heartbeat | Subscription/worker process | Process crash between deployments |

GraphQL Yoga's runtime portability (Node.js, Bun, Deno, edge) is a strength — and Vigilmon's simple HTTP probe works the same way everywhere. With a health route, a real GraphQL probe, and SSL monitoring in place, you'll know about Yoga server failures before any GraphQL client does.

Monitor your app with Vigilmon

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

Start free →