Module: GraphQL::FragmentCache::ObjectHelpers
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/fragment_cache/object_helpers.rb
Overview
Adds #cache_fragment method
Constant Summary collapse
- NO_OBJECT =
Object.new
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
Instance Method Details
#cache_fragment(object_to_cache = NO_OBJECT, **options, &block) ⇒ Object
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 |
# File 'lib/graphql/fragment_cache/object_helpers.rb', line 26 def cache_fragment(object_to_cache = NO_OBJECT, **, &block) raise ArgumentError, "Block or argument must be provided" unless block || object_to_cache != NO_OBJECT unless GraphQL::FragmentCache.enabled return block ? block.call : object_to_cache end unless .delete(:default_options_merged) = GraphQL::FragmentCache..merge() end if .key?(:if) || .key?(:unless) disabled = .key?(:if) ? !.delete(:if) : .delete(:unless) if disabled return block ? block.call : object_to_cache end end [:object] = object_to_cache if object_to_cache != NO_OBJECT context_to_use = .delete(:context) context_to_use = context if context_to_use.nil? && respond_to?(:context) raise ArgumentError, "cannot find context, please pass it explicitly" unless context_to_use fragment = Fragment.new(context_to_use, **) GraphQL::FragmentCache::Schema::LazyCacheResolver.new(fragment, context_to_use, object_to_cache, &block) end |