@graphql-mesh/transport-mysql
Version:
36 lines (35 loc) • 1.37 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConnectionOptsFromEndpointUri = getConnectionOptsFromEndpointUri;
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
const fetch_1 = require("@whatwg-node/fetch");
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 fetch_1.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,
};
}
;