Class: GraphQL::Upgrader::Member

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

Defined Under Namespace

Classes: FieldFinder

Constant Summary

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



731
732
733
734
735
736
737
# File 'lib/graphql/upgrader/member.rb', line 731

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



773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/graphql/upgrader/member.rb', line 773

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)


795
796
797
798
799
800
# File 'lib/graphql/upgrader/member.rb', line 795

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

  true
end