Class: Mutations::Snippets::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
ResolvesProject
Defined in:
app/graphql/mutations/snippets/create.rb

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Instance Method Summary collapse

Methods included from ResolvesProject

#resolve_project

Methods inherited from BaseMutation

#api_user?, #current_user, #errors_on_object, #ready?

Instance Method Details

#resolve(args) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/graphql/mutations/snippets/create.rb', line 39

def resolve(args)
  project_path = args.delete(:project_path)

  if project_path.present?
    project = find_project!(project_path: project_path)
  elsif !can_create_personal_snippet?
    raise_resource_not_available_error!
  end

  service_response = ::Snippets::CreateService.new(project,
                                                   context[:current_user],
                                                   create_params(args)).execute

  snippet = service_response.payload[:snippet]

  # Only when the user is not an api user and the operation was successful
  if !api_user? && service_response.success?
    ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user)
  end

  {
    snippet: service_response.success? ? snippet : nil,
    errors: errors_on_object(snippet)
  }
end