Schema API Reference
Functions
Section titled “Functions”buildSchema
Section titled “buildSchema”function buildSchema( db: PgDatabase<any, any, any>, config?: BuildSchemaConfig,): { schema: GraphQLSchema entities: GeneratedEntities withPermissions: (permissions: PermissionConfig) => GraphQLSchema clearPermissionCache: (id?: string) => void}Main entry point. Takes a Drizzle PgDatabase instance and optional configuration, returns the generated GraphQL schema, entity definitions, and permission helpers.
buildSchemaFromDrizzle
Section titled “buildSchemaFromDrizzle”function buildSchemaFromDrizzle( drizzleSchema: Record<string, unknown>, config?: BuildSchemaConfig,): { schema: GraphQLSchema entities: GeneratedEntities withPermissions: (permissions: PermissionConfig) => GraphQLSchema clearPermissionCache: (id?: string) => void}Builds a schema directly from Drizzle schema exports without a database connection. Creates stub resolvers — intended for introspection, codegen, and testing.
buildEntities
Section titled “buildEntities”function buildEntities( db: PgDatabase<any, any, any>, config?: BuildSchemaConfig,): GeneratedEntitiesReturns the GeneratedEntities object (queries, mutations, inputs, types) without building a full GraphQLSchema. Useful for composing into an existing schema.
generateSDL
Section titled “generateSDL”function generateSDL( schema: GraphQLSchema,): stringGenerates the GraphQL SDL string from a GraphQLSchema (as produced by buildSchema or buildSchemaFromDrizzle). Codegen utility.
generateTypes
Section titled “generateTypes”function generateTypes( schema: GraphQLSchema, options?: CodegenOptions,): stringGenerates TypeScript type definitions from a GraphQLSchema. Codegen utility.
generateEntityDefs
Section titled “generateEntityDefs”function generateEntityDefs( schema: GraphQLSchema, options?: CodegenOptions,): stringGenerates entity definition types for use with @graphql-suite/client from a GraphQLSchema. Codegen utility.
permissive
Section titled “permissive”function permissive( id: string, tables?: Record<string, boolean | TableAccess>,): PermissionConfigCreates a permissive permission config. In permissive mode, all tables are accessible unless explicitly denied.
restricted
Section titled “restricted”function restricted( id: string, tables?: Record<string, boolean | TableAccess>,): PermissionConfigCreates a restricted permission config. In restricted mode, all tables are denied unless explicitly allowed.
readOnly
Section titled “readOnly”function readOnly(): TableAccessReturns a TableAccess object with query: true and all mutations set to false.
withRowSecurity
Section titled “withRowSecurity”function withRowSecurity( rules: Record<string, (context: any) => Record<string, unknown>>,): HooksConfigGenerates a HooksConfig that injects WHERE clauses from row-level security rules. Rules are applied as before hooks on query, querySingle, count, update, and delete operations.
mergeHooks
Section titled “mergeHooks”function mergeHooks(...configs: HooksConfig[]): HooksConfigMerges multiple hook configurations. When multiple hooks target the same table and operation, they are composed in order.
Classes
Section titled “Classes”SchemaBuilder
Section titled “SchemaBuilder”class SchemaBuilder { constructor(db: PgDatabase<any, any, any>, config?: BuildSchemaConfig) build(): { schema: GraphQLSchema entities: GeneratedEntities withPermissions: (permissions: PermissionConfig) => GraphQLSchema clearPermissionCache: (id?: string) => void } buildEntities(): GeneratedEntities}The underlying builder class. Exposed for advanced use cases where you need more control over the build process.
Constants
Section titled “Constants”GraphQLJSON
Section titled “GraphQLJSON”Custom GraphQL scalar type for JSONB columns. Serializes and parses arbitrary JSON values.
BuildSchemaConfig
Section titled “BuildSchemaConfig”type BuildSchemaConfig = { mutations?: boolean limitRelationDepth?: number limitSelfRelationDepth?: number suffixes?: { list?: string; single?: string } hooks?: HooksConfig tables?: { exclude?: readonly string[] config?: Record<string, TableOperations> } pruneRelations?: Record<string, RelationPruneRule> debug?: boolean | { schemaSize?: boolean; relationTree?: boolean }}GeneratedEntities
Section titled “GeneratedEntities”type GeneratedEntities = { queries: Record<string, GraphQLFieldConfig<any, any>> mutations: Record<string, GraphQLFieldConfig<any, any>> inputs: Record<string, GraphQLInputObjectType> types: Record<string, GraphQLObjectType>}PermissionConfig
Section titled “PermissionConfig”type PermissionConfig = { id: string mode: 'permissive' | 'restricted' tables?: Record<string, boolean | TableAccess>}TableAccess
Section titled “TableAccess”type TableAccess = { query?: boolean insert?: boolean update?: boolean delete?: boolean}TableOperations
Section titled “TableOperations”type TableOperations = { queries?: boolean mutations?: boolean}RelationPruneRule
Section titled “RelationPruneRule”type RelationPruneRule = false | 'leaf' | { only: string[] }HooksConfig
Section titled “HooksConfig”type HooksConfig = { [tableName: string]: TableHookConfig}TableHookConfig
Section titled “TableHookConfig”type TableHookConfig = { [K in OperationType]?: OperationHooks}OperationHooks
Section titled “OperationHooks”type OperationHooks = | { before?: BeforeHookFn; after?: AfterHookFn } | { resolve: ResolveHookFn }BeforeHookFn
Section titled “BeforeHookFn”type BeforeHookFn = ( ctx: HookContext,) => Promise<BeforeHookResult | undefined> | BeforeHookResult | undefinedAfterHookFn
Section titled “AfterHookFn”type AfterHookFn = (ctx: AfterHookContext) => Promise<any> | anyResolveHookFn
Section titled “ResolveHookFn”type ResolveHookFn = (ctx: ResolveHookContext) => Promise<any> | anyHookContext
Section titled “HookContext”type HookContext = { args: any context: any info: GraphQLResolveInfo}AfterHookContext
Section titled “AfterHookContext”type AfterHookContext = { result: any beforeData: any context: any info: GraphQLResolveInfo}ResolveHookContext
Section titled “ResolveHookContext”type ResolveHookContext = HookContext & { defaultResolve: (overrideArgs?: any) => Promise<any>}OperationType
Section titled “OperationType”type OperationType = | 'query' | 'querySingle' | 'count' | 'insert' | 'insertSingle' | 'update' | 'delete'BeforeHookResult
Section titled “BeforeHookResult”type BeforeHookResult = { args?: any data?: any}CodegenOptions
Section titled “CodegenOptions”type CodegenOptions = { drizzle?: { importPath: string typeNames?: Record<string, string> }}