Sha256: dac352f8b984f415bfa53749cc34e128813e0a3dcd8aea39fbd552269cf2cfea

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module NulogyGraphqlApi
  module Tasks
    class SchemaGenerator
      def initialize(schema_output_path, schema_definition_path, context: {})
        @schema_output_path = schema_output_path
        @schema_definition_path = schema_definition_path
        @context = context
      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 schema_definition
        require @schema_definition_path
        @schema_definition ||= GraphQL::Schema.descendants.first.to_definition(context: @context)
      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

1 entries across 1 versions & 1 rubygems

Version Path
nulogy_graphql_api-0.5.0 lib/nulogy_graphql_api/tasks/schema_generator.rb