0

I have this code:

import { Neo4jOptions } from './../interfaces/neo4joptions.interface';
import { DynamicModule, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Connection } from 'cypher-query-builder';
import { ConnectionWithDriver, Neo4jConfig } from './neo4j-config.interface';
import { NEO4J_CONFIG, NEO4J_CONNECTION, NEO4J_OPTIONS, TYPE_DEFS } from './neo4j.constants';
import { createDatabaseConfig, ConnectionError } from './neo4j.utils';
import { QueryRepository } from './query.repository';
import { Neo4jService } from './neo4j.service';

@Module({
  providers: [QueryRepository, Neo4jService],
})
export class Neo4jModule {
  static forRootAsync( typeDefs: any, neo4jOptions?: Neo4jOptions,customConfig?: Neo4jConfig): DynamicModule {
    const providers = [
      {
        provide: NEO4J_CONFIG,
        inject: [ConfigService],
        useFactory: (configService: ConfigService) =>
          createDatabaseConfig(configService, customConfig),
      },
      {
        provide: TYPE_DEFS,
        useFactory: () => typeDefs,
      },
      {
        provide: NEO4J_OPTIONS,
        useFactory: () => neo4jOptions,
      },
      {
        provide: NEO4J_CONNECTION,
        inject: [NEO4J_CONFIG,NEO4J_OPTIONS],
        useFactory: async (config: Neo4jConfig, options: Neo4jOptions) => {
          try {
            const { host, scheme, port, username, password } = config;

            const connection = new Connection(`${scheme}://${host}:${port}`, {
              username,
              password,
              ...options
            },{}) as ConnectionWithDriver;

            await connection.driver.verifyConnectivity();    
            return connection;
          } catch (error) {
            throw new ConnectionError(error);
          }
        },
      },
    ];

    return {
      module: Neo4jModule,
      imports: [ConfigModule],
      global: true,
      providers: providers,
      exports: providers,
    };
  }
}

where I am creating a ConnectionWithDriver and then trying to verify the connection. The problem is that there seems to be a conflict in the _id types in neo4j-driver and cypher-query-builder. verifyConnectivity() gives the following error:

Property 'verifyConnectivity' does not exist on type 'never'.
  The intersection 'import("/Applications/flash/flash-gateway/node_modules/cypher-query-builder/node_modules/neo4j-driver/types/driver").Driver & import("/Applications/flash/flash-gateway/node_modules/neo4j-driver/types/driver").Driver' was reduced to 'never' because property '_id' exists in multiple constituents and is private in some.

I would appreciate any help with this.

.

MichaelE
  • 757
  • 14
  • 42
  • A stackoverflow question should only ask a single question. For #1, you may be using 2 conflicting versions of the neo4j driver. [This article](https://sylhare.github.io/2022/02/09/How-to-fix-npm-dependency-library-hell.html) may help. – cybersam Jun 06 '23 at 17:41
  • @cybersam Ok...my bad. I edited the post to just the first question. in regards to your suggestion I am only using the neo4j-driver. From my understanding Neo4jGraphQL uses neo4j-driver under the hood as well. I am not using the nest-neo4j driver. I am not sure what cyber-query-builder is doing and why it would have different type definition for _id according to the error message. – MichaelE Jun 06 '23 at 21:43

0 Answers0