Sha256: 15ab9f57a4d3201a72b8f82fb92bebd3eb4354c5233368279eef0e9f1506e115

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require "graphql/schema_comparator"
require "rainbow"

module NulogyGraphqlApi
  module Tasks
    class SchemaChangesChecker
      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

      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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nulogy_graphql_api-0.5.3 lib/nulogy_graphql_api/tasks/schema_changes_checker.rb
nulogy_graphql_api-0.5.1 lib/nulogy_graphql_api/tasks/schema_changes_checker.rb
nulogy_graphql_api-0.5.0 lib/nulogy_graphql_api/tasks/schema_changes_checker.rb