Sha256: 2f75c207ddd9b63c046071e6dd1f5299cd3c6dfc44f961bc815a08f15fd7f09d

Contents?: true

Size: 917 Bytes

Versions: 4

Compression:

Stored size: 917 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
      end

      def generate_schema
        visible_schema = Class.new(@schema)
        visible_schema.use(GraphQL::Schema::AlwaysVisible)
        visible_schema.to_definition(context: @context)
      end

      def check_changes
        return if old_schema.blank?

        SchemaChangesChecker.new.check_changes(old_schema, generate_schema)
      end

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

      private

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

        File.read(@schema_output_path)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nulogy_graphql_api-4.3.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-4.2.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-4.1.0 lib/nulogy_graphql_api/tasks/schema_generator.rb
nulogy_graphql_api-4.0.0 lib/nulogy_graphql_api/tasks/schema_generator.rb