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 ...@@ -6,6 +6,7 @@ module Gitlab
module Epics module Epics
class LazyEpicAggregate class LazyEpicAggregate
include ::Gitlab::Graphql::Aggregations::Epics::Constants include ::Gitlab::Graphql::Aggregations::Epics::Constants
include ::Gitlab::Graphql::Deferred
attr_reader :facet, :epic_id, :lazy_state attr_reader :facet, :epic_id, :lazy_state
...@@ -49,6 +50,8 @@ module Gitlab ...@@ -49,6 +50,8 @@ module Gitlab
@block ? @block.call(node, object) : object @block ? @block.call(node, object) : object
end end
alias_method :execute, :epic_aggregate
private private
def validate_facet(aggregate_facet) def validate_facet(aggregate_facet)
......
...@@ -5,6 +5,8 @@ module Gitlab ...@@ -5,6 +5,8 @@ module Gitlab
module Aggregations module Aggregations
module Issues module Issues
class LazyBlockAggregate class LazyBlockAggregate
include ::Gitlab::Graphql::Deferred
attr_reader :issue_id, :lazy_state attr_reader :issue_id, :lazy_state
def initialize(query_ctx, issue_id, &block) def initialize(query_ctx, issue_id, &block)
...@@ -35,6 +37,8 @@ module Gitlab ...@@ -35,6 +37,8 @@ module Gitlab
result result
end end
alias_method :execute, :block_aggregate
private private
def load_records_into_loaded_objects def load_records_into_loaded_objects
......
...@@ -5,6 +5,8 @@ module Gitlab ...@@ -5,6 +5,8 @@ module Gitlab
module Aggregations module Aggregations
module Vulnerabilities module Vulnerabilities
class LazyUserNotesCountAggregate class LazyUserNotesCountAggregate
include ::Gitlab::Graphql::Deferred
attr_reader :vulnerability, :lazy_state attr_reader :vulnerability, :lazy_state
def initialize(query_ctx, vulnerability) def initialize(query_ctx, vulnerability)
......
...@@ -17,6 +17,14 @@ module Gitlab ...@@ -17,6 +17,14 @@ module Gitlab
self.class.new { yield force } self.class.new { yield force }
end 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 # Force evaluation of a (possibly) lazy value
def self.force(value) def self.force(value)
case 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