summaryrefslogtreecommitdiff
path: root/app/graphql/types/repository/blob_type.rb
blob: dd5c70887def0cfd8247c8333fec7aabdf24d68c (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# frozen_string_literal: true
module Types
  module Repository
    # rubocop: disable Graphql/AuthorizeTypes
    # This is presented through `Repository` that has its own authorization
    class BlobType < BaseObject
      graphql_name 'RepositoryBlob'

      present_using BlobPresenter

      field :id, GraphQL::Types::ID, null: false,
            description: 'ID of the blob.'

      field :oid, GraphQL::Types::String, null: false, method: :id,
            description: 'OID of the blob.'

      field :path, GraphQL::Types::String, null: false,
            description: 'Path of the blob.'

      field :name, GraphQL::Types::String,
            description: 'Blob name.',
            null: true

      field :mode, type: GraphQL::Types::String,
            description: 'Blob mode.',
            null: true

      field :lfs_oid, GraphQL::Types::String, null: true,
            calls_gitaly: true,
            description: 'LFS OID of the blob.'

      field :web_path, GraphQL::Types::String, null: true,
            description: 'Web path of the blob.'

      field :ide_edit_path, GraphQL::Types::String, null: true,
            description: 'Web path to edit this blob in the Web IDE.'

      field :fork_and_edit_path, GraphQL::Types::String, null: true,
            description: 'Web path to edit this blob using a forked project.'

      field :ide_fork_and_edit_path, GraphQL::Types::String, null: true,
            description: 'Web path to edit this blob in the Web IDE using a forked project.'

      field :fork_and_view_path, GraphQL::Types::String, null: true,
            description: 'Web path to view this blob using a forked project.'

      field :size, GraphQL::Types::Int, null: true,
            description: 'Size (in bytes) of the blob.'

      field :raw_size, GraphQL::Types::Int, null: true,
            description: 'Size (in bytes) of the blob, or the blob target if stored externally.'

      field :raw_blob, GraphQL::Types::String, null: true, method: :data,
            description: 'Raw content of the blob.'

      field :raw_text_blob, GraphQL::Types::String, null: true, method: :text_only_data,
            description: 'Raw content of the blob, if the blob is text data.'

      field :stored_externally, GraphQL::Types::Boolean, null: true, method: :stored_externally?,
            description: "Whether the blob's content is stored externally (for instance, in LFS)."

      field :external_storage, GraphQL::Types::String, null: true, method: :external_storage,
            description: "External storage being used, if enabled (for instance, 'LFS')."

      field :edit_blob_path, GraphQL::Types::String, null: true,
            description: 'Web path to edit the blob in the old-style editor.'

      field :raw_path, GraphQL::Types::String, null: true,
            description: 'Web path to download the raw blob.'

      field :external_storage_url, GraphQL::Types::String, null: true,
            description: 'Web path to download the raw blob via external storage, if enabled.'

      field :replace_path, GraphQL::Types::String, null: true,
            description: 'Web path to replace the blob content.'

      field :pipeline_editor_path, GraphQL::Types::String, null: true,
            description: 'Web path to edit .gitlab-ci.yml file.'

      field :gitpod_blob_url, GraphQL::Types::String, null: true,
            description: 'URL to the blob within Gitpod.'

      field :find_file_path, GraphQL::Types::String, null: true,
            description: 'Web path to find file.'

      field :blame_path, GraphQL::Types::String, null: true,
            description: 'Web path to blob blame page.'

      field :history_path, GraphQL::Types::String, null: true,
            description: 'Web path to blob history page.'

      field :permalink_path, GraphQL::Types::String, null: true,
            description: 'Web path to blob permalink.',
            calls_gitaly: true

      field :environment_formatted_external_url, GraphQL::Types::String, null: true,
            description: 'Environment on which the blob is available.',
            calls_gitaly: true

      field :environment_external_url_for_route_map, GraphQL::Types::String, null: true,
            description: 'Web path to blob on an environment.',
            calls_gitaly: true

      field :file_type, GraphQL::Types::String, null: true,
            description: 'Expected format of the blob based on the extension.'

      field :simple_viewer, type: Types::BlobViewerType,
            description: 'Blob content simple viewer.',
            null: false

      field :rich_viewer, type: Types::BlobViewerType,
            description: 'Blob content rich viewer.',
            null: true

      field :plain_data, GraphQL::Types::String,
            description: 'Blob plain highlighted data.',
            null: true,
            calls_gitaly: true

      field :can_modify_blob, GraphQL::Types::Boolean, null: true, method: :can_modify_blob?,
            calls_gitaly: true,
            description: 'Whether the current user can modify the blob.'

      field :can_current_user_push_to_branch, GraphQL::Types::Boolean, null: true, method: :can_current_user_push_to_branch?,
            description: 'Whether the current user can push to the branch.'

      field :archived, GraphQL::Types::Boolean, null: true, method: :archived?,
            description: 'Whether the current project is archived.'

      field :language, GraphQL::Types::String,
            description: 'Blob language.',
            method: :blob_language,
            null: true,
            calls_gitaly: true

      field :code_navigation_path, GraphQL::Types::String, null: true, calls_gitaly: true,
            description: 'Web path for code navigation.'

      field :project_blob_path_root, GraphQL::Types::String, null: true,
            description: 'Web path for the root of the blob.'

      def raw_text_blob
        object.data unless object.binary?
      end

      def lfs_oid
        Gitlab::Graphql::Loaders::BatchLfsOidLoader.new(object.repository, object.id).find
      end
    end
  end
end

Types::Repository::BlobType.prepend_mod_with('Types::Repository::BlobType')