Class: GraphqlMigrateExecution::FieldDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_migrate_execution/field_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_definition, name, node) ⇒ FieldDefinition

Returns a new instance of FieldDefinition.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/graphql_migrate_execution/field_definition.rb', line 4

def initialize(type_definition, name, node)
  @type_definition = type_definition
  @name = name.to_sym
  @node = node

  @resolve_mode = nil
  @hash_key = nil
  @resolver = nil
  @type_instance_method = nil
  @object_direct_method = nil
  @dig = nil
  @fallback_value = nil
  @already_migrated = nil

  @resolver_method = nil
  @unknown_options = []
end

Instance Attribute Details

#already_migratedObject

Returns the value of attribute already_migrated.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def already_migrated
  @already_migrated
end

#digObject

Returns the value of attribute dig.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def dig
  @dig
end

#fallback_valueObject

Returns the value of attribute fallback_value.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def fallback_value
  @fallback_value
end

#hash_keyObject

Returns the value of attribute hash_key.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def hash_key
  @hash_key
end

#nameObject (readonly)

Returns the value of attribute name.



66
67
68
# File 'lib/graphql_migrate_execution/field_definition.rb', line 66

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



66
67
68
# File 'lib/graphql_migrate_execution/field_definition.rb', line 66

def node
  @node
end

#object_direct_methodObject

Returns the value of attribute object_direct_method.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def object_direct_method
  @object_direct_method
end

#resolve_modeObject

Returns the value of attribute resolve_mode.



66
67
68
# File 'lib/graphql_migrate_execution/field_definition.rb', line 66

def resolve_mode
  @resolve_mode
end

#resolverObject

Returns the value of attribute resolver.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def resolver
  @resolver
end

#type_definitionObject (readonly)

Returns the value of attribute type_definition.



66
67
68
# File 'lib/graphql_migrate_execution/field_definition.rb', line 66

def type_definition
  @type_definition
end

#type_instance_methodObject

Returns the value of attribute type_instance_method.



79
80
81
# File 'lib/graphql_migrate_execution/field_definition.rb', line 79

def type_instance_method
  @type_instance_method
end

#unknown_optionsObject (readonly)

Returns the value of attribute unknown_options.



66
67
68
# File 'lib/graphql_migrate_execution/field_definition.rb', line 66

def unknown_options
  @unknown_options
end

Instance Method Details

#check_for_resolver_methodObject



110
111
112
113
114
115
116
# File 'lib/graphql_migrate_execution/field_definition.rb', line 110

def check_for_resolver_method
  if resolve_mode.nil? && (resolver_method)
    @resolve_mode = :type_instance_method
    @type_instance_method = @name
  end
  nil
end

#future_resolve_shorthandObject



72
73
74
75
# File 'lib/graphql_migrate_execution/field_definition.rb', line 72

def future_resolve_shorthand
  method_name = Strategy.prefix_if_necessary(resolver_method.name).to_sym
  name == method_name ? true : method_name
end

#implicit_resolveObject



102
103
104
# File 'lib/graphql_migrate_execution/field_definition.rb', line 102

def implicit_resolve
  @name
end

#migration_strategyObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/graphql_migrate_execution/field_definition.rb', line 22

def migration_strategy
  if unsupported_extras?
    return UnsupportedExtra
  elsif resolver_method&.uses_current_path
    return UnsupportedCurrentPath
  end

  if @type_definition.is_resolver && @type_definition.returns_hash?
    return HashKey
  end

  case resolve_mode
  when nil, :implicit_resolve
    if @type_definition.migration.implicit == "ignore"
      DoNothing
    else
      Implicit
    end
  when :hash_key, :object_direct_method, :dig
    DoNothing
  when :already_migrated
    case @already_migrated.keys.first
    when :resolve_each
      ResolveEach
    when :resolve_static
      ResolveStatic
    when :resolve_batch
      ResolveBatch
    when :resolve_legacy_instance_method
      DoNothing
    else
      raise ArgumentError, "Unexpected already_migrated: #{@already_migrated.inspect}"
    end
  when :type_instance_method
    resolver_method.migration_strategy
  when :resolver
    DoNothing
  when :fallback_value
    FallbackValue
  else
    raise "No migration strategy for resolve_mode #{@resolve_mode.inspect}"
  end
end

#pathObject



81
82
83
# File 'lib/graphql_migrate_execution/field_definition.rb', line 81

def path
  @path ||= "#{type_definition.name}.#{@name}"
end

#resolve_mode_keyObject



106
107
108
# File 'lib/graphql_migrate_execution/field_definition.rb', line 106

def resolve_mode_key
  resolve_mode && public_send(resolve_mode)
end

#resolver_methodObject



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/graphql_migrate_execution/field_definition.rb', line 89

def resolver_method
  case @resolver_method
  when nil
    method_name = @type_instance_method || @name
    @resolver_method = @type_definition.resolver_methods[method_name] || :NOT_FOUND
    resolver_method
  when :NOT_FOUND
    nil
  else
    @resolver_method
  end
end

#sourceObject



68
69
70
# File 'lib/graphql_migrate_execution/field_definition.rb', line 68

def source
  node.location.slice
end

#source_lineObject



85
86
87
# File 'lib/graphql_migrate_execution/field_definition.rb', line 85

def source_line
  @node.location.start_line
end