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



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/graphql/upgrader/member.rb', line 193

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