Module: Rails::GraphQL::Request::Organizable

Included in:
Component
Defined in:
lib/rails/graphql/request/steps/organizable.rb

Overview

Helper methods for the organize step of a request

Instance Method Summary collapse

Instance Method Details

#cache_dumpObject

Build the cache object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails/graphql/request/steps/organizable.rb', line 19

def cache_dump
  arguments =
    if @arguments === EMPTY_HASH
      nil
    elsif is_a?(Component::Operation)
      all_to_gid(@arguments.transform_values)
    else
      @arguments.to_h
    end

  { arguments: arguments }
end

#cache_load(data) ⇒ Object

Organize from cache data



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails/graphql/request/steps/organizable.rb', line 33

def cache_load(data)
  if (args = data[:arguments]).blank?
      @arguments = EMPTY_HASH
  elsif is_a?(Component::Operation)
    @arguments = all_from_gid(args.transform_values)

    unless defined?(@variables)
      @variables = collect_arguments(self, request.args, var_access: false).freeze
    end
  else
    @arguments = request.build(Request::Arguments, args).freeze
  end

  # Always trigger the organized event
  unless unresolvable?
    strategy.add_listeners_from(self)
    trigger_event(:organized)
  end

  # Mark component as organized
  @organized = true
end

#organize!Object

Organize the object if it is not already organized



9
10
11
12
13
14
15
16
# File 'lib/rails/graphql/request/steps/organizable.rb', line 9

def organize!
  organize unless defined?(@organized)
rescue => error
  invalidate!
  report_exception(error)
ensure
  @organized = true
end