@graphql-mesh/serve-cli
Version:
170 lines (169 loc) • 6.04 kB
TypeScript
import 'dotenv/config';
import { Command } from '@commander-js/extra-typings';
import type { JWTAuthPluginOptions } from '@graphql-mesh/plugin-jwt-auth';
import type { OpenTelemetryMeshPluginOptions } from '@graphql-mesh/plugin-opentelemetry';
import type { PrometheusPluginOptions } from '@graphql-mesh/plugin-prometheus';
import type useMeshRateLimit from '@graphql-mesh/plugin-rate-limit';
import type { GatewayConfigContext, GatewayConfigProxy, GatewayConfigSubgraph, GatewayConfigSupergraph } from '@graphql-mesh/serve-runtime';
import type { KeyValueCache, Logger, YamlConfig } from '@graphql-mesh/types';
import type { ServerConfig } from './server';
export type GatewayCLIConfig = (GatewayCLISupergraphConfig | GatewayCLISubgraphConfig | GatewayCLIProxyConfig) & ServerConfig & {
/**
* Count of workers to spawn. Defaults to `os.availableParallelism()` when NODE_ENV
* is "production", otherwise only one (the main) worker.
*/
fork?: number;
/**
* GraphQL schema polling interval in milliseconds.
*
* @default 10_000
*/
pollingInterval?: number;
} & GatewayCLIBuiltinPluginConfig;
export interface GatewayCLISupergraphConfig extends Omit<GatewayConfigSupergraph, 'supergraph' | 'cache'> {
/**
* SDL, path or an URL to the Federation Supergraph.
*
* Alternatively, CDN options for pulling a remote Federation Supergraph.
*
* @default 'supergraph.graphql'
*/
supergraph?: GatewayConfigSupergraph['supergraph'];
}
export interface GatewayCLISubgraphConfig extends Omit<GatewayConfigSubgraph, 'subgraph' | 'cache'> {
/**
* SDL, path or an URL to the Federation Supergraph.
*
* Alternatively, CDN options for pulling a remote Federation Supergraph.
*
* @default 'subgraph.graphql'
*/
subgraph?: GatewayConfigSubgraph['subgraph'];
}
export interface GatewayCLIProxyConfig extends Omit<GatewayConfigProxy, 'proxy' | 'cache'> {
/**
* HTTP executor to proxy all incoming requests to another HTTP endpoint.
*/
proxy?: GatewayConfigProxy['proxy'];
}
export interface GatewayCLIBuiltinPluginConfig {
/**
* Configure JWT Auth
*
* [Learn more](https://graphql-hive.com/docs/gateway/authorization-authentication)
*/
jwt?: JWTAuthPluginOptions;
/**
* Configure Prometheus metrics
*
* [Learn more](https://graphql-hive.com/docs/gateway/monitoring-tracing)
*/
prometheus?: Exclude<PrometheusPluginOptions, GatewayConfigContext>;
/**
* Configure OpenTelemetry
*
* [Learn more](https://graphql-hive.com/docs/gateway/monitoring-tracing)
*/
openTelemetry?: Exclude<OpenTelemetryMeshPluginOptions, GatewayConfigContext>;
/**
* Configure Rate Limiting
*
* [Learn more](https://graphql-hive.com/docs/gateway/other-features/security/rate-limiting)
*/
rateLimiting?: Exclude<Parameters<typeof useMeshRateLimit>[0], GatewayConfigContext>;
/**
* Enable Just-In-Time compilation of GraphQL documents.
*
* [Learn more](https://github.com/zalando-incubator/graphql-jit?tab=readme-ov-file#benchmarks)
*/
jit?: boolean;
cache?: KeyValueCache | GatewayCLILocalforageCacheConfig | GatewayCLIRedisCacheConfig | GatewayCLICloudflareKVCacheConfig;
}
export type GatewayCLILocalforageCacheConfig = YamlConfig.LocalforageConfig & {
type: 'localforage';
};
export type GatewayCLIRedisCacheConfig = YamlConfig.RedisConfig & {
type: 'redis';
};
export type GatewayCLICloudflareKVCacheConfig = YamlConfig.CFWorkersKVCacheConfig & {
type: 'cfw-kv';
};
/**
* Type helper for defining the config.
*/
export declare function defineConfig(config: GatewayCLIConfig): GatewayCLIConfig;
/** The context of the running program. */
export interface CLIContext {
/** @default new DefaultLogger() */
log: Logger;
/** @default 'Mesh Serve' */
productName: string;
/** @default 'serve GraphQL federated architecture for any API service(s)' */
productDescription: string;
/** @default '@graphql-mesh/serve-cli' */
productPackageName: string;
/** @default Mesh logo */
productLogo?: string;
/** @default https://the-guild.dev/graphql/mesh */
productLink: string;
/** @default 'mesh-serve' */
/**
* A safe binary executable name, should not contain any special
* characters or white-spaces.
*
* @default 'mesh-serve'
*/
binName: string;
/** @default 'mesh.config' */
configFileName: string;
/** @default globalThis.__VERSION__ */
version: string;
}
/** Inferred program options from the root command {@link cli}. */
export type CLIGlobals = CLI extends Command<any, infer O> ? O : never;
export type CLI = typeof cli;
export type AddCommand = (ctx: CLIContext, cli: CLI) => void;
export declare const defaultOptions: {
fork: number;
host: string;
port: number;
polling: string;
};
/** The root cli of serve-cli. */
declare let cli: Command<[], {
fork?: number;
configPath?: string;
host?: string;
port?: number;
polling?: number;
maskedErrors: boolean;
hiveRegistryToken?: string;
hivePersistedDocumentsEndpoint?: string;
hivePersistedDocumentsToken?: string;
hiveCdnEndpoint?: string;
hiveCdnKey?: string;
apolloGraphRef?: string;
apolloKey?: string;
disableWebsockets?: true;
jit?: true;
}>;
export declare function run(userCtx: Partial<CLIContext>): Promise<Command<[], {
fork?: number;
configPath?: string;
host?: string;
port?: number;
polling?: number;
maskedErrors: boolean;
hiveRegistryToken?: string;
hivePersistedDocumentsEndpoint?: string;
hivePersistedDocumentsToken?: string;
hiveCdnEndpoint?: string;
hiveCdnKey?: string;
apolloGraphRef?: string;
apolloKey?: string;
disableWebsockets?: true;
jit?: true;
}>>;
export declare function handleNodeWarnings(): void;
export declare function enableModuleCachingIfPossible(): void;
export {};