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.
parseResolveInfo
Section titled “parseResolveInfo”function parseResolveInfo(info: GraphQLResolveInfo): ResolveTree | nullBuilds a selection tree for the field currently being resolved. The schema builder uses it to prune columns and to derive nested relation arguments; it is exported because it is generally useful in any resolver that wants to know what the client asked for.
Fragments and inline fragments are inlined against their type condition, @skip / @include are
applied, arguments are coerced (variables and defaults included), and introspection meta-fields are
left out. Returns null when info carries no usable field node.
import { parseResolveInfo } from '@graphql-suite/schema'
const resolve = (_source, _args, _context, info) => { const tree = parseResolveInfo(info) const selected = Object.keys(tree?.fieldsByTypeName.UserSelectItem ?? {}) // ['id', 'email'] for `{ users { id email } }`}Uses only root exports of graphql, so a single copy of the library serves both graphql 16 and 17.
It replaces graphql-parse-resolve-info,
whose peer range stops at graphql 16, and produces the same ResolveTree shape.
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.
ResolveTree
Section titled “ResolveTree”type ResolveTree = { /** Field name as defined in the schema. */ name: string /** Response key — the alias when one is given, otherwise the field name. */ alias: string /** Coerced argument values, with variables and defaults already applied. */ args: Record<string, unknown> /** Sub-selection, keyed by the type name it was selected on. */ fieldsByTypeName: FieldsByTypeName}Returned by parseResolveInfo.
FieldsByTypeName
Section titled “FieldsByTypeName”type FieldsByTypeName = Record<string, Record<string, ResolveTree>>Selected sub-fields of a field, grouped by the type they were selected on. The inner key is the response key (alias when present), matching the shape of a GraphQL response.
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> }}