Hello again.
I'm trying to return a (Post ) node using Graphql.
the Post type looks like this.
type Post {
id: ID
post_id: String
user_id: String
text: String
post_type: String
user_liked: Boolean
author_info: User
text_post: TextPost
}
and the User type looks like this.
type User {
id: ID
created_at: String
display_name: String
bio: String
avatar: String
default_profile_image: Boolean
cover: String
favourite_posts_count: Int @cypher(statement: "RETURN SIZE((this)-[:FAVOURITES]-())")
user_id: ID
}
and my query looks like this.
fetchPosts(user_id: String, limit: Int, skip: Int): [Post]
@cypher(
statement"""MATCH (u:User)-[f:FOLLOWS]->(u2:User)-[c:CREATED]-(p:Post)
WHERE u.user_id = $user_id
WITH u, p, EXISTS((u)-[:LIKES]->(p)) AS isLiked,
RETURN p {
.created_at,
.user_id,
.post_id,
.post_type,
user_liked: isLiked,
author_info: [ (p)-[CREATED]-(User) | author_info]
} ORDER BY p.created_at DESC Skip $skip LIMIT $limit
)
when I try to return the result without mentioning author_info
the result are returned as expected but once I specify author_info
like this for ex:
author_info{
username
}
it gives me this error message
"message": "Variable `undefined` not defined (line 34, column 177 (offset: 1073))\n\"} ORDER BY p.created_at DESC Skip $skip LIMIT $limit\", {offset:$offset, first:$first, user_id:$user_id, limit:$limit, skip:$skip}, True) AS x UNWIND x AS `post` RETURN `post` {undefined} AS `post`\"\n
and if I try to change author_info
in the post type from
author_info: User
to
author_info: User @relation(name: "CREATED", direction: IN)
so my Post type looks like this (also I would prefer it to be like this, it's more convenient this way)
type Post {
id: ID
post_id: String
user_id: String
text: String
post_type: String
user_liked: Boolean
author_info: User @relation(name: "CREATED", direction: IN)
text_post: TextPost
}
then once I specify author_info on the query, it gives me this error.
"message": "Expected to find a node at ref slot 1 but found Map{post_id -> String(\"93ac89c0335f11eb9c33eb106b4a2825\"), created_at -> String(\"2020-12-01 00:03:14.223361\"), post_type -> String(\"text_post\"), user_id -> String(\"MI9B8M4AYkZgLXFNoKHkGAIUv4H2\")} instead"
like I've mentioned before I would prefer to specify the author_info
's cypher query on the Post type but it gives me the latter problem and even when I change author_info
's type to User and specify its cypher query on fetchpost()
it gives me the first error.
Is there a way to mix the returned result to give me the result from isLiked
while also calling author_info
from the post type?. And if not, then how can I fix the first error? please.
Thank you for the help. And best regards.