Sha256: 4e2ff1a6c753b216be5834b36f2b0c2f9c7294c94b13aa75df6e4008724b8747

Contents?: true

Size: 976 Bytes

Versions: 9

Compression:

Stored size: 976 Bytes

Contents

module NulogyGraphqlApi
  module Tasks
    class SchemaGenerator
      def initialize(schema_output_path, schema, context: {})
        @schema_output_path = schema_output_path
        @schema = schema
        @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)
      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

      def schema_definition
        GraphQL::Schema::Printer.print_schema(@schema, context: @context)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nulogy_graphql_api-3.0.1 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.2.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.1.3 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.1.2 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.1.1 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.1.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.0.1 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-2.0.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-1.1.1 lib/nulogy_graphql_api/tasks/schema_generator.rb