Class: GraphQL::Upgrader::PositionalTypeArgTransform

Inherits:
Transform
  • Object
show all
Defined in:
lib/graphql/upgrader/member.rb

Overview

Move type X to be the second positional argument to field ...

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



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/graphql/upgrader/member.rb', line 189

def apply(input_text)
  input_text.gsub(
    /(?<field>(?:field|input_field|return_field|connection|argument) :(?:[a-zA-Z_0-9]*)) do(?<block_contents>.*?)[ ]*type (?<return_type>.*?)\n/m
  ) do
    field = $~[:field]
    block_contents = $~[:block_contents]
    return_type = normalize_type_expression($~[:return_type], preserve_bang: true)

    "#{field}, #{return_type} do#{block_contents}"
  end
end