graphiti 1.0.rc.21 → 1.0.rc.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.standard.yml +14 -0
- data/.travis.yml +31 -2
- data/Appraisals +16 -10
- data/Gemfile +5 -5
- data/Guardfile +2 -2
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/exe/graphiti +1 -1
- data/gemfiles/rails_4.gemfile +0 -1
- data/gemfiles/rails_5.gemfile +0 -1
- data/gemfiles/rails_6.gemfile +19 -0
- data/graphiti.gemspec +15 -14
- data/lib/generators/graphiti/api_test_generator.rb +16 -16
- data/lib/generators/graphiti/generator_mixin.rb +7 -7
- data/lib/generators/graphiti/install_generator.rb +19 -19
- data/lib/generators/graphiti/resource_generator.rb +19 -19
- data/lib/generators/graphiti/resource_test_generator.rb +10 -10
- data/lib/graphiti.rb +24 -26
- data/lib/graphiti/adapters/abstract.rb +25 -39
- data/lib/graphiti/adapters/active_record.rb +43 -49
- data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +33 -11
- data/lib/graphiti/adapters/graphiti_api.rb +16 -16
- data/lib/graphiti/adapters/null.rb +0 -12
- data/lib/graphiti/cli.rb +7 -7
- data/lib/graphiti/configuration.rb +14 -15
- data/lib/graphiti/context.rb +1 -1
- data/lib/graphiti/debugger.rb +22 -26
- data/lib/graphiti/delegates/pagination.rb +9 -9
- data/lib/graphiti/deserializer.rb +7 -9
- data/lib/graphiti/errors.rb +119 -119
- data/lib/graphiti/extensions/boolean_attribute.rb +1 -1
- data/lib/graphiti/extensions/extra_attribute.rb +1 -1
- data/lib/graphiti/extensions/temp_id.rb +1 -1
- data/lib/graphiti/filter_operators.rb +6 -0
- data/lib/graphiti/hash_renderer.rb +15 -15
- data/lib/graphiti/jsonapi_serializable_ext.rb +1 -1
- data/lib/graphiti/query.rb +35 -35
- data/lib/graphiti/railtie.rb +14 -10
- data/lib/graphiti/renderer.rb +2 -2
- data/lib/graphiti/resource.rb +4 -6
- data/lib/graphiti/resource/configuration.rb +9 -13
- data/lib/graphiti/resource/documentation.rb +4 -2
- data/lib/graphiti/resource/dsl.rb +21 -25
- data/lib/graphiti/resource/interface.rb +3 -3
- data/lib/graphiti/resource/links.rb +14 -14
- data/lib/graphiti/resource/persistence.rb +9 -9
- data/lib/graphiti/resource/polymorphism.rb +3 -3
- data/lib/graphiti/resource/remote.rb +3 -3
- data/lib/graphiti/resource/sideloading.rb +5 -5
- data/lib/graphiti/resource_proxy.rb +12 -12
- data/lib/graphiti/schema.rb +27 -26
- data/lib/graphiti/schema_diff.rb +10 -10
- data/lib/graphiti/scope.rb +12 -16
- data/lib/graphiti/scoping/base.rb +5 -5
- data/lib/graphiti/scoping/default_filter.rb +1 -1
- data/lib/graphiti/scoping/filter.rb +15 -24
- data/lib/graphiti/scoping/filterable.rb +5 -5
- data/lib/graphiti/scoping/paginate.rb +1 -1
- data/lib/graphiti/scoping/sort.rb +7 -7
- data/lib/graphiti/serializer.rb +8 -4
- data/lib/graphiti/sideload.rb +23 -39
- data/lib/graphiti/sideload/belongs_to.rb +2 -2
- data/lib/graphiti/sideload/has_many.rb +1 -1
- data/lib/graphiti/sideload/many_to_many.rb +18 -2
- data/lib/graphiti/sideload/polymorphic_belongs_to.rb +14 -8
- data/lib/graphiti/stats/dsl.rb +7 -1
- data/lib/graphiti/tasks.rb +10 -10
- data/lib/graphiti/types.rb +98 -98
- data/lib/graphiti/util/attribute_check.rb +1 -1
- data/lib/graphiti/util/class.rb +3 -3
- data/lib/graphiti/util/field_params.rb +1 -1
- data/lib/graphiti/util/hash.rb +19 -1
- data/lib/graphiti/util/link.rb +15 -19
- data/lib/graphiti/util/persistence.rb +17 -22
- data/lib/graphiti/util/relationship_payload.rb +2 -2
- data/lib/graphiti/util/remote_params.rb +12 -12
- data/lib/graphiti/util/remote_serializer.rb +2 -2
- data/lib/graphiti/util/serializer_attributes.rb +20 -25
- data/lib/graphiti/util/serializer_relationships.rb +17 -18
- data/lib/graphiti/util/sideload.rb +1 -1
- data/lib/graphiti/util/transaction_hooks_recorder.rb +3 -2
- data/lib/graphiti/version.rb +1 -1
- metadata +22 -6
@@ -9,21 +9,43 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def belongs_to_many_filter(scope, value)
|
12
|
-
|
13
|
-
.
|
14
|
-
|
12
|
+
if polymorphic?
|
13
|
+
clauses = value.group_by { |v| v["type"] }.map { |group|
|
14
|
+
ids = group[1].map { |g| g["id"] }
|
15
|
+
filter_for(scope, ids, group[0])
|
16
|
+
}
|
17
|
+
scope = clauses.shift
|
18
|
+
clauses.each { |c| scope = scope.or(c) }
|
19
|
+
scope
|
20
|
+
else
|
21
|
+
filter_for(scope, value)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
if polymorphic?
|
22
|
-
c[foreign_type_column] = foreign_type_value
|
25
|
+
def ids_for_parents(parents)
|
26
|
+
if polymorphic?
|
27
|
+
parents.group_by(&:class).map do |group|
|
28
|
+
{id: super(group[1]), type: group[0].name}.to_json
|
23
29
|
end
|
30
|
+
else
|
31
|
+
super
|
24
32
|
end
|
33
|
+
end
|
25
34
|
|
26
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
def filter_for(scope, value, type = nil)
|
38
|
+
scope
|
39
|
+
.includes(through_relationship_name)
|
40
|
+
.where(belongs_to_many_clause(value, type))
|
41
|
+
end
|
42
|
+
|
43
|
+
def belongs_to_many_clause(value, type)
|
44
|
+
where = {true_foreign_key => value}
|
45
|
+
if polymorphic? && type
|
46
|
+
where[foreign_type_column] = type
|
47
|
+
end
|
48
|
+
{through_table_name => where}
|
27
49
|
end
|
28
50
|
|
29
51
|
def foreign_type_column
|
@@ -51,6 +73,6 @@ class Graphiti::Adapters::ActiveRecord::ManyToManySideload < Graphiti::Sideload:
|
|
51
73
|
def infer_foreign_key
|
52
74
|
key = parent_reflection.options[:through]
|
53
75
|
value = through_reflection.foreign_key.to_sym
|
54
|
-
{
|
76
|
+
{key => value}
|
55
77
|
end
|
56
78
|
end
|
@@ -10,10 +10,10 @@ module Graphiti
|
|
10
10
|
response = resource.make_request(url)
|
11
11
|
json = JSON.parse(response.body)
|
12
12
|
|
13
|
-
if json[
|
13
|
+
if json["errors"]
|
14
14
|
handle_remote_error(url, json)
|
15
15
|
else
|
16
|
-
models = json[
|
16
|
+
models = json["data"].map { |d| build_entity(json, d) }
|
17
17
|
Util::RemoteSerializer.for(resource.class.serializer, models)
|
18
18
|
models
|
19
19
|
end
|
@@ -22,13 +22,13 @@ module Graphiti
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def handle_remote_error(url, json)
|
25
|
-
errors = json[
|
26
|
-
if raw = error[
|
27
|
-
{
|
25
|
+
errors = json["errors"].map { |error|
|
26
|
+
if (raw = error["meta"].try(:[], "__raw_error__"))
|
27
|
+
{message: raw["message"], backtrace: raw["backtrace"]}
|
28
28
|
else
|
29
|
-
{
|
29
|
+
{message: "#{error["title"]} - #{error["detail"]}"}
|
30
30
|
end
|
31
|
-
|
31
|
+
}.compact
|
32
32
|
raise Errors::Remote.new(url, errors)
|
33
33
|
end
|
34
34
|
|
@@ -41,30 +41,30 @@ module Graphiti
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def find_entity(json, id, type)
|
44
|
-
lookup = Array(json[
|
45
|
-
lookup.find { |l| l[
|
44
|
+
lookup = Array(json["data"]) | Array(json["included"])
|
45
|
+
lookup.find { |l| l["id"] == id.to_s && l["type"] == type }
|
46
46
|
end
|
47
47
|
|
48
48
|
def build_entity(json, node)
|
49
|
-
entity = OpenStruct.new(node[
|
50
|
-
entity.id = node[
|
51
|
-
entity._type = node[
|
52
|
-
process_relationships(entity, json, node[
|
49
|
+
entity = OpenStruct.new(node["attributes"])
|
50
|
+
entity.id = node["id"]
|
51
|
+
entity._type = node["type"]
|
52
|
+
process_relationships(entity, json, node["relationships"] || {})
|
53
53
|
entity
|
54
54
|
end
|
55
55
|
|
56
56
|
def process_relationships(entity, json, relationship_json)
|
57
57
|
entity._relationships = {}
|
58
58
|
relationship_json.each_pair do |name, hash|
|
59
|
-
if data = hash[
|
59
|
+
if (data = hash["data"])
|
60
60
|
if data.is_a?(Array)
|
61
61
|
data.each do |d|
|
62
|
-
rel = find_entity(json, d[
|
62
|
+
rel = find_entity(json, d["id"], d["type"])
|
63
63
|
related_entity = build_entity(json, rel)
|
64
64
|
add_relationship(entity, related_entity, name, true)
|
65
65
|
end
|
66
66
|
else
|
67
|
-
rel = find_entity(json, hash[
|
67
|
+
rel = find_entity(json, hash["data"]["id"], hash["data"]["type"])
|
68
68
|
related_entity = build_entity(json, rel)
|
69
69
|
add_relationship(entity, related_entity, name)
|
70
70
|
end
|
@@ -68,18 +68,6 @@ module Graphiti
|
|
68
68
|
scope
|
69
69
|
end
|
70
70
|
|
71
|
-
def filter_datetime_eq(scope, attribute, value)
|
72
|
-
scope
|
73
|
-
end
|
74
|
-
|
75
|
-
def filter_datetime_not_eq(scope, attribute, value)
|
76
|
-
scope
|
77
|
-
end
|
78
|
-
|
79
|
-
def filter_datetime_lte(scope, attribute, value)
|
80
|
-
scope
|
81
|
-
end
|
82
|
-
|
83
71
|
def filter_float_eq(scope, attribute, value)
|
84
72
|
scope
|
85
73
|
end
|
data/lib/graphiti/cli.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "thor"
|
2
|
+
require "net/http"
|
3
|
+
require "graphiti"
|
4
4
|
|
5
5
|
Thor::Base.shell = Thor::Shell::Color
|
6
6
|
|
7
7
|
module Graphiti
|
8
8
|
class CLI < Thor
|
9
|
-
desc
|
9
|
+
desc "schema_check OLD_SCHEMA NEW_SCHEMA", "Diff 2 schemas for backwards incompatibilities. Pass file path or URL. If your app relies on JSON Web Tokens, you can set GRAPHITI_TOKEN for authentication"
|
10
10
|
def schema_check(old, new)
|
11
11
|
old = schema_for(old)
|
12
12
|
new = schema_for(new)
|
@@ -25,7 +25,7 @@ module Graphiti
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def schema_for(input)
|
28
|
-
if input.starts_with?(
|
28
|
+
if input.starts_with?("http")
|
29
29
|
JSON.parse(fetch_remote_schema(input))
|
30
30
|
else
|
31
31
|
JSON.parse(File.read(input))
|
@@ -35,9 +35,9 @@ module Graphiti
|
|
35
35
|
def fetch_remote_schema(path)
|
36
36
|
uri = URI(path)
|
37
37
|
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
-
http.use_ssl = true if uri.scheme ==
|
38
|
+
http.use_ssl = true if uri.scheme == "https"
|
39
39
|
req = Net::HTTP::Get.new(uri)
|
40
|
-
req[
|
40
|
+
req["Authorization"] = "Token token=\"#{ENV["GRAPHITI_TOKEN"]}\""
|
41
41
|
res = http.request(req)
|
42
42
|
res.body
|
43
43
|
end
|
@@ -10,13 +10,14 @@ module Graphiti
|
|
10
10
|
|
11
11
|
attr_accessor :respond_to
|
12
12
|
attr_accessor :context_for_endpoint
|
13
|
-
attr_accessor :schema_path
|
14
13
|
attr_accessor :links_on_demand
|
15
14
|
attr_accessor :pagination_links_on_demand
|
16
15
|
attr_accessor :pagination_links
|
17
16
|
attr_accessor :typecast_reads
|
18
|
-
|
19
|
-
|
17
|
+
|
18
|
+
attr_reader :debug, :debug_models
|
19
|
+
|
20
|
+
attr_writer :schema_path
|
20
21
|
|
21
22
|
# Set defaults
|
22
23
|
# @api private
|
@@ -28,13 +29,13 @@ module Graphiti
|
|
28
29
|
@pagination_links_on_demand = false
|
29
30
|
@pagination_links = false
|
30
31
|
@typecast_reads = true
|
31
|
-
self.debug = ENV.fetch(
|
32
|
-
self.debug_models = ENV.fetch(
|
32
|
+
self.debug = ENV.fetch("GRAPHITI_DEBUG", true)
|
33
|
+
self.debug_models = ENV.fetch("GRAPHITI_DEBUG_MODELS", false)
|
33
34
|
|
34
35
|
if defined?(::Rails)
|
35
|
-
if File.
|
36
|
+
if File.exist?("#{::Rails.root}/.graphiticfg.yml")
|
36
37
|
cfg = YAML.load_file("#{::Rails.root}/.graphiticfg.yml")
|
37
|
-
@schema_path = "#{::Rails.root}/public#{cfg[
|
38
|
+
@schema_path = "#{::Rails.root}/public#{cfg["namespace"]}/schema.json"
|
38
39
|
else
|
39
40
|
@schema_path = "#{::Rails.root}/public/schema.json"
|
40
41
|
end
|
@@ -44,7 +45,7 @@ module Graphiti
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def schema_path
|
47
|
-
@schema_path ||= raise(
|
48
|
+
@schema_path ||= raise("No schema_path defined! Set Graphiti.config.schema_path to save your schema.")
|
48
49
|
end
|
49
50
|
|
50
51
|
def debug=(val)
|
@@ -58,13 +59,11 @@ module Graphiti
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def with_option(key, value)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
send(:"#{key}=", original)
|
67
|
-
end
|
62
|
+
original = send(key)
|
63
|
+
send(:"#{key}=", value)
|
64
|
+
yield
|
65
|
+
ensure
|
66
|
+
send(:"#{key}=", original)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
data/lib/graphiti/context.rb
CHANGED
data/lib/graphiti/debugger.rb
CHANGED
@@ -10,19 +10,17 @@ module Graphiti
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
def on_data(name, start, stop, id, payload)
|
13
|
-
took = ((stop-start)*1000.0).round(2)
|
13
|
+
took = ((stop - start) * 1000.0).round(2)
|
14
14
|
params = scrub_params(payload[:params])
|
15
15
|
|
16
16
|
if payload[:exception]
|
17
17
|
on_data_exception(payload, params)
|
18
|
-
|
19
|
-
if payload[:
|
20
|
-
|
21
|
-
on_sideload_data(payload, params, took)
|
22
|
-
end
|
23
|
-
else
|
24
|
-
on_primary_data(payload, params, took)
|
18
|
+
elsif payload[:sideload]
|
19
|
+
if payload[:results]
|
20
|
+
on_sideload_data(payload, params, took)
|
25
21
|
end
|
22
|
+
else
|
23
|
+
on_primary_data(payload, params, took)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
@@ -30,7 +28,7 @@ module Graphiti
|
|
30
28
|
unless payload[:exception_object].instance_variable_get(:@__graphiti_debug)
|
31
29
|
add_chunk do |logs, json|
|
32
30
|
logs << ["\n=== Graphiti Debug ERROR", :red, true]
|
33
|
-
if sideload = payload[:sideload]
|
31
|
+
if (sideload = payload[:sideload])
|
34
32
|
logs << ["#{sideload.parent_resource.class}: Sideload \"#{sideload.name}\"", :red, true]
|
35
33
|
json[:parent_resource] = sideload.parent_resource.class.name
|
36
34
|
json[:sideload] = sideload.name
|
@@ -39,22 +37,20 @@ module Graphiti
|
|
39
37
|
query = "#{payload[:resource].class.name}.all(#{JSON.pretty_generate(params)}).data"
|
40
38
|
logs << [query, :cyan, true]
|
41
39
|
logs << ["The error occurred when running the above query. Copy/paste it into a rake task or Rails console session to reproduce. Keep in mind you may have to set context.", :yellow, true]
|
42
|
-
json[:query] = query
|
43
40
|
else
|
44
41
|
query = "This sideload is done manually via .scope - no debug information available."
|
45
42
|
logs << [query, :cyan, true]
|
46
|
-
json[:query] = query
|
47
43
|
end
|
44
|
+
json[:query] = query
|
45
|
+
|
48
46
|
logs << "\n\n"
|
49
|
-
|
50
|
-
payload[:exception_object].instance_variable_set(:@__graphiti_debug, json)
|
51
|
-
end
|
47
|
+
payload[:exception_object]&.instance_variable_set(:@__graphiti_debug, json)
|
52
48
|
end
|
53
49
|
end
|
54
50
|
end
|
55
51
|
|
56
52
|
def results(raw_results)
|
57
|
-
raw_results.map { |r| "[#{r.class.name}, #{r.id.inspect}]" }.join(
|
53
|
+
raw_results.map { |r| "[#{r.class.name}, #{r.id.inspect}]" }.join(", ")
|
58
54
|
end
|
59
55
|
|
60
56
|
def on_sideload_data(payload, params, took)
|
@@ -94,7 +90,7 @@ module Graphiti
|
|
94
90
|
|
95
91
|
def on_render(name, start, stop, id, payload)
|
96
92
|
add_chunk do |logs|
|
97
|
-
took = ((stop-start)*1000.0).round(2)
|
93
|
+
took = ((stop - start) * 1000.0).round(2)
|
98
94
|
logs << [""]
|
99
95
|
logs << ["=== Graphiti Debug", :green, true]
|
100
96
|
logs << ["Rendering:", :green, true]
|
@@ -109,7 +105,7 @@ module Graphiti
|
|
109
105
|
yield
|
110
106
|
ensure
|
111
107
|
flush
|
112
|
-
self.chunks = [] unless
|
108
|
+
self.chunks = [] unless preserve
|
113
109
|
end
|
114
110
|
else
|
115
111
|
yield
|
@@ -125,7 +121,7 @@ module Graphiti
|
|
125
121
|
end
|
126
122
|
|
127
123
|
def flush
|
128
|
-
Graphiti.broadcast(
|
124
|
+
Graphiti.broadcast("debug.flush", {}) do |payload|
|
129
125
|
payload[:chunks] = chunks
|
130
126
|
graph_statements.each do |chunk|
|
131
127
|
flush_chunk(chunk)
|
@@ -138,26 +134,26 @@ module Graphiti
|
|
138
134
|
def scrub_params(params)
|
139
135
|
params ||= {}
|
140
136
|
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
|
141
|
-
params.reject! { |k,v| [:controller, :action, :format, :debug].include?(k.to_sym) }
|
142
|
-
params.reject! { |k,v| k.to_sym == :include }
|
137
|
+
params.reject! { |k, v| [:controller, :action, :format, :debug].include?(k.to_sym) }
|
138
|
+
params.reject! { |k, v| k.to_sym == :include }
|
143
139
|
params.deep_symbolize_keys
|
144
140
|
end
|
145
141
|
|
146
142
|
def add_chunk(resource = nil, parent = nil)
|
147
143
|
logs, json = [], {}
|
148
144
|
yield(logs, json)
|
149
|
-
|
145
|
+
chunks << {
|
150
146
|
resource: resource,
|
151
147
|
parent: parent,
|
152
148
|
logs: logs,
|
153
149
|
json: json,
|
154
|
-
children: []
|
150
|
+
children: [],
|
155
151
|
}
|
156
152
|
end
|
157
153
|
|
158
154
|
def graph_statements
|
159
155
|
@chunks.each do |chunk|
|
160
|
-
if parent = chunk[:parent]
|
156
|
+
if (parent = chunk[:parent])
|
161
157
|
relevant = chunks.find { |c| c[:resource] == parent }
|
162
158
|
relevant[:children].unshift(chunk) if relevant
|
163
159
|
end
|
@@ -179,7 +175,7 @@ module Graphiti
|
|
179
175
|
|
180
176
|
def flush_chunk(chunk, depth = 0)
|
181
177
|
chunk[:logs].each do |args|
|
182
|
-
indent =
|
178
|
+
indent = " " * depth
|
183
179
|
args[0] = "#{indent}#{args[0]}"
|
184
180
|
Graphiti.log(*args)
|
185
181
|
end
|
@@ -191,8 +187,8 @@ module Graphiti
|
|
191
187
|
end
|
192
188
|
|
193
189
|
ActiveSupport::Notifications.subscribe \
|
194
|
-
|
190
|
+
"graphiti.data", method(:on_data)
|
195
191
|
ActiveSupport::Notifications.subscribe \
|
196
|
-
|
192
|
+
"graphiti.render", method(:on_render)
|
197
193
|
end
|
198
194
|
end
|
@@ -10,12 +10,12 @@ module Graphiti
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def links
|
13
|
-
@links ||= {
|
13
|
+
@links ||= {}.tap do |links|
|
14
14
|
links[:first] = pagination_link(1)
|
15
15
|
links[:last] = pagination_link(last_page)
|
16
16
|
links[:prev] = pagination_link(current_page - 1) unless current_page == 1
|
17
17
|
links[:next] = pagination_link(current_page + 1) unless current_page == last_page
|
18
|
-
end.select{|k,v| !v.nil? }
|
18
|
+
end.select {|k, v| !v.nil? }
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -27,11 +27,11 @@ module Graphiti
|
|
27
27
|
|
28
28
|
# Overwrite the pagination query params with the desired page
|
29
29
|
uri.query = @proxy.query.hash.merge({
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
page: {
|
31
|
+
number: page,
|
32
|
+
size: page_size,
|
33
|
+
},
|
34
|
+
}).to_query
|
35
35
|
uri.to_s
|
36
36
|
end
|
37
37
|
|
@@ -50,10 +50,10 @@ module Graphiti
|
|
50
50
|
begin
|
51
51
|
return @item_count if @item_count
|
52
52
|
@item_count = @proxy.resource.stat(:total, :count).call(@proxy.scope.unpaginated_object, :total)
|
53
|
-
unless @item_count.
|
53
|
+
unless @item_count.is_a?(Numeric)
|
54
54
|
raise TypeError, "#{@proxy.resource}.stat(:total, :count) returned an invalid value #{@item_count}"
|
55
55
|
end
|
56
|
-
rescue
|
56
|
+
rescue
|
57
57
|
# FIXME: Unable to log because of how rspec mocks were
|
58
58
|
# created for the logger. In other words, logging here will
|
59
59
|
# break tests.
|
@@ -47,7 +47,7 @@
|
|
47
47
|
class Graphiti::Deserializer
|
48
48
|
def initialize(payload)
|
49
49
|
@payload = payload
|
50
|
-
@payload = @payload[:_jsonapi] if @payload.
|
50
|
+
@payload = @payload[:_jsonapi] if @payload.key?(:_jsonapi)
|
51
51
|
end
|
52
52
|
|
53
53
|
def params
|
@@ -73,9 +73,7 @@ class Graphiti::Deserializer
|
|
73
73
|
|
74
74
|
# Override the attributes
|
75
75
|
# # @see #attributes
|
76
|
-
|
77
|
-
@attributes = attrs
|
78
|
-
end
|
76
|
+
attr_writer :attributes
|
79
77
|
|
80
78
|
# 'meta' information about this resource. Includes:
|
81
79
|
#
|
@@ -88,7 +86,7 @@ class Graphiti::Deserializer
|
|
88
86
|
{
|
89
87
|
type: data[:type],
|
90
88
|
temp_id: data[:'temp-id'],
|
91
|
-
method: action
|
89
|
+
method: action,
|
92
90
|
}
|
93
91
|
end
|
94
92
|
|
@@ -164,12 +162,12 @@ class Graphiti::Deserializer
|
|
164
162
|
|
165
163
|
def process_relationship_datum(datum)
|
166
164
|
temp_id = datum[:'temp-id']
|
167
|
-
included_object = included.find
|
165
|
+
included_object = included.find { |i|
|
168
166
|
next unless i[:type] == datum[:type]
|
169
167
|
|
170
168
|
(i[:id] && i[:id] == datum[:id]) ||
|
171
169
|
(i[:'temp-id'] && i[:'temp-id'] == temp_id)
|
172
|
-
|
170
|
+
}
|
173
171
|
included_object ||= {}
|
174
172
|
included_object[:relationships] ||= {}
|
175
173
|
|
@@ -183,10 +181,10 @@ class Graphiti::Deserializer
|
|
183
181
|
meta: {
|
184
182
|
jsonapi_type: datum[:type],
|
185
183
|
temp_id: temp_id,
|
186
|
-
method: method
|
184
|
+
method: method,
|
187
185
|
},
|
188
186
|
attributes: attributes,
|
189
|
-
relationships: relationships
|
187
|
+
relationships: relationships,
|
190
188
|
}
|
191
189
|
end
|
192
190
|
|