graphiti 1.2.42 → 1.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +96 -0
  3. data/.standard.yml +4 -4
  4. data/Appraisals +18 -44
  5. data/CHANGELOG.md +1 -0
  6. data/gemfiles/rails_5_2.gemfile +2 -2
  7. data/gemfiles/rails_5_2_graphiti_rails.gemfile +3 -4
  8. data/gemfiles/rails_6_graphiti_rails.gemfile +1 -2
  9. data/gemfiles/{rails_5_1.gemfile → rails_7.gemfile} +2 -2
  10. data/gemfiles/{rails_4.gemfile → rails_7_graphiti_rails.gemfile} +3 -2
  11. data/graphiti.gemspec +5 -5
  12. data/lib/graphiti/adapters/abstract.rb +8 -3
  13. data/lib/graphiti/adapters/active_record.rb +47 -36
  14. data/lib/graphiti/adapters/null.rb +1 -1
  15. data/lib/graphiti/adapters/persistence/associations.rb +13 -15
  16. data/lib/graphiti/delegates/pagination.rb +30 -10
  17. data/lib/graphiti/errors.rb +17 -11
  18. data/lib/graphiti/extensions/temp_id.rb +1 -1
  19. data/lib/graphiti/filter_operators.rb +0 -1
  20. data/lib/graphiti/hash_renderer.rb +40 -2
  21. data/lib/graphiti/query.rb +74 -71
  22. data/lib/graphiti/railtie.rb +4 -4
  23. data/lib/graphiti/renderer.rb +1 -0
  24. data/lib/graphiti/request_validator.rb +1 -1
  25. data/lib/graphiti/resource/configuration.rb +2 -1
  26. data/lib/graphiti/resource/dsl.rb +14 -6
  27. data/lib/graphiti/resource/polymorphism.rb +1 -1
  28. data/lib/graphiti/resource/sideloading.rb +4 -4
  29. data/lib/graphiti/resource.rb +2 -1
  30. data/lib/graphiti/resource_proxy.rb +8 -2
  31. data/lib/graphiti/schema.rb +6 -4
  32. data/lib/graphiti/scope.rb +2 -2
  33. data/lib/graphiti/scoping/filter.rb +12 -8
  34. data/lib/graphiti/scoping/paginate.rb +47 -3
  35. data/lib/graphiti/scoping/sort.rb +4 -6
  36. data/lib/graphiti/serializer.rb +19 -1
  37. data/lib/graphiti/sideload/polymorphic_belongs_to.rb +3 -4
  38. data/lib/graphiti/stats/dsl.rb +0 -1
  39. data/lib/graphiti/util/serializer_attributes.rb +6 -0
  40. data/lib/graphiti/util/simple_errors.rb +3 -3
  41. data/lib/graphiti/version.rb +1 -1
  42. data/lib/graphiti.rb +1 -0
  43. metadata +17 -23
  44. data/.travis.yml +0 -94
  45. data/gemfiles/rails_5_0.gemfile +0 -18
  46. data/gemfiles/rails_5_0_graphiti_rails.gemfile +0 -20
  47. data/gemfiles/rails_5_1_graphiti_rails.gemfile +0 -20
@@ -1,6 +1,7 @@
1
1
  module Graphiti
2
2
  class Scoping::Paginate < Scoping::Base
3
3
  DEFAULT_PAGE_SIZE = 20
4
+ PARAMS = [:number, :size, :offset, :before, :after]
4
5
 
5
6
  def apply
6
7
  if size > resource.max_page_size
@@ -33,24 +34,67 @@ module Graphiti
33
34
 
34
35
  # Apply default pagination proc via the Resource adapter
35
36
  def apply_standard_scope
36
- resource.adapter.paginate(@scope, number, size)
37
+ meth = resource.adapter.method(:paginate)
38
+
39
+ if meth.arity == 4 # backwards-compat
40
+ resource.adapter.paginate(@scope, number, size, offset)
41
+ else
42
+ resource.adapter.paginate(@scope, number, size)
43
+ end
37
44
  end
38
45
 
39
46
  # Apply the custom pagination proc
40
47
  def apply_custom_scope
41
- resource.instance_exec(@scope, number, size, resource.context, &custom_scope)
48
+ resource.instance_exec \
49
+ @scope,
50
+ number,
51
+ size,
52
+ resource.context,
53
+ offset,
54
+ &custom_scope
42
55
  end
