Module: ActiveGraphql::Client::Actions::VariableDetectable

Included in:
Action, Action::FormatInputs, Action::FormatVariableInputs
Defined in:
lib/active_graphql/client/actions/variable_detectable.rb

Overview

handles all action details which are specific for query type request

Instance Method Summary collapse

Instance Method Details

#variable_attributes(attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/active_graphql/client/actions/variable_detectable.rb', line 8

def variable_attributes(attributes)
  variables_or_nil = attributes.transform_values do |value|
    if value.is_a?(Hash)
      variable_attributes(value)
    elsif variable_value?(value)
      value
    elsif value.is_a?(Array)
      variable_attributes(value.map.with_index { |val, i| [i, val] }.to_h)
    end
  end

  flatten_keys(variables_or_nil).select { |_, val| val.present? }
end

#variable_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/active_graphql/client/actions/variable_detectable.rb', line 22

def variable_value?(value)
  kind_of_file?(value) || (value.is_a?(Array) && kind_of_file?(value.first))
end