Class: GraphQL::SchemaComparator::Diff::Directive

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

Instance Method Summary collapse

Constructor Details

#initialize(old_directive, new_directive) ⇒ Directive

Returns a new instance of Directive.



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

def initialize(old_directive, new_directive)
  @old_directive = old_directive
  @new_directive = new_directive
  @old_arguments = old_directive.arguments
  @new_arguments = new_directive.arguments
end

Instance Method Details

#diffObject



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

def diff
  changes = []

  if old_directive.description != new_directive.description
    changes << Changes::DirectiveDescriptionChanged.new(old_directive, new_directive)
  end

  changes += removed_locations.map { |location| Changes::DirectiveLocationRemoved.new(new_directive, location) }
  changes += added_locations.map { |location| Changes::DirectiveLocationAdded.new(new_directive, location) }
  changes += added_arguments.map { |argument| Changes::DirectiveArgumentAdded.new(new_directive, argument) }
  changes += removed_arguments.map { |argument| Changes::DirectiveArgumentRemoved.new(new_directive, argument) }

  each_common_argument do |old_argument, new_argument|
    changes += Diff::DirectiveArgument.new(new_directive, old_argument, new_argument).diff
  end

  changes
end