Class: Tasker::GraphqlController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tasker/graphql_controller.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/tasker/graphql_controller.rb', line 16

def execute
  variables = prepare_variables(params[:variables])
  query = params[:query]
  operation_name = params[:operationName]

  # Authorize GraphQL operations before execution
  authorize_graphql_operations!(query, operation_name) if authorization_enabled?

  context = {
    # Query context goes here, for example:
    current_user: current_tasker_user,
    authenticated: tasker_user_authenticated?
  }
  result = Tasker::TaskerRailsSchema.execute(query, variables: variables, context: context,
                                                    operation_name: operation_name)
  render(json: result)
rescue StandardError => e
  raise(e) unless Rails.env.development?

  handle_error_in_development(e)
end