summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/error_tracking/sentry_errors_resolver.rb
blob: 4cd65daa655d46085d282eb700e578a0ad7855e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

module Resolvers
  module ErrorTracking
    class SentryErrorsResolver < BaseResolver
      type Types::ErrorTracking::SentryErrorType.connection_type, null: true
      extension Gitlab::Graphql::Extensions::ExternallyPaginatedArrayExtension

      argument :search_term, ::GraphQL::STRING_TYPE,
              description: 'Search query for the Sentry error details.',
              required: false

      # TODO: convert to Enum
      argument :sort, ::GraphQL::STRING_TYPE,
              description: 'Attribute to sort on. Options are frequency, first_seen, last_seen. last_seen is default.',
              required: false

      delegate :project, to: :object

      def resolve(**args)
        args[:cursor] = args.delete(:after)

        result = ::ErrorTracking::ListIssuesService.new(project, current_user, args).execute

        next_cursor = result.dig(:pagination, 'next', 'cursor')
        previous_cursor = result.dig(:pagination, 'previous', 'cursor')
        issues = result[:issues]

        # ReactiveCache is still fetching data
        return if issues.nil?

        Gitlab::Graphql::ExternallyPaginatedArray.new(previous_cursor, next_cursor, *issues)
      end

      def self.field_options
        super.merge(connection: false) # we manage the pagination manually, so opt out of the connection field extension
      end
    end
  end
end