<commit_before># frozen_string_literal: true

module Api
  module Internal
    class GraphqlController < ActionController::Base
      include Analyzable
      include LogrageSetting
      include RavenContext

      skip_before_action :verify_authenticity_token
      before_action :authenticate_user!

      def execute
        variables = ensure_hash(params[:variables])
        query = params[:query]
        context = {
          writable: true,
          admin: true,
          viewer: current_user
        }
        result = ::Canary::AnnictSchema.execute(query, variables: variables, context: context)
        render json: result
      end

      private

      # Handle form data, JSON body, or a blank value
      def ensure_hash(ambiguous_param)
        case ambiguous_param
        when String
          if ambiguous_param.present?
            ensure_hash(JSON.parse(ambiguous_param))
          else
            {}
          end
        when Hash, ActionController::Parameters
          ambiguous_param
        when nil
          {}
        else
          raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
        end
      end
    end
  end
end
<commit_msg>Remove authenticate_user! callback<commit_after># frozen_string_literal: true

module Api
  module Internal
    class GraphqlController < ActionController::Base
      include Analyzable
      include LogrageSetting
      include RavenContext

      skip_before_action :verify_authenticity_token

      def execute
        variables = ensure_hash(params[:variables])
        query = params[:query]
        context = {
          writable: true,
          admin: true,
          viewer: current_user
        }
        result = ::Canary::AnnictSchema.execute(query, variables: variables, context: context)
        render json: result
      end

      private

      # Handle form data, JSON body, or a blank value
      def ensure_hash(ambiguous_param)
        case ambiguous_param
        when String
          if ambiguous_param.present?
            ensure_hash(JSON.parse(ambiguous_param))
          else
            {}
          end
        when Hash, ActionController::Parameters
          ambiguous_param
        when nil
          {}
        else
          raise ArgumentError, "Unexpected parameter: #{ambiguous_param}"
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.05752023860247124, 'fraction_numerical': 0.0, 'mean_word_length': 2.0533159947984396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3515075', 'n_tokens_mistral': 598, 'n_tokens_neox': 579, 'n_words': 162}