Skip to content

meshql-sse (@meshql/sse)

Field-aware MeshQL subscriptions over Server-Sent Events (v0.9.0 — 0.2.1 adds Fastify and Hono adapters).

Terminal window
npm install meshql-sse meshql-pubsub meshql-core meshql-http
# or
npx jsr add @meshql/sse @meshql/pubsub @meshql/core @meshql/http

Published on npm as meshql-sse and JSR as @meshql/sse.

Clients open GET /mesh/:entity/:id/events with the same X-Mesh-Query headers as a point read. When @meshql/pubsub notifies a change, the server re-runs the selection and streams an update SSE event with fresh JSON.

import express from "express";
import { createMesh } from "@meshql/core";
import { meshExpressRouter } from "@meshql/http/express";
import { InMemoryPubSubStore, notifyEntityUpdate } from "@meshql/pubsub";
import { meshSseExpressRouter } from "@meshql/sse/express";
const pubsub = new InMemoryPubSubStore();
const mesh = createMesh(schema);
const app = express();
app.use(meshExpressRouter(mesh, "/mesh"));
app.use(meshSseExpressRouter(mesh, { pubsub }, "/mesh"));
// After a mutation, notify subscribers:
notifyEntityUpdate(pubsub, "post", postId);
import Fastify from "fastify";
import { createMeshSseFastifyPlugin } from "@meshql/sse/fastify";
const app = Fastify();
await app.register(createMeshSseFastifyPlugin(mesh, { pubsub, basePath: "/mesh" }));
import { Hono } from "hono";
import { meshSseHonoRoutes } from "@meshql/sse/hono";
const app = new Hono();
app.route("/", meshSseHonoRoutes(mesh, { pubsub, basePath: "/mesh" }));

Signed requests (integrity/access plugins) use the same headers as GET — access control runs on each SSE refresh.

GraphQL uses a persistent websocket with subscription resolvers. MeshQL SSE is REST-native: same selection as GET, refresh on pub/sub events. See From GraphQL.