43
56
 
44
57
  private
45
58
 
46
59
  def requested?
47
- ![page_param[:size], page_param[:number]].all?(&:nil?)
60
+ !PARAMS.map { |p| page_param[p] }.all?(&:nil?)
48
61
  end
49
62
 
50
63
  def page_param
51
64
  @page_param ||= (query_hash[:page] || {})
52
65
  end
53
66
 
67
+ def offset
68
+ offset = nil
69
+
70
+ if (value = page_param[:offset])
71
+ offset = value.to_i
72
+ end
73
+
74
+ if before_cursor&.key?(:offset)
75
+ if page_param.key?(:number)
76
+ raise Errors::UnsupportedBeforeCursor
77
+ end
78
+
79
+ offset = before_cursor[:offset] - (size * number) - 1
80
+ offset = 0 if offset.negative?
81
+ end
82
+
83
+ if after_cursor&.key?(:offset)
84
+ offset = after_cursor[:offset]
85
+ end
86
+
87
+ offset
88
+ end
89
+
90
+ def after_cursor
91
+ page_param[:after]
92
+ end
93
+
94
+ def before_cursor
95
+ page_param[:before]
96
+ end
97
+
54
98
  def number
55
99
  (page_param[:number] || 1).to_i
56
100
  end
@@ -59,12 +59,10 @@ module Graphiti
59
59
  end
60
60
 
61
61
  def sort_param
62
- @sort_param ||= begin
63
- if query_hash[:sort].blank?
64
- resource.default_sort || []
65
- else
66
- normalize(query_hash[:sort])
67
- end
62
+ @sort_param ||= if query_hash[:sort].blank?
63
+ resource.default_sort || []
64
+ else
65
+ normalize(query_hash[:sort])
68
66
  end
69
67
  end
70
68
 
@@ -25,8 +25,9 @@ module Graphiti
25
25
 
26
26
  # See #requested_relationships
27
27
  def self.relationship(name, options = {}, &block)
28
+ prev = Util::Hash.deep_dup(field_condition_blocks)
28
29
  super
29
- field_condition_blocks.delete(name)
30
+ self.field_condition_blocks = prev
30
31
  _register_condition(relationship_condition_blocks, name, options)
31
32
  end
32
33
 
@@ -45,6 +46,23 @@ module Graphiti
45
46
  end
46
47
  end
47
48
 
49
+ def cursor
50
+ starting_offset = 0
51
+ page_param = @proxy.query.pagination
52
+ if (page_number = page_param[:number])
53
+ page_size = page_param[:size] || @resource.default_page_size
54
+ starting_offset = (page_number - 1) * page_size
55
+ end
56
+
57
+ if (cursor = page_param[:after])
58
+ starting_offset = cursor[:offset]
59
+ end
60
+
61
+ current_offset = @object.instance_variable_get(:@__graphiti_index)
62
+ offset = starting_offset + current_offset + 1 # (+ 1 b/c o-base index)
63
+ Base64.encode64({offset: offset}.to_json).chomp
64
+ end
65
+
48
66
  def as_jsonapi(kwargs = {})
49
67
  super(**kwargs).tap do |hash|
50
68
  strip_relationships!(hash) if strip_relationships?
@@ -7,7 +7,6 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
7
7
  @calls = []
8
8
  end
9
9
 
10
- # rubocop: disable Style/MethodMissingSuper
11
10
  def method_missing(name, *args, &blk)
12
11
  @calls << [name, args, blk]
13
12
  end
@@ -56,9 +55,9 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
56
55
  args = call[1]
57
56
  opts = args.extract_options!
58
57
  opts.merge! as: sideload.name,
59
- parent: sideload,
60
- group_name: group.name,
61
- polymorphic_child: true
58
+ parent: sideload,
59
+ group_name: group.name,
60
+ polymorphic_child: true
62
61
  unless sideload.resource.class.abstract_class?
63
62
  opts[:foreign_key] ||= sideload.foreign_key
64
63
  opts[:primary_key] ||= sideload.primary_key
@@ -46,7 +46,6 @@ module Graphiti
46
46
  #
47
47
  # ...will hit +method_missing+ and store the proc for future reference.
