<commit_before>module GraphQL
  class Query
    class SerialExecution
      module ValueResolution
        def self.get_strategy_for_kind(kind)
          TYPE_KIND_STRATEGIES[kind] || raise("No value resolution strategy for #{kind}!")
        end

        class BaseResolution
          attr_reader :value, :field_type, :target, :parent_type,
            :ast_field, :query, :execution_strategy
          def initialize(value, field_type, target, parent_type, ast_field, query, execution_strategy)
            @value = value
            @field_type = field_type
            @target = target
            @parent_type = parent_type
            @ast_field = ast_field
            @query = query
            @execution_strategy = execution_strategy
          end

          def result
            return nil if value.nil?
            non_null_result
          end

          def non_null_result
            raise NotImplementedError, "Should return a value based on initialization params"
          end

          def get_strategy_for_kind(*args)
            GraphQL::Query::SerialExecution::ValueResolution.get_strategy_for_kind(*args)
          end
        end

        class ScalarResolution < BaseResolution
          # Apply the scalar's defined `coerce_result` method to the value
          def non_null_result
            field_type.coerce_result(value)
          end
        end

        class ListResolution < BaseResolution
          # For each item in the list,
          # Resolve it with the "wrapped" type of this list
          def non_null_result
            wrapped_type = field_type.of_type
            value.map do |item|
              strategy_class = get_strategy_for_kind(wrapped_type.kind)
              inner_strategy = strategy_class.new(item, wrapped_type, target, parent_type, ast_field, query, execution_strategy)
              inner_strategy.result
            end
          end
        end

        class HasPossibleTypeResolution < BaseResolution
          def non_null_result
            resolved_type = field_type.resolve_type(value)
            strategy_class = get_strategy_for_kind(resolved_type.kind)
            inner_strategy = strategy_class.new(value, resolved_type, target, parent_type, ast_field, query, execution_strategy)
            inner_strategy.result
          end
        end

        class ObjectResolution < BaseResolution
          # Resolve the selections on this object
          def non_null_result
            resolver = execution_strategy.selection_resolution.new(value, field_type, ast_field.selections, query, execution_strategy)
            resolver.result
          end
        end

        class NonNullResolution < BaseResolution
          # Get the "wrapped" type and resolve the value according to that type
          def result
            raise GraphQL::ExecutionError, "Type mismatch resolving '#{ast_field.name}'" if value.nil?
            wrapped_type = field_type.of_type<commit_msg>For lists, only compute the strategy once<commit_after>module GraphQL
  class Query
    class SerialExecution
      module ValueResolution
        def self.get_strategy_for_kind(kind)
          TYPE_KIND_STRATEGIES[kind] || raise("No value resolution strategy for #{kind}!")
        end

        class BaseResolution
          attr_reader :value, :field_type, :target, :parent_type,
            :ast_field, :query, :execution_strategy
          def initialize(value, field_type, target, parent_type, ast_field, query, execution_strategy)
            @value = value
            @field_type = field_type
            @target = target
            @parent_type = parent_type
            @ast_field = ast_field
            @query = query
            @execution_strategy = execution_strategy
          end

          def result
            return nil if value.nil?
            non_null_result
          end

          def non_null_result
            raise NotImplementedError, "Should return a value based on initialization params"
          end

          def get_strategy_for_kind(*args)
            GraphQL::Query::SerialExecution::ValueResolution.get_strategy_for_kind(*args)
          end
        end

        class ScalarResolution < BaseResolution
          # Apply the scalar's defined `coerce_result` method to the value
          def non_null_result
            field_type.coerce_result(value)
          end
        end

        class ListResolution < BaseResolution
          # For each item in the list,
          # Resolve it with the "wrapped" type of this list
          def non_null_result
            wrapped_type = field_type.of_type
            strategy_class = get_strategy_for_kind(wrapped_type.kind)
            value.map do |item|
              inner_strategy = strategy_class.new(item, wrapped_type, target, parent_type, ast_field, query, execution_strategy)
              inner_strategy.result
            end
          end
        end

        class HasPossibleTypeResolution < BaseResolution
          def non_null_result
            resolved_type = field_type.resolve_type(value)
            strategy_class = get_strategy_for_kind(resolved_type.kind)
            inner_strategy = strategy_class.new(value, resolved_type, target, parent_type, ast_field, query, execution_strategy)
            inner_strategy.result
          end
        end

        class ObjectResolution < BaseResolution
          # Resolve the selections on this object
          def non_null_result
            resolver = execution_strategy.selection_resolution.new(value, field_type, ast_field.selections, query, execution_strategy)
            resolver.result
          end
        end

        class NonNullResolution < BaseResolution
          # Get the "wrapped" type and resolve the value according to that type
          def result
            raise GraphQL::ExecutionError, "Type mismatch resolving '#{ast_field.name}'" if value.nil?
            wrapped_type = field_type.of_type
{'fraction_non_alphanumeric': 0.05311973018549747, 'fraction_numerical': 0.0, 'mean_word_length': 2.146419098143236, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3222802', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1527, 'n_words': 405}