<commit_before>require "browser/aliases"

class Api::GraphqlController < ApiController

  before_action :get_app
  # before_action :authorize!

  def execute
    variables = ensure_hash(params[:variables])
    query = params[:query]
    operation_name = params[:operationName]
    context = {
      # Query context goes here, for example:
      user_data: user_data,
      app: @app,
      from_api: true,
      #authorize: lambda{|mode, object| authorize!(mode, object) },
      #can: lambda{| mode, object | can?( mode, object) },
      #logout!: ->{logout!},
      #session: session,
      set_locale: lambda{set_locale},
      auth: lambda{auth},
      get_app_user: lambda{get_app_user},
      request: request,
    }

    result = ChaskiqSchema.execute(query, 
      variables: variables, 
      context: context, 
      operation_name: operation_name,
      max_depth: 5
    )
   
    render json: result  
  
  rescue ActiveRecord::RecordNotFound => e
    render json: { 
      errors: [{ <commit_msg>Update graphql_controller.rb<commit_after>require "browser/aliases"

class Api::GraphqlController < ApiController

  before_action :get_app
  # before_action :authorize!

  def execute
    variables = ensure_hash(params[:variables])
    query = params[:query]
    operation_name = params[:operationName]
    context = {
      # Query context goes here, for example:
      user_data: user_data,
      app: @app,
      from_api: true,
      #authorize: lambda{|mode, object| authorize!(mode, object) },
      #can: lambda{| mode, object | can?( mode, object) },
      #logout!: ->{logout!},
      #session: session,
      set_locale: lambda{set_locale},
      auth: lambda{auth},
      get_app_user: lambda{get_app_user},
      request: request,
    }

    result = ChaskiqSchema.execute(query, 
      variables: variables, 
      context: context, 
      operation_name: operation_name
      #max_depth: 5
    )
   
    render json: result  
  
  rescue ActiveRecord::RecordNotFound => e
    render json: { 
      errors: [{ 
{'fraction_non_alphanumeric': 0.11067388096409247, 'fraction_numerical': 0.000983767830791933, 'mean_word_length': 2.949514563106796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6332581', 'n_tokens_mistral': 630, 'n_tokens_neox': 615, 'n_words': 147}