graphiti 1.2.15 → 1.2.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +43 -14
- data/Appraisals +37 -5
- data/CHANGELOG.md +1 -1
- data/Gemfile +2 -0
- data/Guardfile +5 -5
- data/deprecated_generators/graphiti/resource_generator.rb +1 -1
- data/gemfiles/rails_5_0.gemfile +18 -0
- data/gemfiles/rails_5_0_graphiti_rails.gemfile +20 -0
- data/gemfiles/rails_5_1.gemfile +18 -0
- data/gemfiles/rails_5_1_graphiti_rails.gemfile +20 -0
- data/gemfiles/{rails_5.gemfile → rails_5_2.gemfile} +0 -0
- data/gemfiles/{rails_5_graphiti_rails.gemfile → rails_5_2_graphiti_rails.gemfile} +0 -0
- data/gemfiles/rails_6.gemfile +1 -1
- data/gemfiles/rails_6_graphiti_rails.gemfile +1 -1
- data/graphiti.gemspec +11 -12
- data/lib/graphiti.rb +3 -3
- data/lib/graphiti/adapters/abstract.rb +3 -3
- data/lib/graphiti/adapters/active_record.rb +65 -36
- data/lib/graphiti/adapters/active_record/many_to_many_sideload.rb +2 -1
- data/lib/graphiti/configuration.rb +1 -1
- data/lib/graphiti/debugger.rb +4 -4
- data/lib/graphiti/delegates/pagination.rb +8 -4
- data/lib/graphiti/deserializer.rb +3 -3
- data/lib/graphiti/errors.rb +24 -4
- data/lib/graphiti/extensions/extra_attribute.rb +1 -1
- data/lib/graphiti/query.rb +32 -16
- data/lib/graphiti/railtie.rb +1 -1
- data/lib/graphiti/request_validator.rb +4 -4
- data/lib/graphiti/request_validators/update_validator.rb +1 -2
- data/lib/graphiti/request_validators/validator.rb +2 -2
- data/lib/graphiti/resource.rb +10 -0
- data/lib/graphiti/resource/configuration.rb +10 -3
- data/lib/graphiti/resource/dsl.rb +10 -4
- data/lib/graphiti/resource/interface.rb +2 -2
- data/lib/graphiti/resource/links.rb +3 -3
- data/lib/graphiti/resource/persistence.rb +2 -1
- data/lib/graphiti/resource/polymorphism.rb +3 -2
- data/lib/graphiti/resource/remote.rb +1 -1
- data/lib/graphiti/runner.rb +4 -3
- data/lib/graphiti/schema.rb +6 -6
- data/lib/graphiti/scope.rb +5 -5
- data/lib/graphiti/scoping/base.rb +3 -3
- data/lib/graphiti/scoping/filter.rb +17 -7
- data/lib/graphiti/scoping/sort.rb +1 -1
- data/lib/graphiti/serializer.rb +7 -0
- data/lib/graphiti/sideload.rb +30 -22
- data/lib/graphiti/sideload/belongs_to.rb +1 -1
- data/lib/graphiti/sideload/has_many.rb +19 -1
- data/lib/graphiti/sideload/many_to_many.rb +6 -2
- data/lib/graphiti/stats/payload.rb +4 -4
- data/lib/graphiti/types.rb +15 -15
- data/lib/graphiti/util/link.rb +6 -2
- data/lib/graphiti/util/persistence.rb +16 -10
- data/lib/graphiti/util/relationship_payload.rb +4 -4
- data/lib/graphiti/util/simple_errors.rb +1 -1
- data/lib/graphiti/util/transaction_hooks_recorder.rb +1 -1
- data/lib/graphiti/version.rb +1 -1
- metadata +18 -22
@@ -15,10 +15,10 @@ module Graphiti
|
|
15
15
|
# }
|
16
16
|
class Payload
|
17
17
|
def initialize(resource, query, scope, data)
|
18
|
-
@resource
|
19
|
-
@query
|
20
|
-
@scope
|
21
|
-
@data
|
18
|
+
@resource = resource
|
19
|
+
@query = query
|
20
|
+
@scope = scope
|
21
|
+
@data = data
|
22
22
|
end
|
23
23
|
|
24
24
|
# Generate the payload for +{ meta: { stats: { ... } } }+
|
data/lib/graphiti/types.rb
CHANGED
@@ -93,14 +93,14 @@ module Graphiti
|
|
93
93
|
read: Dry::Types["coercible.string"],
|
94
94
|
write: Dry::Types["coercible.integer"],
|
95
95
|
kind: "scalar",
|
96
|
-
description: "Base Type. Query/persist as integer, render as string."
|
96
|
+
description: "Base Type. Query/persist as integer, render as string."
|
97
97
|
},
|
98
98
|
uuid: {
|
99
99
|
params: Dry::Types["coercible.string"],
|
100
100
|
read: Dry::Types["coercible.string"],
|
101
101
|
write: Dry::Types["coercible.string"],
|
102
102
|
kind: "scalar",
|
103
|
-
description: "Base Type. Like a normal string, but by default only eq/!eq and case-sensitive."
|
103
|
+
description: "Base Type. Like a normal string, but by default only eq/!eq and case-sensitive."
|
104
104
|
},
|
105
105
|
string_enum: {
|
106
106
|
canonical_name: :enum,
|
@@ -108,7 +108,7 @@ module Graphiti
|
|
108
108
|
read: Dry::Types["coercible.string"],
|
109
109
|
write: Dry::Types["coercible.string"],
|
110
110
|
kind: "scalar",
|
111
|
-
description: "String enum type. Like a normal string, but only eq/!eq and case-sensitive. Limited to only the allowed values."
|
111
|
+
description: "String enum type. Like a normal string, but only eq/!eq and case-sensitive. Limited to only the allowed values."
|
112
112
|
},
|
113
113
|
integer_enum: {
|
114
114
|
canonical_name: :enum,
|
@@ -116,71 +116,71 @@ module Graphiti
|
|
116
116
|
read: Dry::Types["coercible.integer"],
|
117
117
|
write: Dry::Types["coercible.integer"],
|
118
118
|
kind: "scalar",
|
119
|
-
description: "Integer enum type. Like a normal integer, but only eq/!eq filters. Limited to only the allowed values."
|
119
|
+
description: "Integer enum type. Like a normal integer, but only eq/!eq filters. Limited to only the allowed values."
|
120
120
|
},
|
121
121
|
string: {
|
122
122
|
params: Dry::Types["coercible.string"],
|
123
123
|
read: Dry::Types["coercible.string"],
|
124
124
|
write: Dry::Types["coercible.string"],
|
125
125
|
kind: "scalar",
|
126
|
-
description: "Base Type."
|
126
|
+
description: "Base Type."
|
127
127
|
},
|
128
128
|
integer: {
|
129
129
|
params: PresentInteger,
|
130
130
|
read: Integer,
|
131
131
|
write: Integer,
|
132
132
|
kind: "scalar",
|
133
|
-
description: "Base Type."
|
133
|
+
description: "Base Type."
|
134
134
|
},
|
135
135
|
big_decimal: {
|
136
136
|
params: ParamDecimal,
|
137
137
|
read: Dry::Types["json.decimal"],
|
138
138
|
write: Dry::Types["json.decimal"],
|
139
139
|
kind: "scalar",
|
140
|
-
description: "Base Type."
|
140
|
+
description: "Base Type."
|
141
141
|
},
|
142
142
|
float: {
|
143
143
|
params: Dry::Types["coercible.float"],
|
144
144
|
read: Float,
|
145
145
|
write: Float,
|
146
146
|
kind: "scalar",
|
147
|
-
description: "Base Type."
|
147
|
+
description: "Base Type."
|
148
148
|
},
|
149
149
|
boolean: {
|
150
150
|
params: PresentBool,
|
151
151
|
read: Bool,
|
152
152
|
write: Bool,
|
153
153
|
kind: "scalar",
|
154
|
-
description: "Base Type."
|
154
|
+
description: "Base Type."
|
155
155
|
},
|
156
156
|
date: {
|
157
157
|
params: PresentDate,
|
158
158
|
read: Date,
|
159
159
|
write: Date,
|
160
160
|
kind: "scalar",
|
161
|
-
description: "Base Type."
|
161
|
+
description: "Base Type."
|
162
162
|
},
|
163
163
|
datetime: {
|
164
164
|
params: PresentParamsDateTime,
|
165
165
|
read: ReadDateTime,
|
166
166
|
write: WriteDateTime,
|
167
167
|
kind: "scalar",
|
168
|
-
description: "Base Type."
|
168
|
+
description: "Base Type."
|
169
169
|
},
|
170
170
|
hash: {
|
171
171
|
params: PresentParamsHash,
|
172
172
|
read: Dry::Types["strict.hash"],
|
173
173
|
write: Dry::Types["strict.hash"],
|
174
174
|
kind: "record",
|
175
|
-
description: "Base Type."
|
175
|
+
description: "Base Type."
|
176
176
|
},
|
177
177
|
array: {
|
178
178
|
params: Dry::Types["strict.array"],
|
179
179
|
read: Dry::Types["strict.array"],
|
180
180
|
write: Dry::Types["strict.array"],
|
181
181
|
kind: "array",
|
182
|
-
description: "Base Type."
|
183
|
-
}
|
182
|
+
description: "Base Type."
|
183
|
+
}
|
184
184
|
}
|
185
185
|
|
186
186
|
hash.each_pair do |k, v|
|
@@ -198,7 +198,7 @@ module Graphiti
|
|
198
198
|
test: Dry::Types["strict.array"].of(map[:test]),
|
199
199
|
write: Dry::Types["strict.array"].of(map[:write]),
|
200
200
|
kind: "array",
|
201
|
-
description: "Base Type."
|
201
|
+
description: "Base Type."
|
202
202
|
}
|
203
203
|
end
|
204
204
|
hash.merge!(arrays)
|
data/lib/graphiti/util/link.rb
CHANGED
@@ -60,10 +60,10 @@ module Graphiti
|
|
60
60
|
def params
|
61
61
|
@params ||= {}.tap do |params|
|
62
62
|
if @sideload.type != :belongs_to || @sideload.remote?
|
63
|
-
params[:filter] = @sideload.
|
63
|
+
params[:filter] = @sideload.link_filter([@model])
|
64
64
|
end
|
65
65
|
|
66
|
-
@sideload.params_proc&.call(params, [@model])
|
66
|
+
@sideload.params_proc&.call(params, [@model], context)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -75,6 +75,10 @@ module Graphiti
|
|
75
75
|
end
|
76
76
|
path
|
77
77
|
end
|
78
|
+
|
79
|
+
def context
|
80
|
+
Graphiti.context[:object]
|
81
|
+
end
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
@@ -8,12 +8,12 @@ class Graphiti::Util::Persistence
|
|
8
8
|
# @param [Model] caller_model The persisted parent object in the request graph
|
9
9
|
# @param [Symbol] foreign_key Attribute assigned by parent object in graph
|
10
10
|
def initialize(resource, meta, attributes, relationships, caller_model, foreign_key = nil)
|
11
|
-
@resource
|
12
|
-
@meta
|
13
|
-
@attributes
|
11
|
+
@resource = resource
|
12
|
+
@meta = meta
|
13
|
+
@attributes = attributes
|
14
14
|
@relationships = relationships
|
15
|
-
@caller_model
|
16
|
-
@foreign_key
|
15
|
+
@caller_model = caller_model
|
16
|
+
@foreign_key = foreign_key
|
17
17
|
|
18
18
|
# Find the correct child resource for a given jsonapi type
|
19
19
|
if (meta_type = @meta[:type].try(:to_sym))
|
@@ -177,9 +177,15 @@ class Graphiti::Util::Persistence
|
|
177
177
|
def process_belongs_to(relationships)
|
178
178
|
[].tap do |processed|
|
179
179
|
iterate(only: [:polymorphic_belongs_to, :belongs_to]) do |x|
|
180
|
-
|
181
|
-
.
|
182
|
-
|
180
|
+
begin
|
181
|
+
id = x.dig(:attributes, :id)
|
182
|
+
x[:object] = x[:resource]
|
183
|
+
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships])
|
184
|
+
processed << x
|
185
|
+
rescue Graphiti::Errors::RecordNotFound
|
186
|
+
path = "relationships/#{x.dig(:meta, :jsonapi_type)}"
|
187
|
+
raise Graphiti::Errors::RecordNotFound.new(x[:sideload].name, id, path)
|
188
|
+
end
|
183
189
|
end
|
184
190
|
end
|
185
191
|
end
|
@@ -202,7 +208,7 @@ class Graphiti::Util::Persistence
|
|
202
208
|
def iterate(only: [], except: [])
|
203
209
|
opts = {
|
204
210
|
resource: @resource,
|
205
|
-
relationships: @relationships
|
211
|
+
relationships: @relationships
|
206
212
|
}.merge(only: only, except: except)
|
207
213
|
|
208
214
|
Graphiti::Util::RelationshipPayload.iterate(opts) do |x|
|
@@ -216,7 +222,7 @@ class Graphiti::Util::Persistence
|
|
216
222
|
temp_id: @meta[:temp_id],
|
217
223
|
caller_model: @caller_model,
|
218
224
|
attributes: @attributes,
|
219
|
-
relationships: @relationships
|
225
|
+
relationships: @relationships
|
220
226
|
}
|
221
227
|
end
|
222
228
|
|
@@ -14,9 +14,9 @@ module Graphiti
|
|
14
14
|
|
15
15
|
def initialize(resource, payload, only: [], except: [])
|
16
16
|
@resource = resource
|
17
|
-
@payload
|
18
|
-
@only
|
19
|
-
@except
|
17
|
+
@payload = payload
|
18
|
+
@only = only
|
19
|
+
@except = except
|
20
20
|
end
|
21
21
|
|
22
22
|
def iterate
|
@@ -67,7 +67,7 @@ module Graphiti
|
|
67
67
|
foreign_key: sideload.foreign_key,
|
68
68
|
attributes: relationship_payload[:attributes],
|
69
69
|
meta: relationship_payload[:meta],
|
70
|
-
relationships: relationship_payload[:relationships]
|
70
|
+
relationships: relationship_payload[:relationships]
|
71
71
|
}
|
72
72
|
end
|
73
73
|
end
|
data/lib/graphiti/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: jsonapi-renderer
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.
|
36
|
+
version: 0.2.2
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- -
|
41
|
+
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2
|
43
|
+
version: '0.2'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.2
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: dry-types
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,20 +190,6 @@ dependencies:
|
|
184
190
|
- - '='
|
185
191
|
- !ruby/object:Gem::Version
|
186
192
|
version: 1.0.beta.4
|
187
|
-
- !ruby/object:Gem::Dependency
|
188
|
-
name: standard
|
189
|
-
requirement: !ruby/object:Gem::Requirement
|
190
|
-
requirements:
|
191
|
-
- - ">="
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
version: '0'
|
194
|
-
type: :development
|
195
|
-
prerelease: false
|
196
|
-
version_requirements: !ruby/object:Gem::Requirement
|
197
|
-
requirements:
|
198
|
-
- - ">="
|
199
|
-
- !ruby/object:Gem::Version
|
200
|
-
version: '0'
|
201
193
|
description:
|
202
194
|
email:
|
203
195
|
- richmolj@gmail.com
|
@@ -241,8 +233,12 @@ files:
|
|
241
233
|
- exe/graphiti
|
242
234
|
- gemfiles/.bundle/config
|
243
235
|
- gemfiles/rails_4.gemfile
|
244
|
-
- gemfiles/
|
245
|
-
- gemfiles/
|
236
|
+
- gemfiles/rails_5_0.gemfile
|
237
|
+
- gemfiles/rails_5_0_graphiti_rails.gemfile
|
238
|
+
- gemfiles/rails_5_1.gemfile
|
239
|
+
- gemfiles/rails_5_1_graphiti_rails.gemfile
|
240
|
+
- gemfiles/rails_5_2.gemfile
|
241
|
+
- gemfiles/rails_5_2_graphiti_rails.gemfile
|
246
242
|
- gemfiles/rails_6.gemfile
|
247
243
|
- gemfiles/rails_6_graphiti_rails.gemfile
|
248
244
|
- graphiti.gemspec
|