UNPKG

@launchql/env

Version:

LaunchQL environment configuration with GraphQL/Graphile support

50 lines (49 loc) 2.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLaunchQLEnvOptions = exports.getEnvOptions = void 0; const deepmerge_1 = __importDefault(require("deepmerge")); const types_1 = require("@launchql/types"); const env_1 = require("@pgpmjs/env"); const env_2 = require("./env"); /** * Get LaunchQL environment options by merging: * 1. Core PGPM defaults (from @pgpmjs/env) * 2. GraphQL defaults (from @launchql/types) * 3. Config file options (including GraphQL options) * 4. Environment variables (both core and GraphQL) * 5. Runtime overrides * * This is the main entry point for LaunchQL packages that need * both core PGPM options and GraphQL/Graphile options. */ const getEnvOptions = (overrides = {}, cwd = process.cwd()) => { // Get core PGPM options (includes pgpmDefaults + config + core env vars) const coreOptions = (0, env_1.getEnvOptions)({}, cwd); // Get GraphQL-specific env vars const graphqlEnvOptions = (0, env_2.getGraphQLEnvVars)(); // Load config again to get any GraphQL-specific config // Config files can contain LaunchQL options (graphile, features, api) // even though loadConfigSync returns PgpmOptions type const configOptions = (0, env_1.loadConfigSync)(cwd); // Merge in order: core -> graphql defaults -> config (for graphql keys) -> graphql env -> overrides return deepmerge_1.default.all([ coreOptions, types_1.launchqlGraphqlDefaults, // Only merge graphql-related keys from config (if present) { ...(configOptions.graphile && { graphile: configOptions.graphile }), ...(configOptions.features && { features: configOptions.features }), ...(configOptions.api && { api: configOptions.api }), }, graphqlEnvOptions, overrides ]); }; exports.getEnvOptions = getEnvOptions; /** * Alias for backward compatibility - same as getEnvOptions */ exports.getLaunchQLEnvOptions = exports.getEnvOptions;