What I want to do
Hi it’s me again, I am learning the ropes of Dgraph, and I am walking through this tutorial by @sakib but have been stuck on this step:
Adding comments on InstaClone posts
You have to know the IDs of all the posts since you’ll need that to connect a comment with the post via the commentOn field. You also need to know the usernames of existing users for the comment By field. The following query fetches IDs of existing posts along with usernames of their posters:
query queryAllPosts {
queryPost {
id
postedBy {
username
}
}
}
It gives the following response: (I managed to retrieve the posts correctly)
{
"queryPost": [
{
"id": "0x4e5d9b3b",
"postedBy": {
"username": "karen"
}
}, ...
Now we’re ready to do an addComment mutation to add some comments: (But I am unable to do this step)
mutation AddComments($commentInput: [AddCommentInput!]!) {
addComment(input: $commentInput) {
comment {
text
commentBy {
username
}
commentOn {
description
postedBy {
username
}
}
}
}
}
For simplicity, let’s assume that existing users will comment on one another’s posts. The following is the data of the query variable:
{
"commentInput": [
{
"text": "This book's a fantastic addition to your other collections",
"commentBy": {
"username": "kmulbery0"
},
"commentOn": {
"id": "0x4e5d9b3b"
}
}, ...
This should result in a successful response:
{
"addComment": {
"comment": [
{
"text": "This book's a fantastic addition to your other collections",
"commentBy": {
"username": "kmulbery0"
},
"commentOn": {
"description": "A new antique book I just collected!",
"postedBy": {
"username": "karen"
}
}
}, ...
Instead, the response I get is:
{
"errors": [
{
"message": "couldn't rewrite mutation addComment because failed to rewrite mutation payload because ID \"0x4e5d9b3b\" isn't a Post",
"path": [
"addComment"
]
},
{
"message": "couldn't rewrite mutation addComment because failed to rewrite mutation payload because ID \"0x4e5d9b3e\" isn't a Post",
"path": [
"addComment"
]
},...
What I did
I have dropped tables and input the mutations again, twice, but it produces the same error.
Dgraph metadata
Using Dgraph Cloud