1# frozen_string_literal: true 2 3module Types 4 class TimelogType < BaseObject 5 graphql_name 'Timelog' 6 7 authorize :read_issue 8 9 field :spent_at, 10 Types::TimeType, 11 null: true, 12 description: 'Timestamp of when the time tracked was spent at.' 13 14 field :time_spent, 15 GraphQL::Types::Int, 16 null: false, 17 description: 'Time spent displayed in seconds.' 18 19 field :user, 20 Types::UserType, 21 null: false, 22 description: 'User that logged the time.' 23 24 field :issue, 25 Types::IssueType, 26 null: true, 27 description: 'Issue that logged time was added to.' 28 29 field :merge_request, 30 Types::MergeRequestType, 31 null: true, 32 description: 'Merge request that logged time was added to.' 33 34 field :note, 35 Types::Notes::NoteType, 36 null: true, 37 description: 'Note where the quick action was executed to add the logged time.' 38 39 field :summary, GraphQL::Types::String, 40 null: true, 41 description: 'Summary of how the time was spent.' 42 43 def user 44 Gitlab::Graphql::Loaders::BatchModelLoader.new(User, object.user_id).find 45 end 46 47 def issue 48 Gitlab::Graphql::Loaders::BatchModelLoader.new(Issue, object.issue_id).find 49 end 50 51 def spent_at 52 object.spent_at || object.created_at 53 end 54 end 55end 56