summaryrefslogtreecommitdiff
path: root/app/graphql/types/notes/diff_position_type.rb
blob: ebc2445171514cb1c4e39cc7dca92e6c256d27b0 (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
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

module Types
  module Notes
    # rubocop: disable Graphql/AuthorizeTypes
    # This is presented through `NoteType` that has its own authorization
    class DiffPositionType < BaseObject
      graphql_name 'DiffPosition'

      field :head_sha, GraphQL::STRING_TYPE, null: false,
            description: "The sha of the head at the time the comment was made"
      field :base_sha,  GraphQL::STRING_TYPE, null: true,
            description: "The merge base of the branch the comment was made on"
      field :start_sha, GraphQL::STRING_TYPE, null: false,
            description: "The sha of the branch being compared against"

      field :file_path, GraphQL::STRING_TYPE, null: false,
            description: "The path of the file that was changed"
      field :old_path, GraphQL::STRING_TYPE, null: true,
            description: "The path of the file on the start sha."
      field :new_path, GraphQL::STRING_TYPE, null: true,
            description: "The path of the file on the head sha."
      field :position_type, Types::Notes::PositionTypeEnum, null: false

      # Fields for text positions
      field :old_line, GraphQL::INT_TYPE, null: true,
            description: "The line on start sha that was changed",
            resolve: -> (position, _args, _ctx) { position.old_line if position.on_text? }
      field :new_line, GraphQL::INT_TYPE, null: true,
            description: "The line on head sha that was changed",
            resolve: -> (position, _args, _ctx) { position.new_line if position.on_text? }

      # Fields for image positions
      field :x, GraphQL::INT_TYPE, null: true,
            description: "The X postion on which the comment was made",
            resolve: -> (position, _args, _ctx) { position.x if position.on_image? }
      field :y, GraphQL::INT_TYPE, null: true,
            description: "The Y position on which the comment was made",
            resolve: -> (position, _args, _ctx) { position.y if position.on_image? }
      field :width, GraphQL::INT_TYPE, null: true,
            description: "The total width of the image",
            resolve: -> (position, _args, _ctx) { position.width if position.on_image? }
      field :height, GraphQL::INT_TYPE, null: true,
            description: "The total height of the image",
            resolve: -> (position, _args, _ctx) { position.height if position.on_image? }
    end
    # rubocop: enable Graphql/AuthorizeTypes
  end
end