Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PersistenceManager:default can't be resolved #47

Closed
myflowpl opened this issue Jun 9, 2020 · 10 comments
Closed

PersistenceManager:default can't be resolved #47

myflowpl opened this issue Jun 9, 2020 · 10 comments

Comments

@myflowpl
Copy link
Collaborator

myflowpl commented Jun 9, 2020

PersistenceManager:default can't be resolved if you don't use @InjectPersistenceManager() before DrivineModule.withOptions()

It was working be course we were importing Repositories with @InjectPersistenceManager() decorator, but if you run DrivineModule.withOptions() before importing the Repository, the default provider will be not defined

@jasperblues I'm working on the PR with e2e tests to illustrate the issue, if you can check it out, for you it should be quicker to debug

@Vincent-Alexandrine
Copy link

Hey,

I'm currently facing kinda the same issue, but with a slightly different log

[Nest] 15904   - 12/13/2020, 20:06:52   [NestFactory] Starting Nest application...
[Nest] 15904   - 12/13/2020, 20:06:52   [ExceptionHandler] Nest can't resolve dependencies of the PersistenceManagerFactory (?, TransactionContextHolder). Please make sure that the argument dependency at index [0] is available in the DrivineModule context.

It refers to the PersistenceManagerFactory when I'm not directly usnig it.

I'm trying to have nest, drivine and graphql running together, but when starting the app, it logs this error. (Afterward, I'll have some "service" files, but they does corresponds to the resolvers files like in the drivine-insipration, but named differently for avoiding confusion with graphql).

My current stack is:

  • "@nestjs/core": "^7.0.0"
  • "@liberation-data/drivine": "^2.1.3"
  • "neo4j-driver": "^4.1.1"
    and
  • yanr2: "1.22.10"

When I'm cloning the repo drivine-inspiration and running it, it does start like a charm; but in this case, I'm first creating a nest app, then adding drivine, with the config set from the .env in the app.module, then used in another file, user.service (the same as a resolver, just the name changing)

Here is the app.module:

@Module({
  imports: [
    ConfigModule.forRoot(),

    GraphQLModule.forRoot({
      typePaths: ['./**/*.graphql'],
      definitions: {
        path: join(process.cwd(), 'src/graphql.ts'),
      },
      include: [UserModule],
    }),

    DrivineModule.withOptions(<DrivineModuleOptions> {
      connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv()]
    }),

    UserModule,
  ],
  controllers: [AppController],

  providers: [AppService],
})
export class AppModule {}

and the user.resolver:

@Injectable()
export class UserService {
  constructor(
    @InjectPersistenceManager() readonly persistenceManager: PersistenceManager,
  ) {}

  async getAll (): Promise<User[]> {
    const spec = new QuerySpecification<any>().withStatement(`
      MATCH (user:User)
      RETURN user
    `);
    return this.persistenceManager.query<any>(spec);
  }
}

then the .env

NODE_ENV=dev
DRIVINE_LOG_LEVEL=VERBOSE

DATABASE_TYPE=NEO4J
DATABASE_USER='neo4j'
DATABASE_PASSWORD='yolo'
DATABASE_HOST='localhost'
DATABASE_PORT='7687'

Also, I would like to say that I'm an utter beginner with nestjs, drivine, yarn2 and ts: I can't really say if this is the same error or just something different ._.

@jasperblues
Copy link
Member

Hello @Vincent-Alexandrine.

Can you confirm once more that it was Drivine 2.1.3 that got installed for you?

According to the error message, NestJS can't find DatabaseRegistry, which is to be injected into PersistenceManagerFactory (the thing that emits a PersistenceManager for a given database config).

But this DatabaseRegistry is configured to be a NestJS component on startup. Look at DrivineModuleBuilder:

infrastructureProviders(): Provider[] {
        return [
            <Provider>{ provide: DatabaseRegistry, useFactory: () => DatabaseRegistry.getInstance() },
            <Provider>{ provide: TransactionContextHolder, useFactory: () => TransactionContextHolder.getInstance() },
            PersistenceManagerFactory,
            TransactionContextMiddleware,
            TransactionalPersistenceManager,
            NonTransactionalPersistenceManager
        ];
    }

^-- There it is. So what is happening here?

What we know so far:

  • Sample app is behaving correctly.
  • In your custom app (was it forked from sample app or built from scratch?) does not appear to be able to find DatabaseRegistry. DatabaseRegistry is not the configured DB, but the registry that contains all of them. Odd.

Next Steps

Is it possible you can sure the source of your app or create a cut down one that reproduces the problem?

@Vincent-Alexandrine
Copy link

Vincent-Alexandrine commented Dec 17, 2020

Hey @jasperblues ,

So I tried a couple of stuffs:

  • remove all ./node_modules and yarn.lock then reinstall, I'm still having the error
  • I created a new nest repo with nest new then installed everything with npm. Some modules haven't been installed: cli-color, class-transformer. Then I have the same error Nest can't resolve dependencies of the PersistenceManagerFactory (?, TransactionContextHolder).. Logging DatabaseRegistry.buildOrResolveFromEnv() in my app.module (after the import), will output
Neo4jConnectionProvider {
 name: 'default',
 type: 'NEO4J',
 host: 'localhost',
 port: 7687,
 user: 'neo4j',
 password: 'password',
 database: 'eternes',
 driver: Driver {
   _id: 0,
   _address: ServerAddress {
     _host: 'localhost',
     _resolved: null,
     _port: 7687,
     _hostPort: 'localhost:7687',
     _stringValue: 'localhost:7687'
   },
   _userAgent: 'neo4j-javascript/4.2.1',
   _authToken: { scheme: 'basic', principal: 'neo4j', credentials: 'password' },
   _config: {
     userAgent: 'neo4j-javascript/4.2.1',
     maxConnectionLifetime: 3600000,
     maxConnectionPoolSize: 100,
     connectionAcquisitionTimeout: 60000,
     fetchSize: 1000
   },
   _log: NoOpLogger { _level: null, _loggerFunction: null },
   _connectionProvider: null
 }
}

The same is output when I do the same in the drivine-inspiration, but in this case afterward there is the error.

Was it what you were asking for ?
Thanks for your help

@jasperblues
Copy link
Member

Wild guess based on past experience:

I suspect it might be the NestJS version. Can you try installing exactly the same version of Nest that the sample app uses?

If this is it - great, use that for now, while I find a fix for all versions.

@Vincent-Alexandrine
Copy link

I changed the nest version to the one in the drivine-inspiration (@nestjs/core, @nestjs/common, @nestjs/cli to ^7.4.4), but I'm still having the issue.

Also I don't know if it could be related, but the yarn install fails to add @liberation-data/agensgraph .

@jasperblues
Copy link
Member

Are you able to (privately) send the code or a sample app that reproduces the problem?

@sashokbg
Copy link

I am having the same problem. Was this issue resolved ?

@jasperblues
Copy link
Member

All - this issue is closed.

If you are having an issue, and you think it is a bug:

Please post exactly what you have tried, what you expected to happen, what actually happened.

If you need help learning Drivine:
Please post under the drivine stack-overflow tag. You will receive an answer just as quickly. The benefit of using StackOverflow for learning is that it is well-indexed by google, so you will help others to learn as well.

@not-Ryan
Copy link

not-Ryan commented Jun 16, 2021

For anyone still having this problem. I was able to fix this by importing modules from @liberation-data/drivine instead of nested folders within driving.
I.e.

Before (broken 👎)

import { DrivineModule } from '@liberation-data/drivine/DrivineModule';
import { DatabaseRegistry } from '@liberation-data/drivine/connection/DatabaseRegistry';

After (working 👍)

import { DrivineModule, DatabaseRegistry } from '@liberation-data/drivine';

At least, that is what fixed this for me 😊

@pfrank13
Copy link

For anyone still having this problem. I was able to fix this by importing modules from @liberation-data/drivine instead of nested folders within driving.
I.e.

Before (broken -1)

import { DrivineModule } from '@liberation-data/drivine/DrivineModule';
import { DatabaseRegistry } from '@liberation-data/drivine/connection/DatabaseRegistry';

After (working +1)

import { DrivineModule, DatabaseRegistry } from '@liberation-data/drivine';

At least, that is what fixed this for me blush

I just wasted so much time on this, wish I had looked at @not-Ryan's response earlier. My IDE didn't grap the imports from @liberation-data/drivine and that minor difference changed it all. Thanks @not-Ryan that was huge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants