Module: Graphiti::ActiveGraph::Runner

Defined in:
lib/graphiti/active_graph/runner.rb

Instance Method Summary collapse

Instance Method Details

#initialize(resource_class, params, query = nil, action = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/graphiti/active_graph/runner.rb', line 3

def initialize(resource_class, params, query = nil, action = nil)
  @resource_class = resource_class
  @params = params
  @query = query
  @action = action

  validator = ::Graphiti::RequestValidator.new(jsonapi_resource, params, action)

  validator.validate! unless params[:skip_render_val]

  @deserialized_payload = validator.deserialized_payload
end

#proxy(base = nil, opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/graphiti/active_graph/runner.rb', line 16

def proxy(base = nil, opts = {})
  base ||= jsonapi_resource.base_scope
  scope_opts = opts.slice(:sideload_parent_length,
    :default_paginate,
    :after_resolve,
    :sideload,
    :parent,
    :params,
    :preloaded).merge(unpaginated_query: params[:unpaginated_query])
  scope = jsonapi_scope(base, scope_opts)
  preloaded = opts[:preloaded]
  options = { payload: deserialized_payload,
    single: opts[:single],
    raise_on_missing: opts[:raise_on_missing],
    preloaded: preloaded
  }
  ::Graphiti::ResourceProxy.new jsonapi_resource,
    scope,
    query,
    **options
end