GraphQL API - Can't create new merge request thread
Summary
It seems like it's not possible to create MR discussion thread from GraphQL. The reason is that when we specify diff position, the API validation logic incorrectly requires the request to specify both old and new line. But the comment should either be on the old or on the new line.
Steps to reproduce
-
Create an MR with a simple change (I changed one line of code and created an MR from Web IDE viktomas/test-project!3 (closed))
-
Get the version with
curl -H "Authorization: Bearer TOKEN" 'https://gitlab.com/api/v4/projects/20486274/merge_requests/3/versions' | jq
[ { "id": 124417604, "head_commit_sha": "1d0f0059d3a11b8f24d1b2493646e367c7ebe3b6", "base_commit_sha": "1f0fa02de1f6b913d674a8be10899fb8540237a9", "start_commit_sha": "1f0fa02de1f6b913d674a8be10899fb8540237a9", "created_at": "2020-11-13T14:09:41.537Z", "merge_request_id": 77967925, "state": "collected", "real_size": "1" } ]
-
Use the triplet of commit_sha to craft a new comment request
curl --request POST --header "Authorization: Bearer TOKEN" --form "body=Via API" \ --form "position[old_path]=test.js" --form "position[new_path]=test.js" \ --form "position[old_line]=20" \ --form "position[head_sha]=1d0f0059d3a11b8f24d1b2493646e367c7ebe3b6" \ --form "position[base_sha]=1f0fa02de1f6b913d674a8be10899fb8540237a9" \ --form "position[start_sha]=1f0fa02de1f6b913d674a8be10899fb8540237a9" \ --form "position[position_type]=text" \ https://gitlab.com/api/v4/projects/20486274/merge_requests/3/discussions
-
This REST API call correctly creates a comment
-
Doing the same thing from GraphQL is not possible
-
Get the MR ID
{ project(fullPath:"viktomas/test-project"){ mergeRequest(iid: "3"){ id } } }
-
craft equivalent of the REST API call
mutation AddComment { createDiffNote(input: {body: "test", noteableId: "gid://gitlab/MergeRequest/77967925", position: {headSha: "1d0f0059d3a11b8f24d1b2493646e367c7ebe3b6", baseSha: "1f0fa02de1f6b913d674a8be10899fb8540237a9", startSha: "1f0fa02de1f6b913d674a8be10899fb8540237a9", paths: {oldPath: "test.js", newPath: "test.js"}, oldLine: 20}}) { note { body } } }
-
you get an error
{ "errors": [ { "message": "Argument 'newLine' on InputObject 'DiffPositionInput' is required. Expected type Int!", "locations": [ { "line": 2, "column": 100 } ], "path": [ "mutation AddComment", "createDiffNote", "input", "position", "newLine" ], "extensions": { "code": "missingRequiredInputObjectAttribute", "argumentName": "newLine", "argumentType": "Int!", "inputObjectType": "DiffPositionInput" } } ] }
Example Project
viktomas/test-project!3 (diffs)
What is the current bug behavior?
GraphQL fails request validation.
What is the expected correct behavior?
The request mentioned in the "Steps to reproduce" should succeed.
Relevant logs and/or screenshots
All already shown in the "Steps to reproduce"
Output of checks
This bug happens on GitLab.com