class NulogyGraphqlApi::Tasks::SchemaGenerator

Public Class Methods

new(schema_output_path, schema, context: {}) click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 4
def initialize(schema_output_path, schema, context: {})
  @schema_output_path = schema_output_path
  @schema = schema
  @context = context.merge(
    schema_generation_context?: true
  )
end

Public Instance Methods

generate_schema() click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 12
def generate_schema
  check_changes
  write_schema_to_file
end

Private Instance Methods

check_changes() click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 19
def check_changes
  return if old_schema.blank?

  SchemaChangesChecker.new.check_changes(old_schema, @schema)
end
old_schema() click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 25
def old_schema
  return unless File.exist?(@schema_output_path)

  File.read(@schema_output_path)
end
schema_definition() click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 36
def schema_definition
  GraphQL::Schema::Printer.print_schema(@schema, context: @context)
end
write_schema_to_file() click to toggle source
# File lib/nulogy_graphql_api/tasks/schema_generator.rb, line 31
def write_schema_to_file
  File.write(@schema_output_path, schema_definition)
  puts Rainbow("\nSuccessfully updated #{@schema_output_path}").green
end