Commit d6f208c6 authored by Phil Hughes's avatar Phil Hughes

Fixes createDiffNote GraphQL mutation

Fixes `new_line` not allowed to be `null` which was causing
the mutation to not allow for diff notes to be created
on deleted lines.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/282476
parent d5341588
......@@ -11,6 +11,21 @@ module Mutations
required: true,
description: copy_field_description(Types::Notes::NoteType, :position)
def ready?(**args)
# As both arguments are optional, validate here that one of the
# arguments are present.
#
# This may be able to be done using InputUnions in the future
# if this RFC is merged:
# https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md
if args[:position].to_hash.values_at(:old_line, :new_line).compact.blank?
raise Gitlab::Graphql::Errors::ArgumentError,
'position oldLine or newLine arguments are required'
end
super(**args)
end
private
def create_note_params(noteable, args)
......
......@@ -8,7 +8,7 @@ module Types
argument :old_line, GraphQL::INT_TYPE, required: false,
description: copy_field_description(Types::Notes::DiffPositionType, :old_line)
argument :new_line, GraphQL::INT_TYPE, required: true,
argument :new_line, GraphQL::INT_TYPE, required: false,
description: copy_field_description(Types::Notes::DiffPositionType, :new_line)
end
# rubocop: enable Graphql/AuthorizeTypes
......
---
title: Fixed diff notes GraphQL mutation not allowing comments on deleted lines
merge_request:
author:
type: fixed
......@@ -41,6 +41,29 @@ RSpec.describe 'Adding a DiffNote' do
it_behaves_like 'a Note mutation that creates a Note'
context 'add comment to old line' do
let(:mutation) do
variables = {
noteable_id: GitlabSchema.id_from_object(noteable).to_s,
body: 'Body text',
position: {
paths: {
old_path: 'files/ruby/popen.rb',
new_path: 'files/ruby/popen.rb'
},
old_line: 14,
base_sha: diff_refs.base_sha,
head_sha: diff_refs.head_sha,
start_sha: diff_refs.start_sha
}
}
graphql_mutation(:create_diff_note, variables)
end
it_behaves_like 'a Note mutation that creates a Note'
end
it_behaves_like 'a Note mutation when there are active record validation errors', model: DiffNote
it_behaves_like 'a Note mutation when there are rate limit validation errors'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment