Module: GraphQL::SchemaComparator::Changes::SafeTypeChange

Included in:
DirectiveArgumentTypeChanged, FieldArgumentTypeChanged, FieldTypeChanged, InputFieldTypeChanged
Defined in:
lib/graphql/schema_comparator/changes/safe_type_change.rb

Instance Method Summary collapse

Instance Method Details

#safe_change_for_field?(old_type, new_type) ⇒ Boolean


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/graphql/schema_comparator/changes/safe_type_change.rb', line 5

def safe_change_for_field?(old_type, new_type)
  if !old_type.kind.wraps? && !new_type.kind.wraps?
    old_type == new_type
  elsif new_type.kind.non_null?
    of_type = old_type.kind.non_null? ? old_type.of_type : old_type
    safe_change_for_field?(of_type, new_type.of_type)
  elsif old_type.kind.list?
    new_type.kind.list? && safe_change_for_field?(old_type.of_type, new_type.of_type) ||
      new_type.kind.non_null? && safe_change_for_field?(old_type, new_type.of_type)
  else
    false
  end
end

#safe_change_for_input_value?(old_type, new_type) ⇒ Boolean


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql/schema_comparator/changes/safe_type_change.rb', line 19

def safe_change_for_input_value?(old_type, new_type)
  if !old_type.kind.wraps? && !new_type.kind.wraps?
    old_type == new_type
  elsif old_type.kind.list? && new_type.kind.list?
    safe_change_for_input_value?(old_type.of_type, new_type.of_type)
  elsif old_type.kind.non_null?
    of_type = new_type.kind.non_null? ? new_type.of_type : new_type
    safe_change_for_input_value?(old_type.of_type, of_type)
  else
    false
  end
end