Class: GraphQL::Upgrader::Member

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

Defined Under Namespace

Classes: FieldFinder

Constant Summary collapse

DEFAULT_TYPE_TRANSFORMS =
[
  TypeDefineToClassTransform,
  MutationResolveProcToMethodTransform, # Do this before switching to class, so we can detect that its a mutation
  UnderscorizeMutationHashTransform,
  MutationDefineToClassTransform,
  NameTransform,
  InterfacesToImplementsTransform,
  PossibleTypesTransform,
  ProcToClassMethodTransform.new("coerce_input"),
  ProcToClassMethodTransform.new("coerce_result"),
  ProcToClassMethodTransform.new("resolve_type"),
]
DEFAULT_FIELD_TRANSFORMS =
[
  RemoveNewlinesTransform,
  RemoveMethodParensTransform,
  PositionalTypeArgTransform,
  ConfigurationToKwargTransform.new(kwarg: "property"),
  ConfigurationToKwargTransform.new(kwarg: "description"),
  ConfigurationToKwargTransform.new(kwarg: "deprecation_reason"),
  ConfigurationToKwargTransform.new(kwarg: "hash_key"),
  PropertyToMethodTransform,
  UnderscoreizeFieldNameTransform,
  ResolveProcToMethodTransform,
  UpdateMethodSignatureTransform,
  RemoveRedundantKwargTransform.new(kwarg: "hash_key"),
  RemoveRedundantKwargTransform.new(kwarg: "method"),
]
DEFAULT_CLEAN_UP_TRANSFORMS =
[
  RemoveExcessWhitespaceTransform,
  RemoveEmptyBlocksTransform,
]

Instance Method Summary collapse

Constructor Details

#initialize(member, skip: SkipOnNullKeyword, type_transforms: DEFAULT_TYPE_TRANSFORMS, field_transforms: DEFAULT_FIELD_TRANSFORMS, clean_up_transforms: DEFAULT_CLEAN_UP_TRANSFORMS) ⇒ Member

Returns a new instance of Member.


773
774
775
776
777
778
779
# File 'lib/graphql/upgrader/member.rb', line 773

def initialize(member, skip: SkipOnNullKeyword, type_transforms: DEFAULT_TYPE_TRANSFORMS, field_transforms: DEFAULT_FIELD_TRANSFORMS, clean_up_transforms: DEFAULT_CLEAN_UP_TRANSFORMS)
  @member = member
  @skip = skip
  @type_transforms = type_transforms
  @field_transforms = field_transforms
  @clean_up_transforms = clean_up_transforms
end

Instance Method Details

#upgradeObject


815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'lib/graphql/upgrader/member.rb', line 815

def upgrade
  type_source = @member.dup
  should_skip = @skip.new.skip?(type_source)
  # return the unmodified code
  if should_skip
    return type_source
  end
  # Transforms on type defn code:
  type_source = apply_transforms(type_source, @type_transforms)
  # Transforms on each field:
  field_sources = find_fields(type_source)
  field_sources.each do |field_source|
    transformed_field_source = apply_transforms(field_source.dup, @field_transforms)
    # Replace the original source code with the transformed source code:
    type_source = type_source.gsub(field_source, transformed_field_source)
  end
  # Clean-up:
  type_source = apply_transforms(type_source, @clean_up_transforms)
  # Return the transformed source:
  type_source
end

#upgradeable?Boolean

Returns:

  • (Boolean)

837
838
839
840
841
842
# File 'lib/graphql/upgrader/member.rb', line 837

def upgradeable?
  return false if @member.include? '< GraphQL::Schema::'
  return false if @member =~ /< Types::Base#{GRAPHQL_TYPES}/

  true
end