Class: HasuraHandler::ActionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/hasura_handler/actions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#protect_against_forgery?

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/hasura_handler/actions_controller.rb', line 7

def index
  unless HasuraHandler::Action.hasura_actions.keys.include?(raw_params['action']['name'])
    render json: { error: true, message: 'action name not registered' }, status: 404
    return
  end

  klass = HasuraHandler::Action.hasura_actions[raw_params['action']['name']]
  action = klass.new(
    clean_headers,
    raw_params['session_variables'].to_h,
    raw_params['input'].to_h
  )

  action.run
  if action.error_message.present?
    render json: { error: true, message: action.error_message }, status: 400
  else
    render json: action.output
  end
end