UNPKG

@graphql-mesh/transport-mysql

Version:
32 lines (31 loc) 1.06 kB
import { process } from '@graphql-mesh/cross-helpers'; import { stringInterpolator } from '@graphql-mesh/string-interpolation'; export function getConnectionOptsFromEndpointUri(endpointUri) { endpointUri = stringInterpolator.parse(endpointUri, { env: 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: process.env.NODE_TLS_REJECT_UNAUTHORIZED === '1', }; } return { user, password, protocol, host, port: parseInt(port, 10), database, trace: !!process.env.DEBUG, debug: !!process.env.DEBUG, ssl: sslOpts, ...additionalOptions, }; }