class NulogyGraphqlApi::Tasks::SchemaChangesChecker

Public Instance Methods

check_changes(old_schema, new_schema) click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_changes_checker.rb, line 7
def check_changes(old_schema, new_schema)
  compare_result = GraphQL::SchemaComparator.compare(old_schema, new_schema)

  abort "Task aborted!\n #{Rainbow('No schema changes found.').green}" if compare_result.identical?
  abort "Task aborted!" unless accept_breaking_changes?(compare_result)
end

Private Instance Methods

accept_breaking_changes?(compare_result) click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_changes_checker.rb, line 16
def accept_breaking_changes?(compare_result)
  return true if !compare_result.breaking? && compare_result.dangerous_changes.none?

  puts Rainbow("\nThe current GraphQL Schema has breaking or dangerous changes:").yellow

  compare_result.breaking_changes.concat(compare_result.dangerous_changes).each do |change|
    puts Rainbow("\n\n- #{change.message} #{change.dangerous? ? '(Dangerous)' : '(Breaking)'}").yellow
    puts Rainbow("  #{change.criticality.reason}").yellow
  end

  puts "\n\nDo you want to update the schema anyway? [Y/n]"

  $stdin.gets.chomp.downcase != "n"
end