So, I have a one to many relationship from Posts to comments:
type Comments {
createdAt: DateTime!
deleted: Boolean
id: ID!
posts: Posts @relation(name: "PostsOnComments")
text: String!
updatedAt: DateTime!
user: String!
}
type Posts {
caption: String!
comments: [Comments!]! @relation(name: "PostsOnComments")
createdAt: DateTime!
displaysrc: String!
id: ID!
likes: Int
updatedAt: DateTime!
}
and wish to run a mutation, which as well as deleting the connection between a post and a comment, attempts to update the field 'deleted, on Comments, to true:
mutation removeComment ($id: ID!, $cid: ID!, $stateB: Boolean) {
removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){
postsPosts {
__typename
id
comments {
__typename
id
text
user
deleted
posts {
__typename
id
}
}
}
}
}
Query Variables
{
"id": "cj0qkl04vep8k0177tky596og",
"cid": "cj1de905k8ya201934l84c3id"
}
But when I run the mutation I get the following error message:
GraphQL error: Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 74):
removeFromPostsOnComments(postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB) {
As was explained to me here, only the link between Posts and comments is deleted, not the actual 'Comment' record itself. So my thinking is, as the record is not deleted, why can I not update the 'deleted' field?
I wish to do this so that it triggers a subscription, which is monitoring the updated field 'deleted'.
The generated mutation output is as follows:
"data": null,
"errors": [
{
"message": "Unknown argument 'deleted' on field 'removeFromPostsOnComments' of type 'Mutation'. (line 2, column 77):\n removeFromPostsOnComments (postsPostsId: $id, commentsCommentsId: $cid, deleted: $stateB){\n ^",
"locations": [
{
"line": 2,
"column": 77
}
]
}
]
}
As can be seen in the image, 'deleted' is definitely included in 'Comments' my GraphCool schema:
I reproduced your issue. First of all, you're getting the error message because deleted
is not part of the arguments of the removeFromPostsOnComments
-mutation, you also see that in the docs:
If you want to update the deleted
field on the Comments
type, you have to use the updateComments
-mutation:
mutation {
updateComments(id: "cj1de905k8ya201934l84c3id", deleted: true) {
id
}
}