summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/notes/base.rb
diff options
context:
space:
mode:
authorLuke Duncalfe <lduncalfe@eml.cc>2019-07-01 16:34:34 +1200
committerLuke Duncalfe <lduncalfe@eml.cc>2019-07-10 12:13:47 +1200
commita00a23ca828488ae343e02d8528bb94936d0e624 (patch)
tree8bf0228a3760133932ed666858a8121eaebc87c7 /app/graphql/mutations/notes/base.rb
parent42e876b7c01c61e74e3c7b0cb637ae43809ce1d2 (diff)
downloadgitlab-ce-a00a23ca828488ae343e02d8528bb94936d0e624.tar.gz
GraphQL mutations for managing Notes
https://gitlab.com/gitlab-org/gitlab-ce/issues/62826
Diffstat (limited to 'app/graphql/mutations/notes/base.rb')
-rw-r--r--app/graphql/mutations/notes/base.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/graphql/mutations/notes/base.rb b/app/graphql/mutations/notes/base.rb
new file mode 100644
index 00000000000..a7198f5fba6
--- /dev/null
+++ b/app/graphql/mutations/notes/base.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Notes
+ class Base < BaseMutation
+ include Gitlab::Graphql::Authorize::AuthorizeResource
+
+ field :note,
+ Types::Notes::NoteType,
+ null: true,
+ description: 'The note after mutation'
+
+ private
+
+ def find_object(id:)
+ GitlabSchema.object_from_id(id)
+ end
+
+ def check_object_is_noteable!(object)
+ unless object.is_a?(Noteable)
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable,
+ 'Cannot add notes to this resource'
+ end
+ end
+
+ def check_object_is_note!(object)
+ unless object.is_a?(Note)
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable,
+ 'Resource is not a note'
+ end
+ end
+ end
+ end
+end