Class: HQ::GraphQL::Comparator

Inherits:
Object
  • Object
show all
Defined in:
lib/hq/graphql/comparator.rb

Constant Summary collapse

CRITICALITY =

Higher values will include changes from criticalities with lower values as well. For example, setting the criticality as dangerous will return dangerous and breaking changes.

{
  breaking: 0,
  dangerous: 1,
  non_breaking: 2
}

Class Method Summary collapse

Class Method Details

.compare(old_schema, new_schema, criticality: :breaking) ⇒ Object

Raises:

  • (::ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hq/graphql/comparator.rb', line 17

def compare(old_schema, new_schema, criticality: :breaking)
  level = CRITICALITY[criticality]
  raise ::ArgumentError, "Invalid criticality. Possible values are #{CRITICALITY.keys.join(", ")}" unless level

  result = ::GraphQL::SchemaComparator.compare(convert_schema_to_string(old_schema), convert_schema_to_string(new_schema))
  return nil if result.identical?

  changes = {}
  changes[:breaking] = result.breaking_changes
  if level >= CRITICALITY[:dangerous]
    changes[:dangerous] = result.dangerous_changes
  end
  if level >= CRITICALITY[:non_breaking]
    changes[:non_breaking] = result.non_breaking_changes
  end
  return nil unless changes.values.flatten.any?

  changes
end