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. Schema Builder
  3. Builder Configuration

On this page

  1. Builder setup
  2. Context type
  3. Auth scopes
  4. SortDirection enum
  5. Importing the builder

Builder Configuration

Pothos SchemaBuilder setup with scope auth, validation plugins, and the GraphQL context type.

The Pothos SchemaBuilder is the foundation of LakeQL's type-safe GraphQL schema. It's pre-configured with auth scopes and validation, and shared across all query schema files.

Builder setup #

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22import SchemaBuilder from "@pothos/core"
import ScopeAuthPlugin from "@pothos/plugin-scope-auth"
import ValidationPlugin from "@pothos/plugin-validation"

const builder = new SchemaBuilder<{
  Context: Context
  Scalars: Partial<UserScalars["Scalars"]>
  AuthScopes: {
    authorized: boolean
    readPermission: PermissionFields
    writePermission: PermissionFields
  }
}>({
  plugins: [ScopeAuthPlugin, ValidationPlugin],
  scopeAuth: {
    /* ... */
  },
  validation: {
    /* ... */
  },
})

Context type #

Every resolver receives this context object:

PropertyType
currentUserJWTPayload | null

Authenticated user payload from JWT verification, or null for unauthenticated requests.

permissionsPermission[]

Configured permission rules for technical users.

hasReadPermission?ReadPermissionResolver

Custom resolver for read permission checks.

hasWritePermission?WritePermissionResolver

Custom resolver for write permission checks.

A logger instance is also injected into the context by the Yoga server setup.

Auth scopes #

The builder defines three scopes that can be applied to any field:

1
2
3
4
5
6
AuthScopes: {
  authorized: boolean // user is authenticated
  readPermission: PermissionFields // { catalog, schema, tableName }
  writePermission: PermissionFields // { catalog, schema, tableName }
}

SortDirection enum #

A shared enum for ordering query results:

1
2
3
import { SortDirection } from "@lakeql/api/builder"
// Values: "ASC" | "DESC"

Importing the builder #

Custom query schemas import the shared builder instance to register types and fields:

1
2
3
4
5
6
7
8
import { builder } from "@lakeql/api/builder"

builder.queryField("hello", (t) =>
  t.string({
    resolve: () => "world",
  })
)

All files that import builder and define types or fields are automatically discovered during schema loading — no explicit registration needed.

Previous page

Schema Builder

Next page

Scalar Types

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22