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:
| Property | Type |
|---|---|
| currentUser | JWTPayload | null |
Authenticated user payload from JWT verification, or | |
| permissions | Permission[] |
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.