grand-stack / grand-stack-starter

Simple starter project for GRANDstack full stack apps
https://grandstack.io/docs/getting-started-grand-stack-starter.html
Apache License 2.0
504 stars 161 forks source link

Why can't I query relationships of neo4j with custom query with cypher using Grandstack? #158

Closed jilink closed 2 years ago

jilink commented 2 years ago

Hi! it's been a week struggling with this issue, I've posted twice on stack overflow and finally somobody advised me to report this as a bug since There's nothing that looks wrong https://stackoverflow.com/questions/69775011/how-to-query-relationships-of-neo4j-with-custom-query-with-cypher-using-grandsta/69779442?noredirect=1#comment123345818_69779442

So I have these models :


type User {
  userId: ID!
  mail: String!
  password: String! @private
  meals: [Meal!] @relationship(type: "IN_MEALS", direction: OUT)
}

type Meal {
  name: String!
  createdBy: User! @relationship(type: "IN_MEALS", direction: IN)
}

The relationship is made in neo4j and when I query all users but when I use this custom query for the custom users, meals are defined as null I don't know why


type Query {
  currentUser: User
    @cypher(
      statement: """
      MATCH (u:User {userId: $auth.jwt.userId})
      OPTIONAL MATCH (u)-[r:IN_MEALS]->(m:Meal)
      RETURN u,r,m  
      """
    )
}
When I do this query in graphql

{
  currentUser {
    userId
    mail
    meals {
      name
    }
  }
}

It tells me that meals are null but they are not ...


{
  "data": {
    "currentUser": {
      "userId": "02e7b50a-1a51-4d3b-b26b-57ed08d89c5a",
      "mail": "mak@gmail.com",
      "meals": null
    }
  }
}

I know that by looking into my neo4j database and also because when I query all users


{
  users {
    mail
    meals {
      name
    }
  }
}

I can see the values in meals :


{
  "data": {
    "users": [
      {
        "mail": "mak@gmail.com",
        "meals": [
          {
            "name": "frites"
          },
          {
            "name": "mcdo"
          },
          {
            "name": "sushi"
          }
        ]
      }
    ]
  }
}

Thanks in advance and don't hesitate to ask for more informations