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

Getting Error while Creating Nodes #31

Closed
fauh45 opened this issue Jul 6, 2021 · 5 comments
Closed

Getting Error while Creating Nodes #31

fauh45 opened this issue Jul 6, 2021 · 5 comments
Labels
documentation Improvements or additions to documentation feature New feature or request

Comments

@fauh45
Copy link

fauh45 commented Jul 6, 2021

While running this code,

import "dotenv/config";

import { neogma } from "../helpers/graph";
import { Interest } from "../helpers/graph/Interest";
import { Post } from "../helpers/graph/Post";
import { User } from "../helpers/graph/User";

const testNeo4J = async () => {
  const user_1 = await User.createOne({
    id: "1",
    username: "1",
  });

  const user_2 = await User.createOne({
    id: "2",
    username: "2",
  });

  const interest = await Interest.createOne({
    id: "int",
    name: "int",
  });

  const post = await Post.createOne({
    id: "1",
    deleted: false,
  });

  await post.relateTo({
    alias: "PartOfInterest",
    where: {
      id: "int",
    },
  });

  await post.relateTo({
    alias: "PostedByUser",
    where: {
      id: "1",
    },
  });

  await user_1.relateTo({
    alias: "LikesInterest",
    where: {
      id: "int",
    },
  });

  await user_2.relateTo({
    alias: "InteractWithPost",
    where: {
      id: "1",
    },
  });

  console.log(user_1);
  console.log(user_2);
  console.log(interest);
  console.log(post);

  await user_1.delete();
  await user_2.delete();
  await interest.delete();
  await post.delete();

  await neogma.driver.close();
};

testNeo4J()
  .then(() => console.log("Done"))
  .catch((err) => console.error(err))
  .finally(() => process.exit());

I found myself with this error,

TypeError: _a.call is not a function
    at QueryRunner.log (D:\Code\<redacted>\node_modules\neogma\dist\Queries\QueryRunner\QueryRunner.js:160:68)
    at D:\Code\<redacted>\node_modules\neogma\dist\Queries\QueryRunner\QueryRunner.js:183:18
    at Object.getRunnable (D:\Code\<redacted>\node_modules\neogma\dist\Sessions\Sessions.js:50:16)
    at QueryRunner.run (D:\Code\<redacted>\node_modules\neogma\dist\Queries\QueryRunner\QueryRunner.js:170:27)
    at D:\Code\<redacted>\node_modules\neogma\dist\Queries\QueryBuilder\QueryBuilder.js:414:32
    at Object.getSession (D:\Code\<redacted>\node_modules\neogma\dist\Sessions\Sessions.js:14:30)
    at Object.getRunnable (D:\Code\<redacted>\node_modules\neogma\dist\Sessions\Sessions.js:52:20)
    at QueryBuilder.run (D:\Code\<redacted>\node_modules\neogma\dist\Queries\QueryBuilder\QueryBuilder.js:413:27)
    at Function.createMany (D:\Code\<redacted>\node_modules\neogma\dist\ModelOps\ModelOps.js:420:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
Done in 13.28s.

I've tried using Neo4J Desktop, Neo4J Sandbox, and Neo4J Aura and nothing does works, it produces the same error.

@fauh45
Copy link
Author

fauh45 commented Jul 6, 2021

Just found the problem, the logger options cannot be used with pino-logger. Sorry for this!

@fauh45 fauh45 closed this as completed Jul 6, 2021
@themetalfleece
Copy link
Owner

Hey there! I'm glad you figured this out.
But I'd like to get to the bottom of this. Could you send me the relevant code that makes it error out when you're using pino? I've never heard of it so far, and I've tried the following, which doesn't throw any errors:

import * as pino from 'pino';
const logger = pino();

export const neogma = new Neogma(
    {
        url: process.env.NEO4J_URL || '',
        username: process.env.NEO4J_USERNAME || '',
        password: process.env.NEO4J_PASSWORD || '',
    },
    {
        encrypted: false,
        logger: (v: string) => logger.info(v),
    },
);

However, the format of the logs is not right, which is brought to my attention now. It's an easy fix though, but I'll wait to see if I'm missing something with Pino which can be implemented.

@themetalfleece themetalfleece reopened this Jul 6, 2021
@fauh45
Copy link
Author

fauh45 commented Jul 7, 2021

What I was trying is actually, something like this,

import * as pino from 'pino';
const logger = pino();

export const neogma = new Neogma(
    {
        url: process.env.NEO4J_URL || '',
        username: process.env.NEO4J_USERNAME || '',
        password: process.env.NEO4J_PASSWORD || '',
    },
    {
        encrypted: false,
        logger: logger,
    },
);

Which makes the error, because it tries to call logger(val) and your code snippets would work just fine. I think what could be great is to actually have different level of logs, like with errors neogma actually call for logger.error(val), so that in production it can be controlled more easily, as the logger is a single instance, so do the log level of it.

Also a little out of topic here, but I think the docs should explain about how to handle cyclical dependencies more, or at least gave some example. Just a suggestion.

@themetalfleece themetalfleece added documentation Improvements or additions to documentation feature New feature or request labels Jul 8, 2021
@themetalfleece
Copy link
Owner

I see, I hadn't considered this level of logging but it should come in handy for sure.

I agree with the documentation issue, I've had more people look for it. It's actually mentioned in the documentation but hard to find, so a separate section for it would be much better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants