Class: GraphQL::Upgrader::UnderscorizeMutationHashTransform
- Defined in:
- lib/graphql/upgrader/member.rb
Overview
Find hash literals which are returned from mutation resolves, and convert their keys to underscores. This catches a lot of cases but misses hashes which are initialized anywhere except in the return expression.
Defined Under Namespace
Classes: ReturnedHashLiteralProcessor
Instance Method Summary collapse
Methods inherited from Transform
#apply_processor, #normalize_type_expression, #reindent_lines, #trim_lines, #underscorize
Instance Method Details
#apply(input_text) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/graphql/upgrader/member.rb', line 410 def apply(input_text) if input_text =~ /def resolve\(\*\*/ processor = apply_processor(input_text, ReturnedHashLiteralProcessor.new) # Use reverse_each to avoid messing up positions processor.keys_to_upgrade.reverse_each do |key_data| underscored_key = underscorize(key_data[:key].to_s) if key_data[:operator] == ":" input_text[key_data[:start]...key_data[:end]] = underscored_key else input_text[key_data[:start]...key_data[:end]] = ":#{underscored_key}" end end end input_text end |