Module: ActiveAdmin::GraphQL::SchemaBuilder::GraphParams

Included in:
ActiveAdmin::GraphQL::SchemaBuilder
Defined in:
lib/active_admin/graphql/schema_builder/graph_params.rb

Instance Method Summary collapse

Instance Method Details

#assignable_slice_from_input(aa_res, input) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 31

def assignable_slice_from_input(aa_res, input)
  blob = input.to_h.stringify_keys
  names = aa_res.graphql_assignable_attribute_names.map(&:to_s)
  if (btc = aa_res.belongs_to_config)
    names -= [btc.to_param.to_s]
  end
  blob.slice(*names)
end

#graph_params_for_mutation(aa_res, kw) ⇒ Object



15
16
17
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 15

def graph_params_for_mutation(aa_res, kw)
  merge_belongs_to_kw!(aa_res, kw, {})
end

#graph_params_from_field_kwargs(aa_res, scope: nil, q: nil, order: nil, **kw) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 7

def graph_params_from_field_kwargs(aa_res, scope: nil, q: nil, order: nil, **kw)
  h = {}
  h[:scope] = scope if scope.present?
  h[:q] = q if !q.nil?
  h[:order] = order if order.present?
  merge_belongs_to_kw!(aa_res, kw, h)
end

#graph_params_from_find_blob(aa_res, blob) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 55

def graph_params_from_find_blob(aa_res, blob)
  h = {}
  if (btc = aa_res.belongs_to_config)
    k = btc.to_param.to_s
    h[k] = blob[k] if blob.key?(k)
  end
  h
end

#graph_params_from_input(aa_res, input) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 19

def graph_params_from_input(aa_res, input)
  h = {}
  return h if input.nil?

  blob = input.to_h.stringify_keys
  if (btc = aa_res.belongs_to_config)
    k = btc.to_param.to_s
    h[k] = blob[k] if blob.key?(k) && blob[k].present?
  end
  h
end

#list_graph_params(aa_res, filter:, scope:, q:, order:, **kw) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 40

def list_graph_params(aa_res, filter:, scope:, q:, order:, **kw)
  h = graph_params_from_field_kwargs(aa_res, scope: scope, q: q, order: order, **kw)
  return h unless filter

  fh = filter.to_h.stringify_keys
  h["scope"] = fh["scope"] if fh.key?("scope")
  h["order"] = fh["order"] if fh.key?("order")
  h["q"] = fh["q"] if fh.key?("q")
  if (btc = aa_res.belongs_to_config)
    pk = btc.to_param.to_s
    h[pk] = fh[pk] if fh.key?(pk)
  end
  h
end

#merge_belongs_to_kw!(aa_res, kw, h) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/active_admin/graphql/schema_builder/graph_params.rb', line 64

def merge_belongs_to_kw!(aa_res, kw, h)
  if (btc = aa_res.belongs_to_config)
    key = btc.to_param
    val = kw[key] || kw[key.to_s] || kw[key.to_sym]
    h[key] = val if val.present?
  end
  h
end