index
Interfaces
ContextStoreOptions
Configuration options for the context store.
Properties
Property | Type | Default value | Description |
---|---|---|---|
|
|
|
Whether to load the value lazily (on first access) or eagerly (immediately). |
Options
Properties
Property | Type | Default value | Description |
---|---|---|---|
|
|
|
Array of module objects to include in the application. Example
|
|
|
Options to pass to makeExecutableSchema. See https://the-guild.dev/graphql/tools/docs/generate-schema#makeexecutableschema | |
|
|
|
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 Parameter | Description |
---|---|
|
Type of the directive arguments |
|
Type of the context |
Type declaration
Name | Type | Description |
---|---|---|
|
|
Name of the directive as it appears in the GraphQL schema (without '@' prefix) Example
|
|
|
Function that implements the directive's validation/transformation logic |
|
Validation target indicating when the directive should be applied | |
|
( |
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:
|
Middleware()<Result, Root, Context, Args>
Middleware<
Result
,Root
,Context
,Args
>: (params
,next
) =>Promise
<Result
>
Type Parameters
Type Parameter |
---|
|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Promise
<Result
>
MiddlewareNext()<T>
MiddlewareNext<
T
>: () =>Promise
<T
>
Type Parameters
Type Parameter |
---|
|
Returns
Promise
<T
>
MiddlewareParams<Root, Context, Args>
MiddlewareParams<
Root
,Context
,Args
>:object
Type Parameters
Type Parameter |
---|
|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
Resolver()<Result, Root, Context, Args>
Resolver<
Result
,Root
,Context
,Args
>: (params
) =>Result
|Promise
<Result
>
Type Parameters
Type Parameter |
---|
|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
Result
| Promise
<Result
>
ResolverParams<Root, Context, Args>
ResolverParams<
Root
,Context
,Args
>:object
Type Parameters
Type Parameter |
---|
|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
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 |
---|
|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
AsyncIterator
<Payload
> | Promise
<AsyncIterator
<Payload
>>
SubscribeParams<Root, Context, Args>
SubscribeParams<
Root
,Context
,Args
>:object
Type Parameters
Type Parameter |
---|
|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
SubscribeResolve()<Result, Payload, Context, Args>
SubscribeResolve<
Result
,Payload
,Context
,Args
>: (params
) =>Result
|Promise
<Result
>
Type Parameters
Type Parameter |
---|
|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
Result
| Promise
<Result
>
SubscribeResolveParams<Payload, Context, Args>
SubscribeResolveParams<
Payload
,Context
,Args
>:object
Type Parameters
Type Parameter |
---|
|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
Subscription<Payload, Result, Root, Context, Args>
Subscription<
Payload
,Result
,Root
,Context
,Args
>:object
Type Parameters
Type Parameter |
---|
|
|
|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
TypeResolver()<Result, Value, Context>
TypeResolver<
Result
,Value
,Context
>: (params
) =>Result
|Promise
<Result
>
Type Parameters
Type Parameter |
---|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
Result
| Promise
<Result
>
TypeResolverParams<Value, Context>
TypeResolverParams<
Value
,Context
>:object
Type Parameters
Type Parameter |
---|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
|
ValidateParams<Context>
ValidateParams<
Context
>:object
Type Parameters
Type Parameter | Default type |
---|---|
|
|
Type declaration
Name | Type |
---|---|
|
|
|
|
|
|
|
( |
|
|
|
|
ValidationDirectiveFn()<DirectiveConfig, Context>
ValidationDirectiveFn<
DirectiveConfig
,Context
>: (params
) =>void
Type Parameters
Type Parameter | Default type |
---|---|
|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
void
ValidationDirectiveFnParams<DirectiveConfig, Context>
ValidationDirectiveFnParams<
DirectiveConfig
,Context
>:ValidateParams
<Context
> &object
Type declaration
Name | Type |
---|---|
|
|
|
() => |
|
( |
Type Parameters
Type Parameter |
---|
|
|
ValidationTarget
ValidationTarget:
"list"
|"object"
|"scalar"
Functions
createApplication()
createApplication(
options
):object
Creates a Baeta application by combining the modules.
Parameters
Parameter | Type | Description |
---|---|---|
|
Configuration options for the application |
Returns
object
An object containing the GraphQL schema
Name | Type |
---|---|
schema | GraphQLSchema |
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 Parameter | Default type |
---|---|
|
‐ |
|
|
Parameters
Parameter | Type | Description |
---|---|---|
|
|
A unique symbol to identify the stored value in the context |
|
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
Parameter | Type | Description |
---|---|---|
... |
() => |
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 Parameter | Default type | Description |
---|---|---|
|
‐ |
Type of the directive configuration object |
|
|
Type of the GraphQL context |
Parameters
Parameter | Type | Description |
---|---|---|
|
|
Configuration options for the input directive |
Returns
Function
A function that transforms a GraphQL schema by applying the directive
Parameters
Parameter | Type |
---|---|
|
|
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());
},
});