Skip to content

Hono

Use MeshQL with Hono via meshHonoRoutes. Works on Node, Bun, Deno, and edge runtimes.

  • Hono 4+
  • Node.js 22+, Bun 1+, or Deno 2+

npm:

Terminal window
npm install meshql-core meshql-http
npm i hono

JSR:

Terminal window
npx jsr add @meshql/core @meshql/http
npm i hono
# or
bunx jsr add @meshql/core @meshql/http && bun add hono
import { Hono } from "hono";
import { createMesh, buildSelectSql, type MeshSchema } from "@meshql/core";
import { meshHonoRoutes } from "@meshql/http/hono";
const schema: MeshSchema = {
entities: {
user: { type: {} as { id: number; name: string }, fields: ["id", "name"], table: "users" },
token: {
type: {} as { accessToken: string },
fields: ["accessToken"],
table: "tokens",
columns: { accessToken: "access_token" },
},
},
joins: {
"user.tokens": {
entity: "token",
on: "tokens.user_id = users.id",
type: "many",
},
},
};
const mesh = createMesh(schema);
mesh.resolve("user", async (plan) => {
const { sql, params } = buildSelectSql(plan, schema);
return [{ user_id: 1, user_name: "Ada", tokens_accessToken: "tok_abc" }];
});
const app = new Hono();
app.route("/", meshHonoRoutes(mesh, { basePath: "/mesh" }));
export default app;
Terminal window
npm i @hono/node-server
import { serve } from "@hono/node-server";
import app from "./app.js";
serve({ fetch: app.fetch, port: 3001 });
import { createClient } from "@meshql/client";
const client = createClient({ url: "http://localhost:3001/mesh" });
const user = await client.query(
{ user: { id: true, name: true, tokens: { accessToken: true } } },
{ entityId: "1" },
);

HTTP adapters