UNPKG

@composedb/server

Version:
59 lines (58 loc) 2.17 kB
/** * ComposeDB server for hybrid execution on the {@linkcode client ComposeDB client}. * * ## Installation * * ```sh * npm install @composedb/server * ``` * * @module server */ import type { DocumentCache } from '@composedb/loader'; import { type Context } from '@composedb/runtime'; import type { CeramicAPI, RuntimeCompositeDefinition } from '@composedb/types'; import type { GraphQLSchema } from 'graphql'; import { type YogaServerInstance, type YogaServerOptions } from 'graphql-yoga'; /** * Returns the viewer ID sent by the client, if set. */ export declare function getViewerID(request: Request): string | null | undefined; export type HandlerParams<ServerContext extends Record<string, unknown> = Record<string, unknown>> = { /** * Optional cache for documents. */ cache?: DocumentCache; /** * Ceramic client instance or HTTP URL. */ ceramic: CeramicAPI | string; /** * Runtime composite definition, created using the {@linkcode devtools.Composite Composite} * development tools. */ definition?: RuntimeCompositeDefinition; /** * {@link https://the-guild.dev/graphql/yoga-server/docs Yoga server} options. */ options?: YogaServerOptions<ServerContext, Context>; /** * GraphQL Schema to use, ignores the `definition` parameter if provided. */ schema?: GraphQLSchema; }; /** * Create a {@link https://the-guild.dev/graphql/yoga-server/docs Yoga server} handling GraphQL requests. */ export declare function createHandler<ServerContext extends Record<string, unknown> = Record<string, unknown>>(params: HandlerParams<ServerContext>): YogaServerInstance<ServerContext, Context>; export type GraphQLServer = { port: number; stop: () => Promise<void>; }; export type GraphQLParams<ServerContext extends Record<string, unknown> = Record<string, unknown>> = HandlerParams<ServerContext> & { port?: number | Array<number>; }; /** * Start a local GraphQL server. */ export declare function startGraphQLServer<ServerContext extends Record<string, unknown> = Record<string, unknown>>(params: GraphQLParams<ServerContext>): Promise<GraphQLServer>;