defineConfig is the recommended way to configure your LakeQL API server. It provides full type safety for permissions by inferring catalog, schema, and table names from your generated configs.
Signature #
1
2
3
4
function defineConfig<const TConfig extends readonly SchemaConfigEntry[]>(
input: TConfig | DefineConfigOptions<TConfig>
): DefinedApiConfig<TConfig>
Configuration options #
The DefineConfigOptions interface extends ApiRuntimeConfig with a required allConfigs field:
| Property | Type |
|---|---|
| getUser? | GetUserResolver |
Custom JWT authentication resolver. built-in mock auth | |
| hasReadPermission? | ReadPermissionResolver |
Custom read permission resolver. built-in read permission check | |
| hasWritePermission? | WritePermissionResolver |
Custom write permission resolver. built-in write permission check | |
| maxRecordsPerPage? | number |
Maximum records per paginated response. 2000 | |
| yogaConfig? | YogaConfigOverrides |
Override GraphQL Yoga options. | |
| permissions? | Permission[] |
Permission rules for technical users. [] | |
| baseDir? | string |
Base directory for resolving relative paths. process.cwd() | |
| schemaPath? | string |
Path to query schema files (relative to baseDir). | |
| graphqlPath? | string |
GraphQL endpoint path. "/graphql" | |
| healthCheckEndpoint? | string |
Health check endpoint path. "/live" | |
| port? | number |
Server port. 4000 | |
Return type #
defineConfig returns a DefinedApiConfig object that includes all your config options plus two convenience methods:
1
2
3
4
5
6
7
interface DefinedApiConfig<TConfig> {
// ...all config options
allConfigs: TConfig
createYogaServer: (logger) => Promise<ApiYoga>
startServer: () => Promise<void>
}
Usage #
Minimal — pass only configs #
1
2
3
4
5
import { defineConfig } from "@lakeql/api/config"
import { allConfigs } from "./config-registry"
export const config = defineConfig(allConfigs)
Full configuration (matching the template) #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { defineConfig } from "@lakeql/api/config"
import { getUser } from "./auth"
import { allConfigs } from "./config-registry"
import { permissions } from "./permissions"
const baseDir = import.meta.dirname
export const config = defineConfig({
allConfigs,
baseDir,
getUser,
graphqlPath: "/graphql",
healthCheckEndpoint: "/live",
permissions,
port: 4000,
schemaPath: "./schemas",
})
Using startServer #
1
2
3
4
import { config } from "./config"
await config.startServer()
This calls startApiServer internally with your defined configuration.