@silkline/hasura-sim
v0.1.3
Published
In-memory Hasura GraphQL Engine (compiled to WebAssembly) + pglite — runs real GraphQL queries/mutations offline for tests and codegen, with no Docker/Postgres/network.
Keywords
Readme
@silkline/hasura-sim
An in-memory Hasura GraphQL engine for tests. The real Hasura GraphQL Engine v2 (Haskell) is compiled to WebAssembly and paired with pglite (WASM Postgres). Feed it static Hasura metadata and a migrated pglite instance, then run GraphQL operations and get back exactly what the real engine returns — no Docker, no Postgres server, no network.
How it works
GraphQL op ─▶ sim_execute (wasm Hasura engine)
│ parse → IR → SQL (real engine: permissions,
│ session vars, relationships, …)
▼
pg_exec bridge ──▶ pglite (in-process Postgres)
▲ │
└──── rows ──────┘The engine runs the real schema-cache builder and query/mutation translator.
SQL is executed against pglite over the PostgreSQL wire protocol (src/wire.mjs),
so binary params + OIDs and result formats round-trip faithfully.
Usage
import { PGlite } from "@electric-sql/pglite";
import { createSimulator } from "@silkline/hasura-sim";
const db = new PGlite();
await db.exec(/* your migrations */);
const sim = await createSimulator({
db,
metadataJson: {
version: 3,
sources: [
{
name: "default",
kind: "postgres",
configuration: {
connection_info: { database_url: "postgres://localhost/db" },
},
tables: [{ table: { schema: "public", name: "widget" } }],
},
],
},
});
const { data, errors } = await sim.execute({
query: "query ($id: Int!) { widget(where: { id: { _eq: $id } }) { id name } }",
variables: { id: 2 },
role: "user", // default "admin"
sessionVariables: { "x-hasura-user-id": "42" },
});metadataJson is consolidated Hasura metadata (hasura metadata export -o json).
The database_url is ignored — all SQL is routed to the provided pglite db.
Status
Validated end-to-end: queries (param-free + parameterized) and mutations (insert, committing). Remote schemas and actions are out of scope (stubbed).
