Class: GraphQL::SchemaComparator::Diff::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema_comparator/diff/field.rb

Instance Method Summary collapse

Constructor Details

#initialize(old_type, new_type, old_field, new_field) ⇒ Field

Returns a new instance of Field.



5
6
7
8
9
10
11
12
13
14
# File 'lib/graphql/schema_comparator/diff/field.rb', line 5

def initialize(old_type, new_type, old_field, new_field)
  @old_type = old_type
  @new_type = new_type

  @old_field = old_field
  @new_field = new_field

  @old_arguments = old_field.arguments
  @new_arguments = new_field.arguments
end

Instance Method Details

#diffObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/graphql/schema_comparator/diff/field.rb', line 16

def diff
  changes = []

  if old_field.description != new_field.description
    changes << Changes::FieldDescriptionChanged.new(new_type, old_field, new_field)
  end

  if old_field.deprecation_reason != new_field.deprecation_reason
    changes << Changes::FieldDeprecationChanged.new(new_type, old_field, new_field)
  end

  if old_field.type.to_type_signature != new_field.type.to_type_signature
    changes << Changes::FieldTypeChanged.new(new_type, old_field, new_field)
  end

  changes += arg_removals

  changes += arg_additions

  each_common_argument do |old_arg, new_arg|
    changes += Diff::Argument.new(new_type, new_field, old_arg, new_arg).diff
  end

  changes
end