Skip to main content

index

Interfaces

ContextStoreOptions

Configuration options for the context store.

Properties

PropertyTypeDefault valueDescription

lazy?

boolean

true;

Whether to load the value lazily (on first access) or eagerly (immediately).


Options

Properties

PropertyTypeDefault valueDescription

modules

Record<string, unknown>[]

undefined

Array of module objects to include in the application.

Example

const modules = [userModule, postModule, commentModule];

executableSchemaOptions?

ExecutableSchemaOptions

undefined

Options to pass to makeExecutableSchema. See https://the-guild.dev/graphql/tools/docs/generate-schema#makeexecutableschema

pruneSchema?

boolean

false;

When true, removes fields that don't have corresponding resolvers.

Type Aliases

ExecutableSchemaOptions

ExecutableSchemaOptions: Omit<IExecutableSchemaDefinition, "typeDefs" | "resolvers">


InputDirectiveOptions<DirectiveConfig, Context>

InputDirectiveOptions<DirectiveConfig, Context>: object

Configuration options for creating an input directive.

Type Parameters

Type ParameterDescription

DirectiveConfig

Type of the directive arguments

Context

Type of the context

Type declaration

NameTypeDescription

name

string

Name of the directive as it appears in the GraphQL schema (without '@' prefix)

Example

'trim' for '@trim' directive

resolve

ValidationDirectiveFn<DirectiveConfig, Context>

Function that implements the directive's validation/transformation logic

target

ValidationTarget

Validation target indicating when the directive should be applied

getListDepth?

(config) => number

Returns the depth of list of lists validated by this directive. The depth 0 indicates the topmost list of a field or argument. The depth 1 indicates the first nested list. The depth 2 indicates the second nested list, and so on.

The directive config is provided as an argument, so depth can be based on directive arguments.

So in the following example:

input Input {
list: [[[String!]!]!]! @validList(maxItems: 2, listDepth: 0) @validList(maxItems: 5, listDepth: 1) @validList(maxItems: 3, listDepth: 2)
}

Middleware()<Result, Root, Context, Args>

Middleware<Result, Root, Context, Args>: (params, next) => Promise<Result>

Type Parameters

Type Parameter

Result

Root

Context

Args

Parameters

ParameterType

params

MiddlewareParams<Root, Context, Args>

next

MiddlewareNext<Result>

Returns

Promise<Result>


MiddlewareNext()<T>

MiddlewareNext<T>: () => Promise<T>

Type Parameters

Type Parameter

T

Returns

Promise<T>


MiddlewareParams<Root, Context, Args>

MiddlewareParams<Root, Context, Args>: object

Type Parameters

Type Parameter

Root

Context

Args

Type declaration

NameType

args

Args

ctx

Context

info

GraphQLResolveInfo

root

Root


Resolver()<Result, Root, Context, Args>

Resolver<Result, Root, Context, Args>: (params) => Result | Promise<Result>

Type Parameters

Type Parameter

Result

Root

Context

Args

Parameters

ParameterType

params

ResolverParams<Root, Context, Args>

Returns

Result | Promise<Result>


ResolverParams<Root, Context, Args>

ResolverParams<Root, Context, Args>: object

Type Parameters

Type Parameter

Root

Context

Args

Type declaration

NameType

args

Args

ctx

Context

info

GraphQLResolveInfo

root

Root


ScalarResolver

ScalarResolver: GraphQLScalarType<unknown, unknown>


Subscribe()<Payload, Root, Context, Args>

Subscribe<Payload, Root, Context, Args>: (params) => AsyncIterator<Payload> | Promise<AsyncIterator<Payload>>

Type Parameters

Type Parameter

Payload

Root

Context

Args

Parameters

ParameterType

params

SubscribeParams<Root, Context, Args>

Returns

AsyncIterator<Payload> | Promise<AsyncIterator<Payload>>


SubscribeParams<Root, Context, Args>

SubscribeParams<Root, Context, Args>: object

Type Parameters

Type Parameter

Root

Context

Args

Type declaration

NameType

args

Args

ctx

Context

info

GraphQLResolveInfo

root

Root


SubscribeResolve()<Result, Payload, Context, Args>

SubscribeResolve<Result, Payload, Context, Args>: (params) => Result | Promise<Result>

Type Parameters

Type Parameter

Result

Payload

Context

Args

Parameters

ParameterType

params

SubscribeResolveParams<Payload, Context, Args>

Returns

Result | Promise<Result>


SubscribeResolveParams<Payload, Context, Args>

SubscribeResolveParams<Payload, Context, Args>: object

Type Parameters

Type Parameter

Payload

Context

Args

Type declaration

NameType

args

Args

ctx

Context

info

GraphQLResolveInfo

payload

Payload


Subscription<Payload, Result, Root, Context, Args>

Subscription<Payload, Result, Root, Context, Args>: object

Type Parameters

Type Parameter

Payload

Result

Root

Context

Args

Type declaration

NameType

resolve

SubscribeResolve<Result, Payload, Context, Args>

