class GraphQL::Query::Context::ScopedContext
Public Class Methods
Source
# File lib/graphql/query/context/scoped_context.rb, line 7 def initialize(query_context) @query_context = query_context @scoped_contexts = nil @all_keys = nil end
Public Instance Methods
Source
# File lib/graphql/query/context/scoped_context.rb, line 47 def [](key) each_present_path_ctx do |path_ctx| if path_ctx.key?(key) return path_ctx[key] end end nil end
Source
# File lib/graphql/query/context/scoped_context.rb, line 56 def current_path @query_context.current_path || GraphQL::EmptyObjects::EMPTY_ARRAY end
Source
# File lib/graphql/query/context/scoped_context.rb, line 60 def dig(key, *other_keys) each_present_path_ctx do |path_ctx| if path_ctx.key?(key) found_value = path_ctx[key] if !other_keys.empty? return found_value.dig(*other_keys) else return found_value end end end nil end
Source
# File lib/graphql/query/context/scoped_context.rb, line 36 def key?(key) if @all_keys && @all_keys.include?(key) each_present_path_ctx do |path_ctx| if path_ctx.key?(key) return true end end end false end
# File lib/graphql/query/context/scoped_context.rb, line 25 def merge!(hash, at: current_path) @all_keys ||= Set.new @all_keys.merge(hash.keys) ctx = @scoped_contexts ||= {} at.each do |path_part| ctx = ctx[path_part] ||= { parent: ctx } end this_scoped_ctx = ctx[:scoped_context] ||= {} this_scoped_ctx.merge!(hash) end
Source
# File lib/graphql/query/context/scoped_context.rb, line 13 def merged_context if @scoped_contexts.nil? GraphQL::EmptyObjects::EMPTY_HASH else merged_ctx = {} #: untyped each_present_path_ctx do |path_ctx| merged_ctx = path_ctx.merge(merged_ctx) end merged_ctx end end