summaryrefslogtreecommitdiff
path: root/app/graphql/types/clusters/agent_type.rb
blob: 89316ed4728f754555adde41d156e753fedf9d60 (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
# frozen_string_literal: true

module Types
  module Clusters
    class AgentType < BaseObject
      graphql_name 'ClusterAgent'

      authorize :admin_cluster

      connection_type_class(Types::CountableConnectionType)

      field :created_at,
            Types::TimeType,
            null: true,
            description: 'Timestamp the cluster agent was created.'

      field :created_by_user,
            Types::UserType,
            null: true,
            description: 'User object, containing information about the person who created the agent.'

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

      field :name,
            GraphQL::Types::String,
            null: true,
            description: 'Name of the cluster agent.'

      field :project, Types::ProjectType,
            description: 'Project this cluster agent is associated with.',
            null: true,
            authorize: :read_project

      field :tokens, Types::Clusters::AgentTokenType.connection_type,
            description: 'Tokens associated with the cluster agent.',
            null: true,
            resolver: ::Resolvers::Clusters::AgentTokensResolver

      field :updated_at,
            Types::TimeType,
            null: true,
            description: 'Timestamp the cluster agent was updated.'

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

      field :connections,
            Types::Kas::AgentConnectionType.connection_type,
            null: true,
            description: 'Active connections for the cluster agent',
            complexity: 5,
            resolver: ::Resolvers::Kas::AgentConnectionsResolver

      field :activity_events,
            Types::Clusters::AgentActivityEventType.connection_type,
            null: true,
            description: 'Recent activity for the cluster agent.',
            resolver: Resolvers::Clusters::AgentActivityEventsResolver

      def project
        Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, object.project_id).find
      end

      def web_path
        ::Gitlab::Routing.url_helpers.project_cluster_agent_path(object.project, object.name)
      end
    end
  end
end