<commit_before># frozen_string_literal: true
module GraphQL
  class Schema
    # Visit the members of this schema and build up artifacts for runtime.
    # @api private
    class Traversal
      # @return [Hash<String => GraphQL::BaseType]
      attr_reader :type_map

      # @return [Hash<String => Hash<String => GraphQL::Field>>]
      attr_reader :instrumented_field_map

      # @param schema [GraphQL::Schema]
      def initialize(schema, introspection: true)
        @schema = schema
        @introspection = introspection
        @field_instrumenters =
          schema.instrumenters[:field] +
            Schema::BUILT_IN_INSTRUMENTERS +
            schema.instrumenters[:field_after_built_ins]

        @type_map = {}
        @instrumented_field_map = Hash.new { |h, k| h[k] = {} }
        visit(schema, nil)
      end

      private

      def visit(member, context_description)
        case member
        when GraphQL::Schema
          member.directives.each { |name, directive| visit(directive, name) }
          # Find the starting points, then visit them
          visit_roots = [member.query, member.mutation, member.subscription]
          if @introspection
            visit_roots << GraphQL::Introspection::SchemaType
          end
          visit_roots.concat(member.orphan_types)
          visit_roots.compact!
          visit_roots.each { |t| visit(t, t.name) }
        when GraphQL::Directive
          member.arguments.each do |name, argument|
            visit(argument.type, "Directive argument #{member.name}.#{name}")
          end
        when GraphQL::BaseType
          type_defn = member.unwrap
          prev_type = @type_map[type_defn.name]
          # Continue to visit this type if it's the first time we've seen it:
          if prev_type.nil?
            validate_type(type_defn, context_description)
            @type_map[type_defn.name] = type_defn
            case type_defn
            when GraphQL::ObjectType<commit_msg>Better context_description for directives in Traversal<commit_after># frozen_string_literal: true
module GraphQL
  class Schema
    # Visit the members of this schema and build up artifacts for runtime.
    # @api private
    class Traversal
      # @return [Hash<String => GraphQL::BaseType]
      attr_reader :type_map

      # @return [Hash<String => Hash<String => GraphQL::Field>>]
      attr_reader :instrumented_field_map

      # @param schema [GraphQL::Schema]
      def initialize(schema, introspection: true)
        @schema = schema
        @introspection = introspection
        @field_instrumenters =
          schema.instrumenters[:field] +
            Schema::BUILT_IN_INSTRUMENTERS +
            schema.instrumenters[:field_after_built_ins]

        @type_map = {}
        @instrumented_field_map = Hash.new { |h, k| h[k] = {} }
        visit(schema, nil)
      end

      private

      def visit(member, context_description)
        case member
        when GraphQL::Schema
          member.directives.each { |name, directive| visit(directive, "Directive #{name}") }
          # Find the starting points, then visit them
          visit_roots = [member.query, member.mutation, member.subscription]
          if @introspection
            visit_roots << GraphQL::Introspection::SchemaType
          end
          visit_roots.concat(member.orphan_types)
          visit_roots.compact!
          visit_roots.each { |t| visit(t, t.name) }
        when GraphQL::Directive
          member.arguments.each do |name, argument|
            visit(argument.type, "Directive argument #{member.name}.#{name}")
          end
        when GraphQL::BaseType
          type_defn = member.unwrap
          prev_type = @type_map[type_defn.name]
          # Continue to visit this type if it's the first time we've seen it:
          if prev_type.nil?
            validate_type(type_defn, context_description)
            @type_map[type_defn.name] = type_defn
            case type_defn
            when GraphQL::ObjectType
{'fraction_non_alphanumeric': 0.08901705115346038, 'fraction_numerical': 0.0, 'mean_word_length': 2.389124893797791, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4416943', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1121, 'n_words': 271}