Commit 723e877e authored by Stan Hu's avatar Stan Hu

Merge branch 'ajk-graphql-laziness' into 'master'

Improve GraphQL lazy abstractions

See merge request gitlab-org/gitlab!50372
parents 61f1fd76 a73b4a1c
......@@ -6,6 +6,7 @@ module Gitlab
module Epics
class LazyEpicAggregate
include ::Gitlab::Graphql::Aggregations::Epics::Constants
include ::Gitlab::Graphql::Deferred
attr_reader :facet, :epic_id, :lazy_state
......@@ -49,6 +50,8 @@ module Gitlab
@block ? @block.call(node, object) : object
end
alias_method :execute, :epic_aggregate
private
def validate_facet(aggregate_facet)
......
......@@ -5,6 +5,8 @@ module Gitlab
module Aggregations
module Issues
class LazyBlockAggregate
include ::Gitlab::Graphql::Deferred
attr_reader :issue_id, :lazy_state
def initialize(query_ctx, issue_id, &block)
......@@ -35,6 +37,8 @@ module Gitlab
result
end
alias_method :execute, :block_aggregate
private
def load_records_into_loaded_objects
......
......@@ -5,6 +5,8 @@ module Gitlab
module Aggregations
module Vulnerabilities
class LazyUserNotesCountAggregate
include ::Gitlab::Graphql::Deferred
attr_reader :vulnerability, :lazy_state
def initialize(query_ctx, vulnerability)
......
......@@ -17,6 +17,14 @@ module Gitlab
self.class.new { yield force }
end
def catch(error_class = StandardError, &block)
self.class.new do
force
rescue error_class => e
yield e
end
end
# Force evaluation of a (possibly) lazy value
def self.force(value)
case value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment