LakeQL
  • Overview
Server Setup
  • Create Server
  • Define Config
  • Yoga Configuration
  • createLakeQLApp
Authentication
  • Authorization Model
  • JWT Authentication
  • Permissions
  • Scope Authorization
  • Trino User Impersonation
  • Debugging Identity
Schema Builder
  • Builder Configuration
  • Scalar Types
  • Comparison Types
  • Pagination
  • Input Validation
Customization
  • Custom Queries & Mutations
  • Extending Core
  • CORS Configuration
  • Error Handling
  • API Reference
GitHub
LakeQL
  1. API
  2. Server Setup
  3. Create Server

On this page

  1. The Runtime
  2. Graceful Shutdown
  3. Lower-Level Entry Points

Create Server

Compose the server with defineApiConfig and start it.

Pass your runtime config to defineApiConfig. It returns a resolved config with convenience methods. Call startServer() to run the full HTTP server.

1
2
3
4
5
6
7
8
9
10
11
12
import { defineApiConfig } from "@lakeql/api/config"

const server = defineApiConfig({
  runtime,
  tokenResolver,
  permissions,
  baseDir: import.meta.dirname,
  schemaPath: "./schemas",
})

await server.startServer()

The Runtime #

The API server does not build the runtime. Your application builds it with createLakeQLRuntime and passes it in as runtime. Resolvers reach read strategies through it. This keeps the API out of the runtime lifecycle, so your code owns shutdown.

Graceful Shutdown #

Because the application owns the runtime, close it on shutdown signals:

1
2
3
4
5
6
7
const shutdown = async () => {
  await runtime.close()
  process.exit(0)
}
process.on("SIGTERM", shutdown)
process.on("SIGINT", shutdown)

Lower-Level Entry Points #

Need the Yoga instance without starting an HTTP listener? defineApiConfig also exposes createYogaServer(logger). For direct use, the package exports createApiServer and startApiServer.

Previous page

Server Setup

Next page

Define Config