UNPKG

@graphql-hive/gateway

Version:
237 lines (233 loc) • 9.06 kB
import { Command } from '@commander-js/extra-typings'; import { GatewayConfigSupergraph, GatewayConfigSubgraph, GatewayConfigProxy, GatewayConfigContext } from '@graphql-hive/gateway-runtime'; export * from '@graphql-hive/gateway-runtime'; import { JWTAuthPluginOptions } from '@graphql-mesh/plugin-jwt-auth'; export * from '@graphql-mesh/plugin-jwt-auth'; import { OpenTelemetryMeshPluginOptions } from '@graphql-mesh/plugin-opentelemetry'; export * from '@graphql-mesh/plugin-opentelemetry'; import { PrometheusPluginOptions } from '@graphql-mesh/plugin-prometheus'; export * from '@graphql-mesh/plugin-prometheus'; export { default as usePrometheus } from '@graphql-mesh/plugin-prometheus'; import useMeshRateLimit from '@graphql-mesh/plugin-rate-limit'; export { default as useRateLimit } from '@graphql-mesh/plugin-rate-limit'; import { KeyValueCache, YamlConfig, Logger } from '@graphql-mesh/types'; export { DefaultLogger, LogLevel, PubSub } from '@graphql-mesh/utils'; export { default as useHttpCache } from '@graphql-mesh/plugin-http-cache'; export { default as useDeduplicateRequest } from '@graphql-mesh/plugin-deduplicate-request'; export { default as useMock } from '@graphql-mesh/plugin-mock'; export { default as useSnapshot } from '@graphql-mesh/plugin-snapshot'; export { default as CloudflareKVCacheStorage } from '@graphql-mesh/cache-cfw-kv'; export { default as RedisCacheStorage } from '@graphql-mesh/cache-redis'; export { default as LocalForageCacheStorage } from '@graphql-mesh/cache-localforage'; export { default as WSTransport, WSTransportOptions } from '@graphql-mesh/transport-ws'; export { default as HTTPCallbackTransport, HTTPCallbackTransportOptions } from '@graphql-mesh/transport-http-callback'; export { default as HTTPTransport, HTTPTransportOptions } from '@graphql-mesh/transport-http'; interface ServerConfig { /** * Host to listen on. * * @default '127.0.0.1' on Windows, otherwise '0.0.0.0' */ host?: string; /** * Port to listen on. * * @default 4000 */ port?: number; /** * SSL Credentials for the HTTPS Server. * * If this is provided, Gateway will be over secure HTTPS instead of unsecure HTTP. */ sslCredentials?: ServerConfigSSLCredentials; /** * The size of the HTTP headers to allow * * @default 16384 */ maxHeaderSize?: number; /** * Whether to disable setting up a WebSocket server. * * @default false */ disableWebsockets?: boolean; /** * Request timeout, 0 to disable. * * @default 300000 (5 minutes) */ requestTimeout?: number; } interface ServerConfigSSLCredentials { key_file_name?: string; cert_file_name?: string; ca_file_name?: string; passphrase?: string; dh_params_file_name?: string; ssl_ciphers?: string; ssl_prefer_low_memory_usage?: boolean; } 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. * * If cache is provided in the config, the {@link supergraph} will be cached setting the TTL to this interval in seconds. * * @default 10_000 */ pollingInterval?: number; } & GatewayCLIBuiltinPluginConfig; 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']; } 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']; } interface GatewayCLIProxyConfig extends Omit<GatewayConfigProxy, 'proxy' | 'cache'> { /** * HTTP executor to proxy all incoming requests to another HTTP endpoint. */ proxy?: GatewayConfigProxy['proxy']; } 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; } type GatewayCLILocalforageCacheConfig = YamlConfig.LocalforageConfig & { type: 'localforage'; }; type GatewayCLIRedisCacheConfig = YamlConfig.RedisConfig & { type: 'redis'; }; type GatewayCLICloudflareKVCacheConfig = YamlConfig.CFWorkersKVCacheConfig & { type: 'cfw-kv'; }; /** * Type helper for defining the config. */ declare function defineConfig(config: GatewayCLIConfig): GatewayCLIConfig; /** The context of the running program. */ interface CLIContext { /** @default new DefaultLogger() */ log: Logger; /** @default 'Mesh Serve' */ productName: string; /** @default 'Federated GraphQL Gateway' */ productDescription: string; /** @default '@graphql-hive/gateway' */ productPackageName: string; /** @default 'Hive Gateway logo' */ productLogo?: string; /** @default https://the-guild.dev/graphql/hive/docs/gateway */ productLink: string; /** @default 'hive-gateway' */ /** * A safe binary executable name, should not contain any special * characters or white-spaces. * * @default 'hive-gateway' */ binName: string; /** @default 'gateway.config' */ configFileName: string; /** @default globalThis.__VERSION__ */ version: string; } /** Inferred program options from the root command {@link cli}. */ type CLIGlobals = CLI extends Command<any, infer O> ? O : never; type CLI = typeof cli; type AddCommand = (ctx: CLIContext, cli: CLI) => void; declare const defaultOptions: { fork: number; host: string; port: number; polling: string; }; /** Root cli for the gateway. */ declare let cli: Command<[], { fork?: number | undefined; configPath?: string | undefined; host: string; port?: number | undefined; polling?: number | undefined; maskedErrors: string | boolean | string[] | []; hiveRegistryToken?: string | undefined; hivePersistedDocumentsEndpoint?: string | undefined; hivePersistedDocumentsToken?: string | undefined; hiveCdnEndpoint?: string | undefined; hiveCdnKey?: string | undefined; apolloGraphRef?: string | undefined; apolloKey?: string | undefined; disableWebsockets?: true | undefined; jit?: true | undefined; }>; declare function run(userCtx: Partial<CLIContext>): Promise<Command<[], { fork?: number | undefined; configPath?: string | undefined; host: string; port?: number | undefined; polling?: number | undefined; maskedErrors: string | boolean | string[] | []; hiveRegistryToken?: string | undefined; hivePersistedDocumentsEndpoint?: string | undefined; hivePersistedDocumentsToken?: string | undefined; hiveCdnEndpoint?: string | undefined; hiveCdnKey?: string | undefined; apolloGraphRef?: string | undefined; apolloKey?: string | undefined; disableWebsockets?: true | undefined; jit?: true | undefined; }>>; declare function handleNodeWarnings(): void; declare function enableModuleCachingIfPossible(): void; export { type AddCommand, type CLI, type CLIContext, type CLIGlobals, type GatewayCLIBuiltinPluginConfig, type GatewayCLICloudflareKVCacheConfig, type GatewayCLIConfig, type GatewayCLILocalforageCacheConfig, type GatewayCLIProxyConfig, type GatewayCLIRedisCacheConfig, type GatewayCLISubgraphConfig, type GatewayCLISupergraphConfig, defaultOptions, defineConfig, enableModuleCachingIfPossible, handleNodeWarnings, run };