andreachild commented on code in PR #3238: URL: https://github.com/apache/tinkerpop/pull/3238#discussion_r2421714633
########## gremlin-mcp/src/main/javascript/src/gremlin/connection.ts: ########## @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @fileoverview Provides a live implementation of the GremlinClient service. + * + * This module defines the `GremlinClientLive` layer, which is responsible for + * creating and managing the lifecycle of a Gremlin database connection. + * The layer uses `Effect.Layer` to provide the `GremlinClient` service + * to the application's context, ensuring that the connection is acquired + * when the layer is built and released when the application shuts down. + */ + +import { Effect, Layer, Option, Redacted } from 'effect'; +import gremlin from 'gremlin'; +import { AppConfig } from '../config.js'; +import { Errors } from '../errors.js'; +import { GremlinClient } from './client.js'; +import type { ConnectionState } from './types.js'; + +const { Client, DriverRemoteConnection } = gremlin.driver; +const { AnonymousTraversalSource } = gremlin.process; + +/** + * Creates and tests a Gremlin connection. + * + * This effect is responsible for establishing a connection to the Gremlin + * server, creating a client and a graph traversal source (`g`), and then + * testing the connection to ensure it is functional before it is used. + * + * @param config The application configuration containing Gremlin connection details. + * @returns An `Effect` that resolves to a `ConnectionState` object or fails with a `GremlinConnectionError`. + */ +const makeConnection = Effect.gen(function* () { + const config = yield* AppConfig; + const protocol = config.gremlin.useSSL ? 'wss' : 'ws'; + const url = `${protocol}://${config.gremlin.host}:${config.gremlin.port}/gremlin`; + const traversalSource = config.gremlin.traversalSource; + + yield* Effect.logInfo('Acquiring Gremlin connection', { + host: config.gremlin.host, + port: config.gremlin.port, + ssl: config.gremlin.useSSL, + traversalSource: config.gremlin.traversalSource, + }); + + const auth = Option.zipWith( + config.gremlin.username, + config.gremlin.password, + (username, password) => ({ username, password: Redacted.value(password) }) + ); + + const connection = yield* Effect.try({ + try: () => + new DriverRemoteConnection(url, { + traversalSource, + auth: Option.getOrUndefined(auth), Review Comment: Is this correct authentication param for gremlin-javascript driver? According to the docs the options should include `authenticator` not `auth`? https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-connecting -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
