UNPKG

@graphql-mesh/transport-mysql

Version:
36 lines (35 loc) 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConnectionOptsFromEndpointUri = void 0; const cross_helpers_1 = require("@graphql-mesh/cross-helpers"); const string_interpolation_1 = require("@graphql-mesh/string-interpolation"); function getConnectionOptsFromEndpointUri(endpointUri) { endpointUri = string_interpolation_1.stringInterpolator.parse(endpointUri, { env: cross_helpers_1.process.env, }); const { username: user, password, protocol = 'mysql:', hostname: host = 'localhost', port = '3306', pathname: databasePath = '/mysql', searchParams, } = new URL(endpointUri); const additionalOptions = {}; searchParams.forEach((value, key) => { additionalOptions[key] = value; }); const database = databasePath.slice(1); let sslOpts; if (protocol === 'mysqls:') { sslOpts = { rejectUnauthorized: cross_helpers_1.process.env.NODE_TLS_REJECT_UNAUTHORIZED === '1', }; } return { user, password, protocol, host, port: parseInt(port, 10), database, trace: !!cross_helpers_1.process.env.DEBUG, debug: !!cross_helpers_1.process.env.DEBUG, ssl: sslOpts, ...additionalOptions, }; } exports.getConnectionOptsFromEndpointUri = getConnectionOptsFromEndpointUri;