summaryrefslogtreecommitdiff
path: root/app/graphql
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-06-26 18:31:05 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-07-04 10:53:39 +0200
commit04b046587fe609cd889f3fa518f08299abc61267 (patch)
tree634fc7d5e2a416950868700a82c171ff4f54239b /app/graphql
parentcd5789415b6e561564073693243e890e79596ed2 (diff)
downloadgitlab-ce-04b046587fe609cd889f3fa518f08299abc61267.tar.gz
Add pipeline lists to GraphQL
This adds Keyset pagination to GraphQL lists. PoC for that is pipelines on merge requests and projects. When paginating a list, the base-64 encoded id of the ordering field (in most cases the primary key) can be passed in the `before` or `after` GraphQL argument.
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/gitlab_schema.rb3
-rw-r--r--app/graphql/resolvers/concerns/resolves_pipelines.rb23
-rw-r--r--app/graphql/resolvers/merge_request_pipelines_resolver.rb16
-rw-r--r--app/graphql/resolvers/project_pipelines_resolver.rb11
-rw-r--r--app/graphql/types/ci/pipeline_status_enum.rb9
-rw-r--r--app/graphql/types/ci/pipeline_type.rb31
-rw-r--r--app/graphql/types/merge_request_type.rb6
-rw-r--r--app/graphql/types/permission_types/ci/pipeline.rb11
-rw-r--r--app/graphql/types/project_type.rb5
9 files changed, 115 insertions, 0 deletions
diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb
index de4fc1d8e32..d9f9129d08a 100644
--- a/app/graphql/gitlab_schema.rb
+++ b/app/graphql/gitlab_schema.rb
@@ -2,7 +2,10 @@ class GitlabSchema < GraphQL::Schema
use BatchLoader::GraphQL
use Gitlab::Graphql::Authorize
use Gitlab::Graphql::Present
+ use Gitlab::Graphql::Connections
query(Types::QueryType)
+
+ default_max_page_size 100
# mutation(Types::MutationType)
end
diff --git a/app/graphql/resolvers/concerns/resolves_pipelines.rb b/app/graphql/resolvers/concerns/resolves_pipelines.rb
new file mode 100644
index 00000000000..9ec45378d8e
--- /dev/null
+++ b/app/graphql/resolvers/concerns/resolves_pipelines.rb
@@ -0,0 +1,23 @@
+module ResolvesPipelines
+ extend ActiveSupport::Concern
+
+ included do
+ type [Types::Ci::PipelineType], null: false
+ argument :status,
+ Types::Ci::PipelineStatusEnum,
+ required: false,
+ description: "Filter pipelines by their status"
+ argument :ref,
+ GraphQL::STRING_TYPE,
+ required: false,
+ description: "Filter pipelines by the ref they are run for"
+ argument :sha,
+ GraphQL::STRING_TYPE,
+ required: false,
+ description: "Filter pipelines by the sha of the commit they are run for"
+ end
+
+ def resolve_pipelines(project, params = {})
+ PipelinesFinder.new(project, context[:current_user], params).execute
+ end
+end
diff --git a/app/graphql/resolvers/merge_request_pipelines_resolver.rb b/app/graphql/resolvers/merge_request_pipelines_resolver.rb
new file mode 100644
index 00000000000..00b51ee1381
--- /dev/null
+++ b/app/graphql/resolvers/merge_request_pipelines_resolver.rb
@@ -0,0 +1,16 @@
+module Resolvers
+ class MergeRequestPipelinesResolver < BaseResolver
+ include ::ResolvesPipelines
+
+ alias_method :merge_request, :object
+
+ def resolve(**args)
+ resolve_pipelines(project, args)
+ .merge(merge_request.all_pipelines)
+ end
+
+ def project
+ merge_request.source_project
+ end
+ end
+end
diff --git a/app/graphql/resolvers/project_pipelines_resolver.rb b/app/graphql/resolvers/project_pipelines_resolver.rb
new file mode 100644
index 00000000000..7f175a3b26c
--- /dev/null
+++ b/app/graphql/resolvers/project_pipelines_resolver.rb
@@ -0,0 +1,11 @@
+module Resolvers
+ class ProjectPipelinesResolver < BaseResolver
+ include ResolvesPipelines
+
+ alias_method :project, :object
+
+ def resolve(**args)
+ resolve_pipelines(project, args)
+ end
+ end
+end
diff --git a/app/graphql/types/ci/pipeline_status_enum.rb b/app/graphql/types/ci/pipeline_status_enum.rb
new file mode 100644
index 00000000000..2c12e5001d8
--- /dev/null
+++ b/app/graphql/types/ci/pipeline_status_enum.rb
@@ -0,0 +1,9 @@
+module Types
+ module Ci
+ class PipelineStatusEnum < BaseEnum
+ ::Ci::Pipeline.all_state_names.each do |state_symbol|
+ value state_symbol.to_s.upcase, value: state_symbol.to_s
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/ci/pipeline_type.rb b/app/graphql/types/ci/pipeline_type.rb
new file mode 100644
index 00000000000..bbb7d9354d0
--- /dev/null
+++ b/app/graphql/types/ci/pipeline_type.rb
@@ -0,0 +1,31 @@
+module Types
+ module Ci
+ class PipelineType < BaseObject
+ expose_permissions Types::PermissionTypes::Ci::Pipeline
+
+ graphql_name 'Pipeline'
+
+ field :id, GraphQL::ID_TYPE, null: false
+ field :iid, GraphQL::ID_TYPE, null: false
+
+ field :sha, GraphQL::STRING_TYPE, null: false
+ field :before_sha, GraphQL::STRING_TYPE, null: true
+ field :status, PipelineStatusEnum, null: false
+ field :duration,
+ GraphQL::INT_TYPE,
+ null: true,
+ description: "Duration of the pipeline in seconds"
+ field :coverage,
+ GraphQL::FLOAT_TYPE,
+ null: true,
+ description: "Coverage percentage"
+ field :created_at, Types::TimeType, null: false
+ field :updated_at, Types::TimeType, null: false
+ field :started_at, Types::TimeType, null: true
+ field :finished_at, Types::TimeType, null: true
+ field :committed_at, Types::TimeType, null: true
+
+ # TODO: Add triggering user as a type
+ end
+ end
+end
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb
index a1f3c0dd8c0..88cd2adc6dc 100644
--- a/app/graphql/types/merge_request_type.rb
+++ b/app/graphql/types/merge_request_type.rb
@@ -45,5 +45,11 @@ module Types
field :upvotes, GraphQL::INT_TYPE, null: false
field :downvotes, GraphQL::INT_TYPE, null: false
field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false
+
+ field :head_pipeline, Types::Ci::PipelineType, null: true, method: :actual_head_pipeline do
+ authorize :read_pipeline
+ end
+ field :pipelines, Types::Ci::PipelineType.connection_type,
+ resolver: Resolvers::MergeRequestPipelinesResolver
end
end
diff --git a/app/graphql/types/permission_types/ci/pipeline.rb b/app/graphql/types/permission_types/ci/pipeline.rb
new file mode 100644
index 00000000000..942539c7cf7
--- /dev/null
+++ b/app/graphql/types/permission_types/ci/pipeline.rb
@@ -0,0 +1,11 @@
+module Types
+ module PermissionTypes
+ module Ci
+ class Pipeline < BasePermissionType
+ graphql_name 'PipelinePermissions'
+
+ abilities :update_pipeline, :admin_pipeline, :destroy_pipeline
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb
index a832e8b4bde..97707215b4e 100644
--- a/app/graphql/types/project_type.rb
+++ b/app/graphql/types/project_type.rb
@@ -70,5 +70,10 @@ module Types
resolver: Resolvers::MergeRequestResolver do
authorize :read_merge_request
end
+
+ field :pipelines,
+ Types::Ci::PipelineType.connection_type,
+ null: false,
+ resolver: Resolvers::ProjectPipelinesResolver
end
end