Class: ActiveGraphql::Client::Actions::Action

Inherits:
Object
  • Object
show all
Includes:
VariableDetectable
Defined in:
lib/active_graphql/client/actions/action.rb,
lib/active_graphql/client/actions/action/format_inputs.rb,
lib/active_graphql/client/actions/action/format_outputs.rb,
lib/active_graphql/client/actions/action/format_variable_inputs.rb

Overview

Base class for query/mutation action objects

Direct Known Subclasses

MutationAction, QueryAction

Defined Under Namespace

Classes: FormatInputs, FormatOutputs, FormatVariableInputs, InvalidActionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VariableDetectable

#variable_attributes, #variable_value?

Constructor Details

#initialize(name:, client:, output_values: [], input_attributes: {}, meta_attributes: {}) ⇒ Action

Returns a new instance of Action.



21
22
23
24
25
26
27
# File 'lib/active_graphql/client/actions/action.rb', line 21

def initialize(name:, client:, output_values: [], input_attributes: {}, meta_attributes: {})
  @name = name
  @output_values = output_values
  @input_attributes = input_attributes
  @meta_attributes = meta_attributes
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def client
  @client
end

#input_attributesObject (readonly)

Returns the value of attribute input_attributes.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def input_attributes
  @input_attributes
end

#meta_attributesObject (readonly)

Returns the value of attribute meta_attributes.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def meta_attributes
  @meta_attributes
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def name
  @name
end

#output_valuesObject (readonly)

Returns the value of attribute output_values.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def output_values
  @output_values
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/active_graphql/client/actions/action.rb', line 17

def type
  @type
end

Instance Method Details

#graphql_variablesObject



78
79
80
# File 'lib/active_graphql/client/actions/action.rb', line 78

def graphql_variables
  variable_attributes(input_attributes)
end

#inspectObject



29
30
31
32
33
34
35
36
# File 'lib/active_graphql/client/actions/action.rb', line 29

def inspect
  "#<#{self.class} " \
    "name: #{name.inspect}, " \
    "input: #{input_attributes.inspect}, " \
    "output: #{output_values.inspect}, " \
    "meta: #{meta_attributes.inspect}" \
    '>'
end

#meta(new_attributes) ⇒ Object



51
52
53
# File 'lib/active_graphql/client/actions/action.rb', line 51

def meta(new_attributes)
  chain(meta_attributes: meta_attributes.merge(new_attributes))
end

#reselect(*array_outputs, **hash_outputs) ⇒ Object



55
56
57
58
# File 'lib/active_graphql/client/actions/action.rb', line 55

def reselect(*array_outputs, **hash_outputs)
  outputs = join_array_and_hash(*array_outputs, **hash_outputs)
  chain(output_values: outputs)
end

#responseObject



47
48
49
# File 'lib/active_graphql/client/actions/action.rb', line 47

def response
  client.post(self)
end

#rewhere(**input_attributes) ⇒ Object



38
39
40
# File 'lib/active_graphql/client/actions/action.rb', line 38

def rewhere(**input_attributes)
  chain(input_attributes: input_attributes)
end

#select(*array_outputs, **hash_outputs) ⇒ Object Also known as: output



60
61
62
63
# File 'lib/active_graphql/client/actions/action.rb', line 60

def select(*array_outputs, **hash_outputs)
  full_array_outputs = (output_values + array_outputs).uniq
  reselect(*full_array_outputs, **hash_outputs)
end

#to_graphqlObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/active_graphql/client/actions/action.rb', line 66

def to_graphql
  assert_format

  <<~TXT
    #{type}#{wrapped_header formatted_variable_headers} {
      #{name}#{wrapped_header formatted_inputs} {
        #{formatted_outputs}
      }
    }
  TXT
end

#where(**extra_input_attributes) ⇒ Object Also known as: input



42
43
44
# File 'lib/active_graphql/client/actions/action.rb', line 42

def where(**extra_input_attributes)
  rewhere(**input_attributes, **extra_input_attributes)
end