class GraphQL::Upgrader::RemoveRedundantKwargTransform
Find a keyword whose value is a string or symbol, and if the value is equivalent to the field name, remove the keyword altogether.
Public Class Methods
new(kwarg:)
click to toggle source
# File lib/graphql/upgrader/member.rb, line 246 def initialize(kwarg:) @kwarg = kwarg @finder_pattern = /(field|return_field|input_field|connection|argument) :(?<name>[a-zA-Z_0-9]*).*#{@kwarg}: ['":](?<kwarg_value>[a-zA-Z_0-9?!]+)['"]?/ end
Public Instance Methods
apply(input_text)
click to toggle source
# File lib/graphql/upgrader/member.rb, line 251 def apply(input_text) if input_text =~ @finder_pattern field_name = $~[:name] kwarg_value = $~[:kwarg_value] if field_name == kwarg_value # It's redundant, remove it input_text = input_text.sub(/, #{@kwarg}: ['":]#{kwarg_value}['"]?/, "") end end input_text end