Class: Graphiti::Schema
- Defined in:
- lib/graphiti/schema.rb,
lib/graphiti/schema/check.rb
Defined Under Namespace
Classes: Check
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Class Method Summary collapse
- .check(resources = nil, path: Graphiti.config.schema_path) ⇒ Object
- .forced? ⇒ Boolean
- .generate(resources = nil) ⇒ Object
- .generate!(resources = nil, path: Graphiti.config.schema_path, force: forced?) ) ⇒ Object
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(resources) ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize(resources) ⇒ Schema
Returns a new instance of Schema.
30 31 32 33 34 |
# File 'lib/graphiti/schema.rb', line 30 def initialize(resources) @resources = resources.sort_by(&:name) @remote_resources = @resources.select(&:remote?) @local_resources = @resources - @remote_resources end |
Instance Attribute Details
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
3 4 5 |
# File 'lib/graphiti/schema.rb', line 3 def resources @resources end |
Class Method Details
.check(resources = nil, path: Graphiti.config.schema_path) ⇒ Object
26 27 28 |
# File 'lib/graphiti/schema.rb', line 26 def self.check(resources = nil, path: Graphiti.config.schema_path) Check.new(generate(resources), path) end |
.forced? ⇒ Boolean
14 15 16 |
# File 'lib/graphiti/schema.rb', line 14 def self.forced? Types.flag(ENV["FORCE_SCHEMA"]) end |
.generate(resources = nil) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/graphiti/schema.rb', line 5 def self.generate(resources = nil) # TODO: Maybe handle this in the Rails integration ::Rails.application.eager_load! if defined?(::Rails) resources ||= Graphiti.resources.reject(&:abstract_class?) resources.reject! { |r| r.name.nil? } new(resources).generate end |
.generate!(resources = nil, path: Graphiti.config.schema_path, force: forced?) ) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/graphiti/schema.rb', line 18 def self.generate!(resources = nil, path: Graphiti.config.schema_path, force: forced?) result = check(resources, path: path) return result.errors if !force && !result.compatible? result.write! [] end |
Instance Method Details
#generate ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/graphiti/schema.rb', line 36 def generate { resources: generate_resources, endpoints: generate_endpoints, types: generate_types } end |