Class: ActiveGraphql::Model::ActionFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_graphql/model/action_formatter.rb

Overview

reformats action to default format which very opinionated and based in following assumptions:

  • all attributes and fields are camel cased

  • all mutation actions accept one or two fields: id and input (input is everyting except ‘id’)

  • collection actions are paginated and accepts input attribute ‘filter`

github graphql structure was used as inspiration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ ActionFormatter

Returns a new instance of ActionFormatter.



18
19
20
# File 'lib/active_graphql/model/action_formatter.rb', line 18

def initialize(action)
  @action = action
end

Class Method Details

.call(action) ⇒ Object



14
15
16
# File 'lib/active_graphql/model/action_formatter.rb', line 14

def self.call(action)
  new(action).call
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
# File 'lib/active_graphql/model/action_formatter.rb', line 22

def call
  action.class.new(
    name: formatted_name,
    client: action.client,
    output_values: formatted_outputs,
    input_attributes: formatted_inputs.symbolize_keys
  )
end