48
48
  # @api private
49
- # rubocop: disable Style/MethodMissingSuper
50
49
  def method_missing(meth, *args, &blk)
51
50
  @calculations[meth] = blk
52
51
  end
@@ -28,6 +28,12 @@ module Graphiti
28
28
 
29
29
  existing = @serializer.send(applied_method)
30
30
  @serializer.send(:"#{applied_method}=", [@name] | existing)
31
+
32
+ @serializer.meta do
33
+ if !!@resource.try(:cursor_paginatable?) && !Graphiti.context[:graphql]
34
+ {cursor: cursor}
35
+ end
36
+ end
31
37
  end
32
38
 
33
39
  private
@@ -33,7 +33,7 @@ module Graphiti
33
33
  def size
34
34
  values.flatten.size
35
35
  end
36
- alias count size
36
+ alias_method :count, :size
37
37
 
38
38
  def values
39
39
  messages.values.reject(&:empty?)
@@ -48,7 +48,7 @@ module Graphiti
48
48
  def empty?
49
49
  size.zero?
50
50
  end
51
- alias blank? empty?
51
+ alias_method :blank?, :empty?
52
52
 
53
53
  def add(attribute, code, message: nil)
54
54
  message ||= "is #{code.to_s.humanize.downcase}"
@@ -64,7 +64,7 @@ module Graphiti
64
64
  def full_messages
65
65
  map { |attribute, message| full_message(attribute, message) }
66
66
  end
67
- alias to_a full_messages
67
+ alias_method :to_a, :full_messages
68
68
 
69
69
  def full_messages_for(attribute)
70
70
  attribute = attribute.to_sym
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.2.42"
2
+ VERSION = "1.3.9"
3
3
  end
data/lib/graphiti.rb CHANGED
@@ -208,6 +208,7 @@ module InstanceVariableOverride
208
208
  values
209
209
  end
210
210
  end
211
+
211
212
  class Object
212
213
  prepend InstanceVariableOverride
213
214
  end
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.42
4
+ version: 1.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: '4.1'
101
+ version: '5.2'
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: '4.1'
108
+ version: '5.2'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: faraday
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -152,44 +152,44 @@ dependencies:
152
152
  name: rake
153
153
  requirement: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - "~>"
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '10.0'
158
158
  type: :development
159
159
  prerelease: false
160
160
  version_requirements: !ruby/object:Gem::Requirement
161
161
  requirements:
162
- - - "~>"
162
+ - - ">="
163
163
  - !ruby/object:Gem::Version
164
164
  version: '10.0'
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: standard
167
167
  requirement: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '='
169
+ - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 0.4.7
171
+ version: 1.4.0
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - '='
176
+ - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 0.4.7
178
+ version: 1.4.0
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: activemodel
181
181
  requirement: !ruby/object:Gem::Requirement
182
182
  requirements:
183
183
  - - ">="
184
184
  - !ruby/object:Gem::Version
185
- version: '4.1'
185
+ version: '5.2'
186
186
  type: :development
187
187
  prerelease: false
188
188
  version_requirements: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
- version: '4.1'
192
+ version: '5.2'
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: graphiti_spec_helpers
195
195
  requirement: !ruby/object:Gem::Requirement
@@ -212,10 +212,10 @@ executables:
212
212
  extensions: []
213
213
  extra_rdoc_files: []
214
214
  files:
215
+ - ".github/workflows/ci.yml"
215
216
  - ".gitignore"
216
217
  - ".rspec"
217
218
  - ".standard.yml"
218
- - ".travis.yml"
219
219
  - ".yardopts"
220
220
  - Appraisals
221
221
  - CHANGELOG.md
@@ -246,15 +246,12 @@ files:
246
246
  - deprecated_generators/graphiti/templates/update_request_spec.rb.erb
247
247
  - exe/graphiti
248
248
  - gemfiles/.bundle/config
249
- - gemfiles/rails_4.gemfile
250
- - gemfiles/rails_5_0.gemfile
251
- - gemfiles/rails_5_0_graphiti_rails.gemfile
252
- - gemfiles/rails_5_1.gemfile
253
- - gemfiles/rails_5_1_graphiti_rails.gemfile
254
249
  - gemfiles/rails_5_2.gemfile
