Class: GraphQL::SchemaComparator::Diff::Enum

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

Instance Method Summary collapse

Constructor Details

#initialize(old_enum, new_enum) ⇒ Enum

Returns a new instance of Enum


5
6
7
8
9
10
11
# File 'lib/graphql/schema_comparator/diff/enum.rb', line 5

def initialize(old_enum, new_enum)
  @old_enum = old_enum
  @new_enum = new_enum

  @old_values = old_enum.values
  @new_values = new_enum.values
end

Instance Method Details

#diffObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/graphql/schema_comparator/diff/enum.rb', line 13

def diff
  changes = []

  changes += removed_values.map { |value| Changes::EnumValueRemoved.new(old_enum, value) }
  changes += added_values.map { |value| Changes::EnumValueAdded.new(new_enum, value) }

  each_common_value do |old_value, new_value|
    # TODO: Add Directive Stuff

    if old_value.description != new_value.description
      changes << Changes::EnumValueDescriptionChanged.new(new_enum, old_value, new_value)
    end

    if old_value.deprecation_reason != new_value.deprecation_reason
      changes << Changes::EnumValueDeprecated.new(new_enum, old_value, new_value)
    end
  end

  changes
end