summaryrefslogtreecommitdiff
path: root/app/graphql/types/notes/diff_position_type.rb
blob: cc00feba2e67b5660c8c02687f5b3a23c57910e9 (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
# 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 :diff_refs, Types::DiffRefsType, null: false,
            description: 'Information about the branch, HEAD, and base at the time of commenting'

      field :file_path, GraphQL::STRING_TYPE, null: false,
            description: 'Path of the file that was changed'
      field :old_path, GraphQL::STRING_TYPE, null: true,
            description: 'Path of the file on the start SHA'
      field :new_path, GraphQL::STRING_TYPE, null: true,
            description: 'Path of the file on the HEAD SHA'
      field :position_type, Types::Notes::PositionTypeEnum, null: false,
            description: 'Type of file the position refers to'

      # Fields for text positions
      field :old_line, GraphQL::INT_TYPE, null: true,
            description: '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: '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: 'X position of the note',
            resolve: -> (position, _args, _ctx) { position.x if position.on_image? }
      field :y, GraphQL::INT_TYPE, null: true,
            description: 'Y position of the note',
            resolve: -> (position, _args, _ctx) { position.y if position.on_image? }
      field :width, GraphQL::INT_TYPE, null: true,
            description: 'Total width of the image',
            resolve: -> (position, _args, _ctx) { position.width if position.on_image? }
      field :height, GraphQL::INT_TYPE, null: true,
            description: 'Total height of the image',
            resolve: -> (position, _args, _ctx) { position.height if position.on_image? }
    end
    # rubocop: enable Graphql/AuthorizeTypes
  end
end