createApiServer is the primary factory function for building a LakeQL API instance. It wires together Hono, GraphQL Yoga, and all middleware into a ready-to-use server object.
Signature #
1
2
function createApiServer(options?: ApiRuntimeConfig): Promise<ApiServer>
Return type #
| Property | Type |
|---|---|
| app | Hono |
The Hono application instance with all routes mounted. | |
| logger | ReturnType<typeof createLogger> |
Configured logger instance from | |
| yoga | Awaited<ReturnType<typeof createYogaServer>> |
The GraphQL Yoga server handling | |
What it sets up #
-
Creates a structured logger via
@lakeql/logger - Initializes GraphQL Yoga with the loaded schema and context
- Mounts Hono logger middleware on all routes
- Configures CORS on the GraphQL path (POST, GET, OPTIONS)
- Connects the Yoga request handler to Hono
Usage #
1
2
3
4
5
6
7
8
9
10
11
12
import { createApiServer } from "@lakeql/api/server"
const { app, logger, yoga } = await createApiServer({
baseDir: import.meta.dirname,
schemaPath: "./schemas",
graphqlPath: "/graphql",
port: 4000,
})
// Add custom middleware or routes to the Hono app
app.get("/health", (c) => c.json({ status: "ok" }))
Starting the server #
For most projects, use defineConfig with startServer() instead of calling createApiServer directly:
1
2
3
4
import { config } from "./config"
await config.startServer()
If you don't need defineConfig, startApiServer calls createApiServer internally and binds to a port:
1
2
3
4
5
6
7
8
import { startApiServer } from "@lakeql/api/server"
await startApiServer({
baseDir: import.meta.dirname,
schemaPath: "./schemas",
port: 4000,
})
startApiServer uses @hono/node-server to serve the application via Node.js http module.