2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
|
|
|
class SnippetType < BaseObject
|
|
|
|
graphql_name 'Snippet'
|
|
|
|
description 'Represents a snippet entry'
|
|
|
|
|
|
|
|
implements(Types::Notes::NoteableType)
|
|
|
|
|
|
|
|
present_using SnippetPresenter
|
|
|
|
|
|
|
|
authorize :read_snippet
|
|
|
|
|
|
|
|
expose_permissions Types::PermissionTypes::Snippet
|
|
|
|
|
|
|
|
field :id, GraphQL::ID_TYPE,
|
|
|
|
description: 'Id of the snippet',
|
|
|
|
null: false
|
|
|
|
|
|
|
|
field :title, GraphQL::STRING_TYPE,
|
|
|
|
description: 'Title of the snippet',
|
|
|
|
null: false
|
|
|
|
|
|
|
|
field :project, Types::ProjectType,
|
|
|
|
description: 'The project the snippet is associated with',
|
|
|
|
null: true,
|
|
|
|
authorize: :read_project,
|
|
|
|
resolve: -> (snippet, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, snippet.project_id).find }
|
|
|
|
|
|
|
|
field :author, Types::UserType,
|
|
|
|
description: 'The owner of the snippet',
|
|
|
|
null: false,
|
|
|
|
resolve: -> (snippet, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, snippet.author_id).find }
|
|
|
|
|
|
|
|
field :file_name, GraphQL::STRING_TYPE,
|
|
|
|
description: 'File Name of the snippet',
|
|
|
|
null: true
|
|
|
|
|
|
|
|
field :description, GraphQL::STRING_TYPE,
|
|
|
|
description: 'Description of the snippet',
|
|
|
|
null: true
|
|
|
|
|
2019-12-13 09:08:01 +00:00
|
|
|
field :visibility_level, Types::VisibilityLevelsEnum,
|
|
|
|
description: 'Visibility Level of the snippet',
|
2019-12-10 07:53:40 +00:00
|
|
|
null: false
|
|
|
|
|
|
|
|
field :created_at, Types::TimeType,
|
|
|
|
description: 'Timestamp this snippet was created',
|
|
|
|
null: false
|
|
|
|
|
|
|
|
field :updated_at, Types::TimeType,
|
|
|
|
description: 'Timestamp this snippet was updated',
|
|
|
|
null: false
|
|
|
|
|
|
|
|
field :web_url, type: GraphQL::STRING_TYPE,
|
|
|
|
description: 'Web URL of the snippet',
|
|
|
|
null: false
|
|
|
|
|
|
|
|
field :raw_url, type: GraphQL::STRING_TYPE,
|
|
|
|
description: 'Raw URL of the snippet',
|
|
|
|
null: false
|
|
|
|
|
2020-01-22 12:08:40 +00:00
|
|
|
field :blob, type: Types::Snippets::BlobType,
|
|
|
|
description: 'Snippet blob',
|
2020-02-25 09:09:10 +00:00
|
|
|
calls_gitaly: true,
|
2020-01-22 12:08:40 +00:00
|
|
|
null: false
|
|
|
|
|
2020-03-19 09:09:27 +00:00
|
|
|
field :ssh_url_to_repo, type: GraphQL::STRING_TYPE,
|
|
|
|
description: 'SSH URL to the snippet repository',
|
2020-04-03 18:10:03 +00:00
|
|
|
calls_gitaly: true,
|
2020-03-19 09:09:27 +00:00
|
|
|
null: true
|
|
|
|
|
|
|
|
field :http_url_to_repo, type: GraphQL::STRING_TYPE,
|
|
|
|
description: 'HTTP URL to the snippet repository',
|
2020-04-03 18:10:03 +00:00
|
|
|
calls_gitaly: true,
|
2020-03-19 09:09:27 +00:00
|
|
|
null: true
|
|
|
|
|
2019-12-10 07:53:40 +00:00
|
|
|
markdown_field :description_html, null: true, method: :description
|
|
|
|
end
|
|
|
|
end
|