Sha256: 39ae12c2a15d9cccf9ae1de960867564199b6d036cf50594dae7a763ef8d0137

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

module NulogyGraphqlApi
  module Tasks
    class SchemaGenerator
      def initialize(schema_output_path, schema_definition, context: {})
        @schema_output_path = schema_output_path
        @schema_definition = schema_definition
        @context = context.merge(
          schema_generation_context?: true
        )
      end

      def generate_schema
        check_changes
        write_schema_to_file
      end

      private

      def check_changes
        return if old_schema.blank?

        SchemaChangesChecker.new.check_changes(old_schema, @schema_definition)
      end

      def old_schema
        return unless File.exist?(@schema_output_path)

        File.read(@schema_output_path)
      end

      def write_schema_to_file
        File.write(@schema_output_path, schema_definition)
        puts Rainbow("\nSuccessfully updated #{@schema_output_path}").green
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nulogy_graphql_api-1.1.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-1.0.0 lib/nulogy_graphql_api/tasks/schema_generator.rb