2

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:

enter image description here

Community
  • 1
  • 1
TheoG
  • 1,498
  • 4
  • 30
  • 54
  • How does your mutation look like on the server? – Locco0_0 Apr 11 '17 at 13:29
  • @Locco0_0 If you mean what does the generated output of running the mutation look like, please see my amended question. – TheoG Apr 11 '17 at 14:18
  • The GraphQL Error suggests that you did not add the deleted argument to the mutation on the server – Locco0_0 Apr 11 '17 at 14:23
  • @Locco0_0 As can be seen on the attached image, see amended question, 'deleted' is definitely added to 'Comments'part of my GraphCool schema. Possibly a bug? – TheoG Apr 11 '17 at 14:58

1 Answers1

3

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:

enter image description here

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
  }
}
nburk
  • 22,409
  • 18
  • 87
  • 132