Class: NulogyGraphqlApi::Tasks::SchemaGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/nulogy_graphql_api/tasks/schema_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema_output_path, schema, context: {}) ⇒ SchemaGenerator

Returns a new instance of SchemaGenerator.



4
5
6
7
8
# 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
end

Instance Method Details

#check_changesObject



16
17
18
19
20
# File 'lib/nulogy_graphql_api/tasks/schema_generator.rb', line 16

def check_changes
  return if old_schema.blank?

  SchemaChangesChecker.new.check_changes(old_schema, generate_schema)
end

#generate_schemaObject



10
11
12
13
14
# File 'lib/nulogy_graphql_api/tasks/schema_generator.rb', line 10

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

#write_schema_to_fileObject



22
23
24
25
# File 'lib/nulogy_graphql_api/tasks/schema_generator.rb', line 22

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