LakeQL
Overview
  • Introduction
Server Setup
  • createApiServer
  • defineConfig
  • Yoga Configuration
Authentication
  • JWT Authentication
  • Permissions
  • Scope Authorization
Schema Builder
  • Builder Configuration
  • Scalar Types
  • Comparison Types
  • Pagination
  • Input Validation
Customization
  • Custom Queries & Mutations
  • Extending Core
  • CORS Configuration
GitHub
LakeQL
  1. API
  2. Server Setup
  3. createApiServer

On this page

  1. Signature
  2. Return type
  3. What it sets up
  4. Usage
  5. Starting the server

createApiServer

Create a configured Hono application with GraphQL Yoga integration, CORS, and logging middleware.

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 #

PropertyType
appHono

The Hono application instance with all routes mounted.

loggerReturnType<typeof createLogger>

Configured logger instance from @lakeql/logger.

yogaAwaited<ReturnType<typeof createYogaServer>>

The GraphQL Yoga server handling /graphql requests.

What it sets up #

  1. Creates a structured logger via @lakeql/logger
  2. Initializes GraphQL Yoga with the loaded schema and context
  3. Mounts Hono logger middleware on all routes
  4. Configures CORS on the GraphQL path (POST, GET, OPTIONS)
  5. 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.

Previous page

Server Setup

Next page

defineConfig

src/server.ts
src/index.ts
src/index.ts