import type { ClassType, ApplicationOptions, Token, ApplicationContext } from '@nl-framework/core'; import type { GraphQLFormattedError } from 'graphql'; import type { IncomingMessage, ServerResponse } from 'node:http'; import type { RequestContext } from '@nl-framework/http'; import { type GraphqlBuildOptions } from './schema-builder'; import type { WebSocketHandler } from 'bun'; import { type PubSub } from './subscriptions/pubsub'; import { type GraphqlWsData } from './subscriptions/ws-transport'; import './scalars'; export interface GraphqlSubscriptionsOptions { /** WebSocket upgrade path. Defaults to the GraphQL HTTP path. */ path?: string; /** * Runs on `connection_init`. Return `false` to reject the socket, or an object * merged into the connection context (do Better Auth session lookup here). */ onConnect?: (ctx: { connectionParams?: Record; request: Request; }) => boolean | Record | Promise>; } export interface GraphqlServerOptions { host?: string; port?: number; path?: string; federation?: GraphqlBuildOptions['federation']; context?: GraphqlContextFactory; /** Pub/sub backing `@Subscription()`. Falls back to the `GRAPHQL_PUBSUB` provider, then in-memory. */ pubsub?: PubSub; /** Enable `graphql-ws` subscriptions on `listen()` (`true` or config). */ subscriptions?: boolean | GraphqlSubscriptionsOptions; } export interface GraphqlApplicationOptions extends ApplicationOptions, GraphqlServerOptions { } export interface GraphqlListenResult { url: string; } export interface GraphqlContextBase { req: IncomingMessage; res: ServerResponse; } export type GraphqlContext = GraphqlContextBase & Record; export type GraphqlContextFactory = (params: GraphqlContextBase) => Promise> | Record; export interface GraphqlExecuteParams { query: string; variables?: Record; operationName?: string; /** Extra values merged onto the GraphQL context (after any configured context factory). */ contextValue?: Record; /** Header map exposed to the node-like request stub for context factories. */ headers?: Record; } export interface GraphqlExecuteResult> { data: TData | null; errors?: GraphQLFormattedError[]; extensions?: Record; } export declare class GraphqlApplication { private readonly context; private readonly options; private readonly ownsContext; private apolloServer?; private apolloServerStarted; private startPromise?; private logger; private readonly unsubscribeModuleListener; private pubsub?; private executableSchema?; private wsServer?; constructor(context: ApplicationContext, options: GraphqlServerOptions, ownsContext: boolean); createHttpHandler(path?: string): Promise<(ctx: RequestContext) => Promise>; /** * Execute a GraphQL operation in-process via Apollo's `executeOperation`, with * no HTTP server or port. The framework's scoped container resolver is attached * to the context so guards, interceptors, and field resolvers run exactly as * they would over HTTP. Intended for `@nl-framework/testing`. */ execute>(params: GraphqlExecuteParams): Promise>; get(token: Token): Promise; getConfig>(): import("@nl-framework/core").ConfigService; /** Resolve the pub/sub: explicit option → `GRAPHQL_PUBSUB` provider → in-memory. */ private resolvePubSub; private buildRequestContext; /** * Build Bun WebSocket handlers speaking `graphql-transport-ws` for this * schema, for callers that already own the HTTP server — the platform HTTP * integration mounts GraphQL as a route handler rather than calling * {@link listen}, so it never gets that method's WebSocket upgrade. This lets * such a caller upgrade subscription sockets on its existing Bun server. * * Returns `undefined` when subscriptions are not enabled (the `subscriptions` * option is falsy) or the schema has not built. The caller upgrades requests * whose path matches `path` with `server.upgrade(request, { data: * upgradeData(request) })` and installs `websocket` on its Bun server. * * `overrides.onConnect` wins over the configured `subscriptions.onConnect`, so * auth (e.g. a Better Auth session lookup) can be supplied after the container * is built rather than threaded through factory options. */ createSubscriptionWsHandlers(overrides?: { onConnect?: GraphqlSubscriptionsOptions['onConnect']; }): Promise<{ websocket: WebSocketHandler; upgradeData: (request: Request) => GraphqlWsData; path: string; } | undefined>; /** * Bind a Bun server that serves GraphQL over HTTP and — when `subscriptions` * is enabled — upgrades `graphql-transport-ws` WebSocket connections on the * same port. Returns the public URL. */ listen(port?: number): Promise; close(): Promise; private ensureApolloServer; private invalidateSchema; private normalizePath; private createHttpGraphqlRequest; private resolveRequestBody; private normalizeRequestBody; private createNodeIncomingRequest; private createServerResponseStub; private toResponse; } export declare const createGraphqlApplication: (rootModule: ClassType, options?: GraphqlApplicationOptions) => Promise; export declare const createGraphqlApplicationFromContext: (context: ApplicationContext, options?: GraphqlServerOptions) => GraphqlApplication; //# sourceMappingURL=application.d.ts.map