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

Model.find({where: {id}}) returns wrong output. #5078

Closed
gethassaan opened this issue May 5, 2024 · 6 comments
Closed

Model.find({where: {id}}) returns wrong output. #5078

gethassaan opened this issue May 5, 2024 · 6 comments
Labels
bug report Something isn't working unreproducible Based on the information given, unable to reproduce at this time

Comments

@gethassaan
Copy link

gethassaan commented May 5, 2024

Describe the bug
I have an application using Nestjs, Graphql and Neo4j. It has a user model and I have used @neo4j/graphql-ogm package and it's generate function to generate OGM object. When I try to get the user by id using find function it returns wrong result.

Type definitions

type User {
    id: ID! @id
    firstName: String!
    lastName: String!
    email: String! @unique
}

To Reproduce
Steps to reproduce the behavior:

  • first create a couple of users using the above scehma.
  • then use the below given code try to fetch the user by id (for me it's returning the first user everytime instead of returning the user with matching id)
const User = (await this.neo4jService.ogm).model('User');
//  find user by id is not returning right user
const [record] = await User.find({
  where: { id: id },
});
  1. See error

Expected behavior
The function should return the result with the passed id.

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot 2024-05-05 at 2 21 32 PM

System (please complete the following information):

  • OS: macOS
  • Version: @neo4j/graphql@5.3.4, @neo4j/graphql-ogm@5.3.4, neo4j-driver@5.20.0
  • Node.js version: 20.10.0
@gethassaan gethassaan added the bug report Something isn't working label May 5, 2024
@neo4j-team-graphql
Copy link
Collaborator

Many thanks for raising this bug report @gethassaan. 🐛 We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

  • Type definitions
  • Resolvers
  • Query and/or Mutation (or multiple) needed to reproduce

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! 🙏

@neo4j-team-graphql neo4j-team-graphql added this to Bug reports in Bug Triage May 5, 2024
@mjfwebb mjfwebb added the unreproducible Based on the information given, unable to reproduce at this time label May 6, 2024
@mjfwebb
Copy link
Contributor

mjfwebb commented May 6, 2024

Hi @gethassaan I tried to reproduce this, but I can successfully request specific users via their IDs, without any issue.

Some thoughts:

  • Did you create the users through GraphQL? It might be an ID mismatch if you made them yourself elsewhere.
  • Can you test without having a NestJS service in between? NestJS may be causing a problem. Perhaps a cache?

@gethassaan
Copy link
Author

gethassaan commented May 6, 2024

Hey @mjfwebb, I created the user via Graphql and the ID's were auto generated and regarding the cache i'm sure it's not cache since I also tried this with a new (fresh) clone.

And as I am trying a simple query as mentioned above, I am out of clues to why this might be happening. 🥲

Can you also share how did you fetch the users? Any process or steps that you followed?

@mjfwebb
Copy link
Contributor

mjfwebb commented May 6, 2024

Sure, here's what I did:

import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import { Neo4jGraphQL } from "@neo4j/graphql";
import { OGM } from "@neo4j/graphql-ogm";
import neo4j from "neo4j-driver";

const driver = neo4j.driver(
  "bolt://localhost:7687",
  neo4j.auth.basic("username", "password")
);

const typeDefs = `#graphql
  type User {
      id: ID! @id
      firstName: String!
      lastName: String!
      email: String! @unique
  }
`;

const ogm = new OGM({ typeDefs, driver });
const User = ogm.model("User");

const resolvers = {};

const neoSchema = new Neo4jGraphQL({
  typeDefs,
  driver,
  resolvers,
});

async function main() {
  const schema = await neoSchema.getSchema();
  await ogm.init();
  const server = new ApolloServer({
    schema,
  });

  const { url } = await startStandaloneServer(server, {
    context: async ({ req }) => ({ req }),
  });

  console.log(`🚀 Server ready at ${url}`);
  const [record] = await User.find({
    where: { id: "your-id-here" },
  });

  console.log(record);
}

main();

Where you replace your-id-here with the id generated. I selected the ID from when I created the user through a mutation:

mutation Mutation {
  createUsers(
    input: [{ email: "test@example.com", firstName: "First", lastName: "Last" }]
  ) {
    users {
      id
    }
  }
}

@gethassaan
Copy link
Author

Thank you @mjfwebb your solution does work, I am not sure why would the bug be coming up. 🤔

@mjfwebb
Copy link
Contributor

mjfwebb commented May 7, 2024

@gethassaan I'll close the issue then, since we confirmed it's not on our side.

@mjfwebb mjfwebb closed this as completed May 7, 2024
@mjfwebb mjfwebb closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
@Liam-Doodson Liam-Doodson removed this from Bug reports in Bug Triage May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something isn't working unreproducible Based on the information given, unable to reproduce at this time
Projects
None yet
Development

No branches or pull requests

3 participants