@btravstack/graphql-server
@btravstack/graphql-server
Type Aliases
GraphqlContext
type GraphqlContext<Principal, Unit> = object;Defined in: graphql.ts:130
The context graphql() hands Yoga for an operation: what a resolver and a plugin's operation hooks (onParse, onValidate, onContextBuilding, onExecute, onSubscribe) read beside Yoga's own request. principal is the caller requires resolved, undefined without requires; unit is the unit record read off the forked kind; incoming is the Node request.
Those hooks run only once the caller is authenticated. A preflight and a refusal end in Yoga's server hooks (onRequest, onResponse), whose context is not this type, so a plugin cannot claim a principal there.
Type Parameters
| Type Parameter | Default type |
|---|---|
Principal | unknown |
Unit | Readonly<Record<string, unknown>> |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
incoming | readonly | IncomingMessage | graphql.ts:132 |
principal | readonly | Principal | graphql.ts:131 |
signal | readonly | AbortSignal | graphql.ts:134 |
unit | readonly | Unit | graphql.ts:133 |
GraphqlOptions
type GraphqlOptions<A, Units, R, U, PS> = object;Defined in: graphql.ts:163
Serve a GraphQL schema as one answerer under the existing HTTP runtime.
Type Parameters
| Type Parameter | Default type |
|---|---|
A extends Authenticators | - |
Units extends UnitsOf<A> | - |
R extends Requirements & { readonly [I in keyof R]: OneScheme<R[I]> } | - |
U extends Readonly<Record<string, AnyPort>> | - |
PS extends readonly unknown[] | readonly Plugin[] |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
cors? | readonly | YogaCors | - | graphql.ts:172 |
developerTools? | readonly | boolean | GraphiQL, introspection and the "Did you mean …" suggestions in an error, all or none — pins GRAPHQL_DEVELOPER_TOOLS, which defaults to false, so a deployment exposes none of them unless it says so. | graphql.ts:178 |
maxTokens? | readonly | number | false | Pins GRAPHQL_MAX_TOKENS (default 1000) — the most tokens graphql-js parses in one document before refusing it, so an oversized document is refused before any validation rule runs on it. false pins the unbounded 0. | graphql.ts:185 |
plugins? | readonly | | PS & PluginsGate<PS, ContextOf<A, Units, R, U>> | readonly Plugin<YogaInitialContext & ContextOf<A, Units, R, U>>[] | Yoga plugins. Each may be typed by the context it reads — a Plugin<{ unit: … }> — and is checked against the GraphqlContext this call builds. | graphql.ts:191 |
prefix? | readonly | `/${string}` | - | graphql.ts:171 |
requires? | readonly | R & RequiresGate<R, { readonly [K in keyof A]: A[K]["scope"] }> | - | graphql.ts:196 |
schema | readonly | GraphQLSchema | - | graphql.ts:170 |
unit? | readonly | U & UnitGate<U, Units, KindOf<R>> | - | graphql.ts:195 |
units? | readonly | Units & { readonly [K in Exclude<keyof Units, Kinds<A>>]: never } | - | graphql.ts:194 |
Functions
fieldResult()
function fieldResult<T>(result): Promise<T>;Defined in: field.ts:21
A resolver's answer from a Result, so a modeled failure is never thrown by hand. Ok is the field's value. Err is the GraphQLError the resolver's own triage minted from its E — an exhaustive mapErrCases, or flatMapErrCases where one refusal is Ok(null), so widening E fails every resolver that folds it — and GraphQL reports it on this field's path, aliases and list indexes included, while its siblings resolve: its message and extensions reach the client, its originalError does not. A defect is masked to Unexpected error. whatever its cause, and graphql() reports it to Observers.
It answers a Promise, and that is the boundary: a GraphQL resolver returns a value or a promise and reports a field's error by rejecting, so this is where a Result leaves for GraphQL's own channel — the one place a resolver needs, as runMain is for a process.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
result | | AsyncResult<T, GraphQLError> | Result<T, GraphQLError> |
Returns
Promise<T>
graphql()
function graphql<A, Units, R, U, PS>(api, options): Provider<HttpHandler, ConfigInvalid,
| EnvReading<never, "GRAPHQL_DEVELOPER_TOOLS" | "GRAPHQL_MAX_TOKENS">
| HttpConfig
| HttpUnit
| Observers
| UnitsNeedsOf<Units>
| SchemePortsOf<R>
| Scope> & object;Defined in: graphql.ts:199
Type Parameters
| Type Parameter | Default type |
|---|---|
A extends Readonly<Record<string, Authenticator<unknown, string, unknown, unknown>>> | - |
Units extends Partial<Readonly<Record<Kinds<A>, AnyUnitModule>>> | Record<never, never> |
R extends Requirements & { readonly [I in string | number | symbol]: OneScheme<R[I]> } | never |
U extends Readonly<Record<string, AnyPort>> | Record<never, never> |
PS extends readonly unknown[] | [] |
Parameters
| Parameter | Type |
|---|---|
api | HttpAuth<A> |
options | GraphqlOptions<A, Units, R, U, PS> |
Returns
Provider<HttpHandler, ConfigInvalid, | EnvReading<never, "GRAPHQL_DEVELOPER_TOOLS" | "GRAPHQL_MAX_TOKENS"> | HttpConfig | HttpUnit | Observers | UnitsNeedsOf<Units> | SchemePortsOf<R> | Scope> & object
GraphqlModule()
function GraphqlModule<Name>(name): <A, I, P, X, N>(options) => Module<ResolvedExports<readonly [typeof HttpRuntime, typeof HttpHandler,
| Logger extends Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>> ? typeof Logger : never
| HealthChecks extends Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>> ? typeof HealthChecks : never, X]>,
| ErrOf<A | AuthOf<A> | P[number]>
| ErrOfModule<readonly [I, HttpStarter<UnitsOf<A>>][number]>,
| Exclude<NeedOf<A | AuthOf<A> | P[number]>, Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>>>
| Exclude<NeedsOfModule<readonly [I, HttpStarter<UnitsOf<A>>][number]>, Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>>>>;Defined in: graphql-module.ts:56
Declare a GraphQL HTTP application without repeating runtime or authenticator wiring.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type |
|---|---|
name | Name |
Returns
<A, I, P, X, N>(options) => Module<ResolvedExports<readonly [typeof HttpRuntime, typeof HttpHandler, | Logger extends Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>> ? typeof Logger : never | HealthChecks extends Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>> ? typeof HealthChecks : never, X]>, | ErrOf<A | AuthOf<A> | P[number]> | ErrOfModule<readonly [I, HttpStarter<UnitsOf<A>>][number]>, | Exclude<NeedOf<A | AuthOf<A> | P[number]>, Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>>> | Exclude<NeedsOfModule<readonly [I, HttpStarter<UnitsOf<A>>][number]>, Available<readonly [I, HttpStarter<UnitsOf<A>>], Provides<P, A>>>>