@newmo/graphql-fake-server
Version:
GraphQL fake server for testing
137 lines • 4.11 kB
TypeScript
import type { MockConfig, RawMockConfig } from "@newmo/graphql-fake-core";
import type { LogLevel } from "./logger.js";
/**
* Server configuration options (user input - all fields optional).
* Controls ports, request limits, and security settings.
*/
export type ServerConfig = {
/**
* The ports for the fake server and Apollo Server.
*/
ports?: {
/**
* Fake Server port.
* Default is 4000.
*/
fakeServer?: number | undefined;
/**
* Apollo Server port.
* It provides the GraphQL Playground.
* Default is 4002.
*/
apolloServer?: number | undefined;
} | undefined;
/**
* The maximum number of registered sequences.
* Default is 1000.
*/
maxRegisteredSequences?: number | undefined;
/**
* The maximum number of depth of complexity of query
* Default is 10
*/
maxQueryDepth?: number | undefined;
/**
* Additional origins to allow for CORS requests.
* By default, only localhost and private IP ranges are allowed.
* This option allows you to specify additional origins to accept.
*/
allowedCORSOrigins?: string[] | undefined;
/**
* Allowed Host headers for the fake server to prevent DNS rebinding attacks.
* - "auto" (default): Automatically generates allowed hosts from CORS origins and localhost addresses
* - string[]: Explicit list of allowed Host headers (e.g., ["localhost:4000", "myapp.local:4000"])
* @default "auto"
*/
allowedHosts?: string[] | "auto" | undefined;
};
/**
* Configuration for the fake server (user input - most fields optional).
*
* @example
* ```js
* export default {
* schemaFilePath: "./api.graphqls",
* logLevel: "debug",
* server: {
* ports: { fakeServer: 4000, apolloServer: 4002 },
* maxQueryDepth: 10,
* },
* mock: {
* maxDepth: 9,
* maxTypeRecursion: 2,
* listLength: 3,
* },
* };
* ```
*/
export type FakeServerConfig = {
/**
* The path to the GraphQL schema file from cwd.
* @required
*/
schemaFilePath: string;
/**
* Log level for the server.
* @default "info"
*/
logLevel?: LogLevel | undefined;
/**
* Server configuration options (ports, limits, security).
* @see ServerConfig
*/
server?: ServerConfig | undefined;
/**
* Mock data generation options (depth limits, default values).
* @see RawMockConfig from @newmo/graphql-fake-core
*/
mock?: RawMockConfig | undefined;
};
/**
* Server configuration (normalized - all fields required).
* @internal
*/
export type RequiredServerConfig = {
ports: {
fakeServer: number;
apolloServer: number;
};
maxRegisteredSequences: number;
maxQueryDepth: number;
allowedCORSOrigins: string[];
allowedHosts: string[] | "auto";
};
/**
* Mock configuration (normalized - all fields required).
* @internal
*/
export type RequiredMockConfig = MockConfig;
/**
* Fake server configuration (normalized - all fields required).
* This is the internal config type with defaults applied.
*
* @see FakeServerConfig for user-facing config with optional fields
* @internal
*/
export type RequiredFakeServerConfig = {
schemaFilePath: string;
logLevel: LogLevel;
server: RequiredServerConfig;
mock: RequiredMockConfig;
};
export declare const normalizeFakeServerConfig: (config: FakeServerConfig) => RequiredFakeServerConfig;
export declare const validateFakeServerConfig: (config: FakeServerConfig) => FakeServerConfig;
/**
* Load the fake server configuration from the file.
* @param configPath
*/
export declare const loadConfig: (cwd: string, configPath: string) => Promise<RequiredFakeServerConfig>;
/**
* Load the fake server configuration from the CLI flags.
* @param cliFlag
*/
export declare const loadFakeServerConfigFromCLI: ({ schemaFilePath, logLevel, }: {
schemaFilePath?: string | undefined;
logLevel?: LogLevel | undefined;
}) => RequiredFakeServerConfig;
//# sourceMappingURL=config.d.ts.map