subscribe

Subscribe<Payload, Root, Context, Args>


TypeResolver()<Result, Value, Context>

TypeResolver<Result, Value, Context>: (params) => Result | Promise<Result>

Type Parameters

Type Parameter

Result

Value

Context

Parameters

ParameterType

params

TypeResolverParams<Value, Context>

Returns

Result | Promise<Result>


TypeResolverParams<Value, Context>

TypeResolverParams<Value, Context>: object

Type Parameters

Type Parameter

Value

Context

Type declaration

NameType

ctx

Context

info

GraphQLResolveInfo

type

GraphQLAbstractType

value

Value


ValidateParams<Context>

ValidateParams<Context>: object

Type Parameters

Type ParameterDefault type

Context

unknown

Type declaration

NameType

args

Record<string, unknown>

ctx

Context

info

GraphQLResolveInfo

path

(number | string)[]

root

unknown

type

GraphQLType


ValidationDirectiveFn()<DirectiveConfig, Context>

ValidationDirectiveFn<DirectiveConfig, Context>: (params) => void

Type Parameters

Type ParameterDefault type

DirectiveConfig

Record<string, unknown>

Context

unknown

Parameters

ParameterType

params

ValidationDirectiveFnParams<DirectiveConfig, Context>

Returns

void


ValidationDirectiveFnParams<DirectiveConfig, Context>

ValidationDirectiveFnParams<DirectiveConfig, Context>: ValidateParams<Context> & object

Type declaration

NameType

directiveConfig

DirectiveConfig

getValue

() => unknown

setValue

(newValue) => void

Type Parameters

Type Parameter

DirectiveConfig

Context


ValidationTarget

ValidationTarget: "list" | "object" | "scalar"

Functions

createApplication()

createApplication(options): object

Creates a Baeta application by combining the modules.

Parameters

ParameterTypeDescription

options

Options

Configuration options for the application

Returns

object

An object containing the GraphQL schema

NameType
schemaGraphQLSchema

Example

const baeta = createApplication({
modules: [userModule, postModule],
});

const { schema } = baeta;

createContextStore()

createContextStore<T, Context>(key, options?): readonly [(ctx) => Promise<T>, (_ctx, loader) => void]

Creates a context store for managing asynchronous values within a context object. See https://baeta.io/docs/guides/context-store

Type Parameters

Type ParameterDefault type

T

Context

unknown

Parameters

ParameterTypeDescription

key

symbol

A unique symbol to identify the stored value in the context

options?

ContextStoreOptions

Configuration options for the store

Returns

readonly [(ctx) => Promise<T>, (_ctx, loader) => void]

A tuple containing get and load functions for managing the stored value

Example

// Create a store for user data
const userStoreKey = Symbol("userStore");
const [getUser, loadUser] = createContextStore<User>(userStoreKey, {
lazy: true,
});

// Initialize the store when you create the context
loadUser(ctx, async () => {
return fetchUser(userId);
});

// Later, retrieve the user in a resolver
const user = await getUser(ctx);

createExtensions()

createExtensions(...extensions): () => Extension[]

Creates a collection of Baeta extensions to be used in modules. The result must be exported as default, and the file path registered in baeta.ts. See https://baeta.io/docs/extensions/

Parameters

ParameterTypeDescription

...extensions

() => Extension[]

Array of extension factory functions

Returns

() => Extension[]

Array of extension factory functions that can be used by Baeta modules

Example

// auth-extension.ts
export const authExt = authExtension(...);

// cache-extension.ts
export const cacheExt = cacheExtension(...);

// extensions.ts
import { createExtensions } from '@baeta/core';
import { authExt } from './auth-extension.ts';
import { cacheExt } from './cache-extension.ts';

export default createExtensions(authExt, cacheExt);

Remarks

Extensions are executed in the order they are provided.


createInputDirective()

createInputDirective<DirectiveConfig, Context>(options): (schema) => GraphQLSchema

Creates a schema transformer that applies an input directive to a GraphQL schema. The directive can be used to validate or transform input fields, arguments, and input types. See https://baeta.io/docs/guides/directives and https://baeta.io/docs/guides/input-directives

Type Parameters

Type ParameterDefault typeDescription

DirectiveConfig

Type of the directive configuration object

Context

unknown

Type of the GraphQL context

Parameters

ParameterTypeDescription

options

InputDirectiveOptions<DirectiveConfig, Context>

Configuration options for the input directive

Returns

Function

A function that transforms a GraphQL schema by applying the directive

Parameters
ParameterType

schema

GraphQLSchema

Returns

GraphQLSchema

Example

const trimDirective = createInputDirective<TrimArgs>({
name: "trim",
target: "scalar",
resolve(params) {
const value = params.getValue();

if (typeof value !== "string") {
return;
}

const config = params.directiveConfig;

if (config.start === true && config.end !== true) {
return params.setValue(value.trimStart());
}
if (config.end === true && config.start !== true) {
return params.setValue(value.trimEnd());
}

params.setValue(value.trim());
},
});