class GraphQL::Upgrader::UpdateMethodSignatureTransform

def apply(input_text)

def apply(input_text)
  input_text.scan(/(?:input_field|field|return_field|connection|argument) .*$/).each do |field|
    matches = /(?<field_type>input_field|return_field|field|connection|argument) :(?<name>[a-zA-Z_0-9_]*)?(:?, +(?<return_type>([A-Za-z\[\]\.\!_0-9\(\)]|::|-> ?\{ ?| ?\})+))?(?<remainder>( |,|$).*)/.match(field)
    if matches
      name = matches[:name]
      return_type = matches[:return_type]
      remainder = matches[:remainder]
      field_type = matches[:field_type]
      with_block = remainder.gsub!(/\ do$/, '')
      remainder.gsub! /,$/, ''
      remainder.gsub! /^,/, ''
      remainder.chomp!
      if return_type
        non_nullable = return_type.sub! /(^|[^\[])!/, '\1'
        non_nullable ||= return_type.sub! /([^\[])\.to_non_null_type([^\]]|$)/, '\1'
        nullable = !non_nullable
        return_type = normalize_type_expression(return_type)
      else
        non_nullable = nil
        nullable = nil
      end
      input_text.sub!(field) do
        is_argument = ['argument', 'input_field'].include?(field_type)
        f = "#{is_argument ? 'argument' : 'field'} :#{name}"
        if return_type
          f += ", #{return_type}"
        end
        unless remainder.empty?
          f += ',' + remainder
        end
        if is_argument
          if nullable
            f += ', required: false'
          elsif non_nullable
            f += ', required: true'
          end
        else
          if nullable
            f += ', null: true'
          elsif non_nullable
            f += ', null: false'
          end
        end
        if field_type == 'connection'
          f += ', connection: true'
        end
        if with_block
          f += ' do'
        end
        f
      end
    end
  end
  input_text
end