Module: Graphiti
- Defined in:
- lib/graphiti/debugger.rb,
lib/graphiti.rb,
lib/graphiti/cli.rb,
lib/graphiti/query.rb,
lib/graphiti/rails.rb,
lib/graphiti/scope.rb,
lib/graphiti/types.rb,
lib/graphiti/errors.rb,
lib/graphiti/runner.rb,
lib/graphiti/schema.rb,
lib/graphiti/context.rb,
lib/graphiti/railtie.rb,
lib/graphiti/version.rb,
lib/graphiti/renderer.rb,
lib/graphiti/resource.rb,
lib/graphiti/sideload.rb,
lib/graphiti/stats/dsl.rb,
lib/graphiti/util/hash.rb,
lib/graphiti/util/link.rb,
lib/graphiti/responders.rb,
lib/graphiti/serializer.rb,
lib/graphiti/util/class.rb,
lib/graphiti/schema_diff.rb,
lib/graphiti/resource/dsl.rb,
lib/graphiti/scoping/base.rb,
lib/graphiti/scoping/sort.rb,
lib/graphiti/adapters/null.rb,
lib/graphiti/configuration.rb,
lib/graphiti/hash_renderer.rb,
lib/graphiti/stats/payload.rb,
lib/graphiti/util/sideload.rb,
lib/graphiti/resource/links.rb,
lib/graphiti/resource_proxy.rb,
lib/graphiti/scoping/filter.rb,
lib/graphiti/resource/remote.rb,
lib/graphiti/filter_operators.rb,
lib/graphiti/scoping/paginate.rb,
lib/graphiti/util/cache_debug.rb,
lib/graphiti/adapters/abstract.rb,
lib/graphiti/request_validator.rb,
lib/graphiti/util/field_params.rb,
lib/graphiti/extensions/temp_id.rb,
lib/graphiti/resource/interface.rb,
lib/graphiti/scoping/filterable.rb,
lib/graphiti/util/remote_params.rb,
lib/graphiti/util/simple_errors.rb,
lib/graphiti/util/include_params.rb,
lib/graphiti/delegates/pagination.rb,
lib/graphiti/resource/persistence.rb,
lib/graphiti/resource/sideloading.rb,
lib/graphiti/util/attribute_check.rb,
lib/graphiti/adapters/graphiti_api.rb,
lib/graphiti/resource/polymorphism.rb,
lib/graphiti/adapters/active_record.rb,
lib/graphiti/resource/configuration.rb,
lib/graphiti/resource/documentation.rb,
lib/graphiti/scoping/default_filter.rb,
lib/graphiti/util/remote_serializer.rb,
lib/graphiti/jsonapi_serializable_ext.rb,
lib/graphiti/scoping/extra_attributes.rb,
lib/graphiti/util/relationship_payload.rb,
lib/graphiti/extensions/extra_attribute.rb,
lib/graphiti/util/serializer_attributes.rb,
lib/graphiti/extensions/boolean_attribute.rb,
lib/graphiti/request_validators/validator.rb,
lib/graphiti/util/serializer_relationships.rb,
lib/graphiti/scoping/filter_group_validator.rb,
lib/graphiti/util/transaction_hooks_recorder.rb,
lib/graphiti/adapters/persistence/associations.rb,
lib/graphiti/request_validators/update_validator.rb
Overview
For “Rails STI” behavior CreditCard.all # => [<Visa>, <Mastercard>, etc]
Defined Under Namespace
Modules: Adapters, Context, Delegates, Errors, Extensions, JsonapiSerializableExt, Links, Rails, RequestValidators, Responders, Scoping, SerializableHash, SerializableTempId, Stats, Util
Classes: CLI, Configuration, Debugger, Deserializer, FilterOperators, HashRenderer, Query, Railtie, Renderer, RequestValidator, Resource, ResourceProxy, Runner, Schema, SchemaDiff, Scope, Serializer, Sideload, Types
Constant Summary
collapse
- DEPRECATOR =
ActiveSupport::Deprecation.new("2.0", "Graphiti")
- VERSION =
"1.7.6"
Class Method Summary
collapse
Class Method Details
.broadcast(name, payload) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/graphiti.rb', line 65
def self.broadcast(name, payload)
name = "#{name}.graphiti"
ActiveSupport::Notifications.instrument(name, payload) do
yield payload if block_given?
end
end
|
118
119
120
|
# File 'lib/graphiti.rb', line 118
def self.cache
@cache
end
|
.cache=(val) ⇒ Object
114
115
116
|
# File 'lib/graphiti.rb', line 114
def self.cache=(val)
@cache = val
end
|
47
48
49
|
# File 'lib/graphiti.rb', line 47
def self.config
@config ||= Configuration.new
end
|
57
58
59
|
# File 'lib/graphiti.rb', line 57
def self.configure
yield config
end
|
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
25
26
27
|
# File 'lib/graphiti.rb', line 25
def self.context
Thread.current[:context] ||= {}
end
|
.context=(val) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
30
31
32
|
# File 'lib/graphiti.rb', line 30
def self.context=(val)
Thread.current[:context] = val
end
|
.log(msg, color = :white, bold = false) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/graphiti.rb', line 90
def self.log(msg, color = :white, bold = false)
colored = if ::ActiveSupport.version >= Gem::Version.new("7.1")
ActiveSupport::LogSubscriber.new.send(:color, msg, color, bold: bold)
else
ActiveSupport::LogSubscriber.new.send(:color, msg, color, bold)
end
logger.debug(colored)
end
|
74
75
76
|
# File 'lib/graphiti.rb', line 74
def self.logger
@logger ||= stdout_logger
end
|
.logger=(val) ⇒ Object
86
87
88
|
# File 'lib/graphiti.rb', line 86
def self.logger=(val)
@logger = val
end
|
.resources ⇒ Object
61
62
63
|
# File 'lib/graphiti.rb', line 61
def self.resources
@resources ||= []
end
|
When we add a sideload, we need to do configuration, such as adding the relationship to the Resource’s serializer. However, the sideload’s Resource class may not be loaded yet.
This is not a problem when Rails autoloading, but is a problem when eager loading, or not using Rails.
So, load every Resource class then call Graphiti.setup!
108
109
110
111
112
|
# File 'lib/graphiti.rb', line 108
def self.setup!
resources.each do |r|
r.apply_sideloads_to_serializer
end
end
|
.stdout_logger ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/graphiti.rb', line 78
def self.stdout_logger
logger = Logger.new($stdout)
logger.formatter = proc do |severity, datetime, progname, msg|
"#{msg}\n"
end
logger
end
|
.with_context(obj, namespace = nil) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/graphiti.rb', line 35
def self.with_context(obj, namespace = nil)
prior = context
self.context = {object: obj, namespace: namespace}
yield
ensure
self.context = prior
resources.each do |resource_class|
resource_class.sideloads.values.each(&:clear_resources)
end
end
|