255
250
  - gemfiles/rails_5_2_graphiti_rails.gemfile
256
251
  - gemfiles/rails_6.gemfile
257
252
  - gemfiles/rails_6_graphiti_rails.gemfile
253
+ - gemfiles/rails_7.gemfile
254
+ - gemfiles/rails_7_graphiti_rails.gemfile
258
255
  - graphiti.gemspec
259
256
  - lib/graphiti.rb
260
257
  - lib/graphiti/adapters/abstract.rb
@@ -351,17 +348,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
348
  requirements:
352
349
  - - ">="
353
350
  - !ruby/object:Gem::Version
354
- version: '2.3'
355
- - - "<"
356
- - !ruby/object:Gem::Version
357
- version: '3.1'
351
+ version: '2.6'
358
352
  required_rubygems_version: !ruby/object:Gem::Requirement
359
353
  requirements:
360
354
  - - ">="
361
355
  - !ruby/object:Gem::Version
362
356
  version: '0'
363
357
  requirements: []
364
- rubygems_version: 3.0.3
358
+ rubygems_version: 3.3.7
365
359
  signing_key:
366
360
  specification_version: 4
367
361
  summary: Easily build jsonapi.org-compatible APIs
data/.travis.yml DELETED
@@ -1,94 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
- gemfile:
8
- - Gemfile
9
- - gemfiles/rails_4.gemfile
10
- - gemfiles/rails_5_0.gemfile
11
- - gemfiles/rails_5_1.gemfile
12
- - gemfiles/rails_5_2.gemfile
13
- - gemfiles/rails_6.gemfile
14
- - gemfiles/rails_5_0_graphiti_rails.gemfile
15
- - gemfiles/rails_5_1_graphiti_rails.gemfile
16
- - gemfiles/rails_5_2_graphiti_rails.gemfile
17
- - gemfiles/rails_6_graphiti_rails.gemfile
18
- env:
19
- - COMMAND="standardrb --no-fix --format progress"
20
- - COMMAND=rspec
21
- - COMMAND=rspec APPRAISAL_INITIALIZED=true
22
- jobs:
23
- allow_failures:
24
- - rvm: ruby-head
25
- include:
26
- - env: COMMAND=rspec
27
- gemfile: Gemfile
28
- rvm: ruby-head
29
- exclude:
30
- # Don't run the appraisal version of the specs for the base gemfile
31
- - env: COMMAND=rspec APPRAISAL_INITIALIZED=true
32
- gemfile: Gemfile
33
- # Don't run the standardrb check on any gemfile except the base gemfile
34
- # (but run it for each ruby version)
35
- - env: COMMAND="standardrb --no-fix --format progress"
36
- gemfile: gemfiles/rails_4.gemfile
37
- - env: COMMAND="standardrb --no-fix --format progress"
38
- gemfile: gemfiles/rails_5_0.gemfile
39
- - env: COMMAND="standardrb --no-fix --format progress"
40
- gemfile: gemfiles/rails_5_1.gemfile
41
- - env: COMMAND="standardrb --no-fix --format progress"
42
- gemfile: gemfiles/rails_5_2.gemfile
43
- - env: COMMAND="standardrb --no-fix --format progress"
44
- gemfile: gemfiles/rails_6.gemfile
45
- - env: COMMAND="standardrb --no-fix --format progress"
46
- gemfile: gemfiles/rails_5_0_graphiti_rails.gemfile
47
- - env: COMMAND="standardrb --no-fix --format progress"
48
- gemfile: gemfiles/rails_5_1_graphiti_rails.gemfile
49
- - env: COMMAND="standardrb --no-fix --format progress"
50
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
51
- - env: COMMAND="standardrb --no-fix --format progress"
52
- gemfile: gemfiles/rails_6_graphiti_rails.gemfile
53
- # Don't run the basic versions of the specs for any of the specific gemfiles
54
- - env: COMMAND=rspec
55
- gemfile: gemfiles/rails_4.gemfile
56
- - env: COMMAND=rspec
57
- gemfile: gemfiles/rails_5_0.gemfile
58
- - env: COMMAND=rspec
59
- gemfile: gemfiles/rails_5_1.gemfile
60
- - env: COMMAND=rspec
61
- gemfile: gemfiles/rails_5_2.gemfile
62
- - env: COMMAND=rspec
63
- gemfile: gemfiles/rails_6.gemfile
64
- - env: COMMAND=rspec
65
- gemfile: gemfiles/rails_5_0_graphiti_rails.gemfile
66
- - env: COMMAND=rspec
67
- gemfile: gemfiles/rails_5_1_graphiti_rails.gemfile
68
- - env: COMMAND=rspec
69
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
70
- - env: COMMAND=rspec
71
- gemfile: gemfiles/rails_6_graphiti_rails.gemfile
72
-
73
- # Don't run rails 4 egmfile against any rubies (for some reason?)
74
- - gemfile: gemfiles/rails_4.gemfile
75
- rvm: 2.5
76
- - gemfile: gemfiles/rails_4.gemfile
77
- rvm: 2.6
78
- - gemfile: gemfiles/rails_4.gemfile
79
- rvm: 2.7
80
-
81
- script:
82
- - bundle _1.17.3_ exec $COMMAND
83
-
84
- install: bundle _1.17.3_ install --retry=3 --jobs=3
85
- before_install:
86
- - gem install bundler -v '1.17.3'
87
- deploy:
88
- provider: rubygems
89
- api_key:
90
- secure: aON6EPWgHZXVQs+n/glMjPJ5kMpeR25khDpYlFIM0Ggf2+xuT/yRMtGbNTYnB01v/v2s9tNWK6QlMGARCbKz/W6WS8VNwFxs4DO1IPY3XoyF8QaPlXVKfBLldjUoVx61zL5xtcv8uZqWT1ATY+DjHW3nQ875ss/GW8tw+UASG1uUEuPCE9z+rNa3xYnm2qSZOwhFWqs5bHRQcc3gF3O8Hy8r4aosYTAlYOSeGDToqTUq1Ws21dV4xnIo97Nhmh9SYBQcKpZk1qF9bUz4zqdKsDKAxHMJRShtILmhPxNpIqE5ZV0+Xt+cnwi11AZDhSgfoUqYO9t2uG562luAqTnEZEQl+Lmc+nx4nJTH6tcR3ri301k0O+qDZ3PgSojJvrUuNC8DDLbbsVJNHYycGOLclqQq1aNbgz9HayEE5s+AyklPcprJhngxA5WP80AtONAxxLt4OjrY0X80TvOi2b5nfIN7DowGmcLbRahnms98Yk6/i1vCNV4R9bO0AaqpGLV+L8sVp98Qquk2mpvB3Le4W89qm5int1y2FNJbgInBpY1UOsI3wLENt0npC1X/KVMJKkpHvk80rGccI5FIVRUDZ3YD77hi+s1busPSVQ/+l4QdTFHmWp13Pghf6hNaIwfNwFMHwM2Fkv8YXa4c1mWc1cY5WP1ELS8cEnjtmp/9Iuc=
91
- gem: graphiti
92
- on:
93
- tags: true
94
- repo: graphiti-api/graphiti
@@ -1,18 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.0"
6
- gem "rspec-rails"
7
- gem "sqlite3", "~> 1.3.6"
8
- gem "database_cleaner"
9
-
10
- group :test do
11
- gem "pry"
12
- gem "pry-byebug", platform: [:mri]
13
- gem "appraisal"
14
- gem "guard"
15
- gem "guard-rspec"
16
- end
17
-
18
- gemspec path: "../"
@@ -1,20 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.0"
6
- gem "rspec-rails"
7
- gem "sqlite3", "~> 1.3.6"
8
- gem "database_cleaner"
9
- gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
10
- gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
11
-
12
- group :test do
13
- gem "pry"
14
- gem "pry-byebug", platform: [:mri]
15
- gem "appraisal"
16
- gem "guard"
17
- gem "guard-rspec"
18
- end
19
-
20
- gemspec path: "../"
@@ -1,20 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 5.1"
6
- gem "rspec-rails"
7
- gem "sqlite3", "~> 1.3.6"
8
- gem "database_cleaner"
9
- gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
10
- gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
11
-
12
- group :test do
13
- gem "pry"
14
- gem "pry-byebug", platform: [:mri]
15
- gem "appraisal"
16
- gem "guard"
17
- gem "guard-rspec"
18
- end
19
-
20
- gemspec path: "../"