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

Wrong node name used for end node in rich relationship #295

Closed
ghost opened this issue Aug 24, 2023 · 1 comment · Fixed by #301
Closed

Wrong node name used for end node in rich relationship #295

ghost opened this issue Aug 24, 2023 · 1 comment · Fixed by #301
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Aug 24, 2023

Description
In our schema we have defined rich relationship. When we are trying to filter on the end node of the relationship, it is throwing error.

GraphQL schema

type Person{
    name: String
    age: Int
    rel_has_target_book: [Person_HAS_Target_Book]
}

type Book{
    name: String
    price: Int
}

type Person_HAS_Target_Book @relation(name: "HAS", from: "source", to: "target", direction: OUT) {
    name: String
    source: Person
    target: Book
}

GraphQL request

query{
  person{
    name
    rel_has_target_book(where:{target:{name:"Book 1"}}){
      target{
        name
      }
    }
  }
}

Generated Cypher query
Here, "personRel_has_target_bookTarget" is the variable name for Book but in the where condition, "personRel_has_target_bookBook" is being used

MATCH (person:Person)
CALL {
    WITH person
    MATCH (person)-[personRel_has_target_book:HAS]->(personRel_has_target_bookTarget:Book)
    WHERE personRel_has_target_bookBook.name = $personRel_has_target_bookBookName
    RETURN collect(personRel_has_target_book {
        target: personRel_has_target_bookTarget {
            .name
        }
    }) AS personRel_has_target_book
}
RETURN person {
    .name,
    rel_has_target_book: personRel_has_target_book
} AS person

Variables: {personRel_has_target_bookBookName=Book 1}

Expected cypher query

MATCH (person:Person)
CALL {
    WITH person
    MATCH (person)-[personRel_has_target_book:HAS]->(personRel_has_target_bookBook:Book)
    WHERE personRel_has_target_bookBook.name = $personRel_has_target_bookBookName
    RETURN collect(personRel_has_target_book {
        target: personRel_has_target_bookBook {
            .name
        }
    }) AS personRel_has_target_book
}
RETURN person {
    .name,
    rel_has_target_book: personRel_has_target_book
} AS person

Variables: {personRel_has_target_bookBookName=Book 1}

Additional context
We looked into the codebase.
In the file "ProjectionBase.kt", if we modify the below line in the function "projectRichAndRegularRelationship", then the correct cypher query is being generated.

Before: node(label).named("$childVariable${relInfo.endField.capitalize()}") to relInfo.endField

After: node(label).named("$childVariable${label.capitalize()}") to label

@ghost
Copy link
Author

ghost commented Aug 24, 2023

Hi @Andy2003
I have raised a PR (#296) to solve this issue. If you find the implementation proper, it can be merged.
Thanks

@Andy2003 Andy2003 added the bug Something isn't working label Sep 8, 2023
@Andy2003 Andy2003 changed the title Wrong variable name generating for end node in rich relationship Wrong node name used for end node in rich relationship Sep 12, 2023
Andy2003 added a commit that referenced this issue Sep 12, 2023
This bugfix fixes an issue where the name of the end-node of a relation is not correctly used in the where clause

resolves #295
Andy2003 added a commit that referenced this issue Sep 12, 2023
This bugfix fixes an issue where the name of the end-node of a relation is not correctly used in the where clause

resolves #295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant