graphiti 1.2.42 → 1.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +96 -0
- data/.standard.yml +4 -4
- data/Appraisals +18 -44
- data/CHANGELOG.md +1 -0
- data/gemfiles/rails_5_2.gemfile +2 -2
- data/gemfiles/rails_5_2_graphiti_rails.gemfile +3 -4
- data/gemfiles/rails_6_graphiti_rails.gemfile +1 -2
- data/gemfiles/{rails_5_1.gemfile → rails_7.gemfile} +2 -2
- data/gemfiles/{rails_4.gemfile → rails_7_graphiti_rails.gemfile} +3 -2
- data/graphiti.gemspec +5 -5
- data/lib/graphiti/adapters/abstract.rb +8 -3
- data/lib/graphiti/adapters/active_record.rb +47 -36
- data/lib/graphiti/adapters/null.rb +1 -1
- data/lib/graphiti/adapters/persistence/associations.rb +13 -15
- data/lib/graphiti/delegates/pagination.rb +30 -10
- data/lib/graphiti/errors.rb +17 -11
- data/lib/graphiti/extensions/temp_id.rb +1 -1
- data/lib/graphiti/filter_operators.rb +0 -1
- data/lib/graphiti/hash_renderer.rb +40 -2
- data/lib/graphiti/query.rb +74 -71
- data/lib/graphiti/railtie.rb +4 -4
- data/lib/graphiti/renderer.rb +1 -0
- data/lib/graphiti/request_validator.rb +1 -1
- data/lib/graphiti/resource/configuration.rb +2 -1
- data/lib/graphiti/resource/dsl.rb +14 -6
- data/lib/graphiti/resource/polymorphism.rb +1 -1
- data/lib/graphiti/resource/sideloading.rb +4 -4
- data/lib/graphiti/resource.rb +2 -1
- data/lib/graphiti/resource_proxy.rb +8 -2
- data/lib/graphiti/schema.rb +6 -4
- data/lib/graphiti/scope.rb +2 -2
- data/lib/graphiti/scoping/filter.rb +12 -8
- data/lib/graphiti/scoping/paginate.rb +47 -3
- data/lib/graphiti/scoping/sort.rb +4 -6
- data/lib/graphiti/serializer.rb +19 -1
- data/lib/graphiti/sideload/polymorphic_belongs_to.rb +3 -4
- data/lib/graphiti/stats/dsl.rb +0 -1
- data/lib/graphiti/util/serializer_attributes.rb +6 -0
- data/lib/graphiti/util/simple_errors.rb +3 -3
- data/lib/graphiti/version.rb +1 -1
- data/lib/graphiti.rb +1 -0
- metadata +17 -23
- data/.travis.yml +0 -94
- data/gemfiles/rails_5_0.gemfile +0 -18
- data/gemfiles/rails_5_0_graphiti_rails.gemfile +0 -20
- data/gemfiles/rails_5_1_graphiti_rails.gemfile +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f5b9382256603c1f3f8f4ab8c4e614804c1a2e2152617d7b19892bca6bd465
|
4
|
+
data.tar.gz: 948837bfa0f8deee2f44849aba9df2bb18f2fdf532a1caaab92b16c7d9ba91fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe6fff9c219fd463378bbdc793f648cbeffe27c61c191f11e2aab4723e952d2d8f7cc26b334255e12adca3e9d819b1bbde17697a6621f11a28151d2649d6d9c
|
7
|
+
data.tar.gz: becca9eaa17f328a99669e1e855a4024862b45d1902ddf30de597f7b33e3f52e4145b0f1dba1542a0d144ba2bc1bdec280ad9d8fa599a102ead9efb5260e1ab3
|
@@ -0,0 +1,96 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request: {}
|
7
|
+
|
8
|
+
concurrency:
|
9
|
+
group: ci-${{ github.head_ref || github.ref }}
|
10
|
+
cancel-in-progress: true
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
lint:
|
14
|
+
name: Lint
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: "3.0"
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Run standardrb
|
23
|
+
run: bundle exec standardrb --no-fix --format progress
|
24
|
+
test:
|
25
|
+
name: "Tests - ${{ matrix.ruby }} | ${{ matrix.gemfile }} | Appraisal: ${{ matrix.appraisal }}"
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
strategy:
|
28
|
+
fail-fast: false
|
29
|
+
matrix:
|
30
|
+
ruby:
|
31
|
+
- "2.6"
|
32
|
+
- "2.7"
|
33
|
+
- "3.0"
|
34
|
+
- "3.1"
|
35
|
+
gemfile:
|
36
|
+
- Gemfile
|
37
|
+
- gemfiles/rails_5_2.gemfile
|
38
|
+
- gemfiles/rails_6.gemfile
|
39
|
+
- gemfiles/rails_7.gemfile
|
40
|
+
- gemfiles/rails_5_2_graphiti_rails.gemfile
|
41
|
+
- gemfiles/rails_6_graphiti_rails.gemfile
|
42
|
+
- gemfiles/rails_7_graphiti_rails.gemfile
|
43
|
+
appraisal:
|
44
|
+
- true
|
45
|
+
- false
|
46
|
+
include:
|
47
|
+
- ruby: ruby-head
|
48
|
+
gemfile: Gemfile
|
49
|
+
appraisal: true
|
50
|
+
- ruby: ruby-head
|
51
|
+
gemfile: Gemfile
|
52
|
+
appraisal: false
|
53
|
+
exclude:
|
54
|
+
# Skip some extra variants
|
55
|
+
- gemfile: Gemfile
|
56
|
+
appraisal: true
|
57
|
+
- gemfile: gemfiles/rails_5_2.gemfile
|
58
|
+
appraisal: false
|
59
|
+
- gemfile: gemfiles/rails_6.gemfile
|
60
|
+
appraisal: false
|
61
|
+
- gemfile: gemfiles/rails_7.gemfile
|
62
|
+
appraisal: false
|
63
|
+
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
|
64
|
+
appraisal: false
|
65
|
+
- gemfile: gemfiles/rails_6_graphiti_rails.gemfile
|
66
|
+
appraisal: false
|
67
|
+
- gemfile: gemfiles/rails_7_graphiti_rails.gemfile
|
68
|
+
appraisal: false
|
69
|
+
# Rails 5 can't run on Ruby 3
|
70
|
+
- gemfile: gemfiles/rails_5_2.gemfile
|
71
|
+
ruby: 3.0
|
72
|
+
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
|
73
|
+
ruby: 3.0
|
74
|
+
- gemfile: gemfiles/rails_5_2.gemfile
|
75
|
+
ruby: 3.1
|
76
|
+
- gemfile: gemfiles/rails_5_2_graphiti_rails.gemfile
|
77
|
+
ruby: 3.1
|
78
|
+
# Raise 7 can't run on 2.6
|
79
|
+
- gemfile: gemfiles/rails_7.gemfile
|
80
|
+
ruby: 2.6
|
81
|
+
- gemfile: gemfiles/rails_7_graphiti_rails.gemfile
|
82
|
+
ruby: 2.6
|
83
|
+
continue-on-error: ${{ matrix.ruby == 'ruby-head' }}
|
84
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
85
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
|
86
|
+
steps:
|
87
|
+
- name: Set up Appraisal
|
88
|
+
if: matrix.appraisal
|
89
|
+
run: echo "APPRAISAL_INITIALIZED=true" >> $GITHUB_ENV
|
90
|
+
- uses: actions/checkout@v2
|
91
|
+
- uses: ruby/setup-ruby@v1
|
92
|
+
with:
|
93
|
+
ruby-version: ${{ matrix.ruby }}
|
94
|
+
bundler-cache: true
|
95
|
+
- name: Run tests
|
96
|
+
run: bundle exec rspec
|
data/.standard.yml
CHANGED
@@ -8,7 +8,7 @@ ignore:
|
|
8
8
|
# There are some false hits when doing repeated
|
9
9
|
# Class.new blocks in different test cases
|
10
10
|
- Lint/DuplicateMethods
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
-
|
11
|
+
# We define a lot of test-specific classes within our test blocks
|
12
|
+
# There's probably a better way to do this, but it's not worth the
|
13
|
+
# effort right now, so let's just disable for specs
|
14
|
+
- Lint/ConstantDefinitionInBlock
|
data/Appraisals
CHANGED
@@ -1,70 +1,44 @@
|
|
1
|
-
appraise "rails-4" do
|
2
|
-
gem "rails", "~> 4.2"
|
3
|
-
gem "rspec-rails"
|
4
|
-
gem "sqlite3", "~> 1.3.6"
|
5
|
-
gem "database_cleaner"
|
6
|
-
end
|
7
|
-
|
8
|
-
appraise "rails-5_0" do
|
9
|
-
gem "rails", "~> 5.0"
|
10
|
-
gem "rspec-rails"
|
11
|
-
gem "sqlite3", "~> 1.3.6"
|
12
|
-
gem "database_cleaner"
|
13
|
-
end
|
14
|
-
|
15
|
-
appraise "rails-5_1" do
|
16
|
-
gem "rails", "~> 5.1"
|
17
|
-
gem "rspec-rails"
|
18
|
-
gem "sqlite3", "~> 1.3.6"
|
19
|
-
gem "database_cleaner"
|
20
|
-
end
|
21
|
-
|
22
1
|
appraise "rails-5_2" do
|
23
|
-
gem "rails", "~> 5.2"
|
2
|
+
gem "rails", "~> 5.2.0"
|
24
3
|
gem "rspec-rails"
|
25
|
-
gem "sqlite3", "~> 1.
|
4
|
+
gem "sqlite3", "~> 1.4.0"
|
26
5
|
gem "database_cleaner"
|
27
6
|
end
|
28
7
|
|
29
|
-
appraise "rails-
|
30
|
-
gem "rails", "~> 5.0"
|
8
|
+
appraise "rails-5_2-graphiti-rails" do
|
9
|
+
gem "rails", "~> 5.2.0"
|
31
10
|
gem "rspec-rails"
|
32
|
-
gem "sqlite3", "~> 1.
|
11
|
+
gem "sqlite3", "~> 1.4.0"
|
33
12
|
gem "database_cleaner"
|
34
|
-
gem "
|
35
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
13
|
+
gem "graphiti-rails", "~> 0.4.0"
|
36
14
|
end
|
37
15
|
|
38
|
-
appraise "rails-
|
39
|
-
gem "rails", "~>
|
16
|
+
appraise "rails-6" do
|
17
|
+
gem "rails", "~> 6.0"
|
40
18
|
gem "rspec-rails"
|
41
|
-
gem "sqlite3", "~> 1.
|
19
|
+
gem "sqlite3", "~> 1.4.0"
|
42
20
|
gem "database_cleaner"
|
43
|
-
gem "rescue_registry", git: "https://github.com/wagenet/rescue_registry.git", branch: "master"
|
44
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
45
21
|
end
|
46
22
|
|
47
|
-
appraise "rails-
|
48
|
-
gem "rails", "~>
|
23
|
+
appraise "rails-6-graphiti-rails" do
|
24
|
+
gem "rails", "~> 6.0"
|
49
25
|
gem "rspec-rails"
|
50
|
-
gem "sqlite3", "~> 1.
|
26
|
+
gem "sqlite3", "~> 1.4.0"
|
51
27
|
gem "database_cleaner"
|
52
|
-
gem "
|
53
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
28
|
+
gem "graphiti-rails", "~> 0.4.0"
|
54
29
|
end
|
55
30
|
|
56
|
-
appraise "rails-
|
57
|
-
gem "rails", "~>
|
31
|
+
appraise "rails-7" do
|
32
|
+
gem "rails", "~> 7.0"
|
58
33
|
gem "rspec-rails"
|
59
34
|
gem "sqlite3", "~> 1.4.0"
|
60
35
|
gem "database_cleaner"
|
61
36
|
end
|
62
37
|
|
63
|
-
appraise "rails-
|
64
|
-
gem "rails", "~>
|
38
|
+
appraise "rails-7-graphiti-rails" do
|
39
|
+
gem "rails", "~> 7.0"
|
65
40
|
gem "rspec-rails"
|
66
41
|
gem "sqlite3", "~> 1.4.0"
|
67
42
|
gem "database_cleaner"
|
68
|
-
gem "
|
69
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
43
|
+
gem "graphiti-rails", "~> 0.4.0"
|
70
44
|
end
|
data/CHANGELOG.md
CHANGED
@@ -12,6 +12,7 @@ Features:
|
|
12
12
|
Fixes:
|
13
13
|
- [282] Support model names including "Resource"
|
14
14
|
- [313](https://github.com/graphiti-api/graphiti/pull/313) Sort remote resources in schema generation
|
15
|
+
- [374](https://github.com/graphiti-api/graphiti/pull/374) Trim leading spaces from error messages
|
15
16
|
|
16
17
|
## 1.1.0
|
17
18
|
|
data/gemfiles/rails_5_2.gemfile
CHANGED
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
gem "rails", "~> 5.2"
|
5
|
+
gem "rails", "~> 5.2.0"
|
6
6
|
gem "rspec-rails"
|
7
|
-
gem "sqlite3", "~> 1.
|
7
|
+
gem "sqlite3", "~> 1.4.0"
|
8
8
|
gem "database_cleaner"
|
9
|
-
gem "
|
10
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
9
|
+
gem "graphiti-rails", "~> 0.4.0"
|
11
10
|
|
12
11
|
group :test do
|
13
12
|
gem "pry"
|
@@ -6,8 +6,7 @@ gem "rails", "~> 6.0"
|
|
6
6
|
gem "rspec-rails"
|
7
7
|
gem "sqlite3", "~> 1.4.0"
|
8
8
|
gem "database_cleaner"
|
9
|
-
gem "
|
10
|
-
gem "graphiti-rails", git: "https://github.com/wagenet/graphiti-rails.git", branch: "master"
|
9
|
+
gem "graphiti-rails", "~> 0.4.0"
|
11
10
|
|
12
11
|
group :test do
|
13
12
|
gem "pry"
|
data/graphiti.gemspec
CHANGED
@@ -16,20 +16,20 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.bindir = "exe"
|
17
17
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
|
-
spec.required_ruby_version =
|
19
|
+
spec.required_ruby_version = ">= 2.6"
|
20
20
|
|
21
21
|
spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
|
22
22
|
spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
|
23
23
|
spec.add_dependency "dry-types", ">= 0.15.0", "< 2.0"
|
24
24
|
spec.add_dependency "graphiti_errors", "~> 1.1.0"
|
25
25
|
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
26
|
-
spec.add_dependency "activesupport", ">=
|
26
|
+
spec.add_dependency "activesupport", ">= 5.2"
|
27
27
|
|
28
28
|
spec.add_development_dependency "faraday", "~> 0.15"
|
29
29
|
spec.add_development_dependency "kaminari", "~> 0.17"
|
30
30
|
spec.add_development_dependency "bundler"
|
31
|
-
spec.add_development_dependency "rake", "
|
32
|
-
spec.add_development_dependency "standard", "
|
33
|
-
spec.add_development_dependency "activemodel", ">=
|
31
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
32
|
+
spec.add_development_dependency "standard", "~> 1.4.0"
|
33
|
+
spec.add_development_dependency "activemodel", ">= 5.2"
|
34
34
|
spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
|
35
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Graphiti
|
2
2
|
module Adapters
|
3
3
|
class Abstract
|
4
|
-
require "graphiti/adapters/persistence/associations
|
4
|
+
require "graphiti/adapters/persistence/associations"
|
5
5
|
include Graphiti::Adapters::Persistence::Associations
|
6
6
|
|
7
7
|
attr_reader :resource
|
@@ -244,14 +244,15 @@ module Graphiti
|
|
244
244
|
# @param scope The scope object we are chaining
|
245
245
|
# @param [Integer] current_page The current page number
|
246
246
|
# @param [Integer] per_page The number of results per page
|
247
|
+
# @param [Integer] offset The offset to start from
|
247
248
|
# @return the scope
|
248
249
|
#
|
249
250
|
# @example ActiveRecord default
|
250
251
|
# # via kaminari gem
|
251
|
-
# def paginate(scope, current_page, per_page)
|
252
|
+
# def paginate(scope, current_page, per_page, offset)
|
252
253
|
# scope.page(current_page).per(per_page)
|
253
254
|
# end
|
254
|
-
def paginate(scope, current_page, per_page)
|
255
|
+
def paginate(scope, current_page, per_page, offset)
|
255
256
|
raise "you must override #paginate in an adapter subclass"
|
256
257
|
end
|
257
258
|
|
@@ -414,6 +415,10 @@ module Graphiti
|
|
414
415
|
[:eq, :not_eq, :gt, :gte, :lt, :lte].freeze
|
415
416
|
end
|
416
417
|
|
418
|
+
def can_group?
|
419
|
+
false
|
420
|
+
end
|
421
|
+
|
417
422
|
private
|
418
423
|
|
419
424
|
def activerecord_adapter
|
@@ -19,24 +19,24 @@ module Graphiti
|
|
19
19
|
def filter_eq(scope, attribute, value)
|
20
20
|
scope.where(attribute => value)
|
21
21
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
alias_method :filter_integer_eq, :filter_eq
|
23
|
+
alias_method :filter_float_eq, :filter_eq
|
24
|
+
alias_method :filter_big_decimal_eq, :filter_eq
|
25
|
+
alias_method :filter_date_eq, :filter_eq
|
26
|
+
alias_method :filter_boolean_eq, :filter_eq
|
27
|
+
alias_method :filter_uuid_eq, :filter_eq
|
28
|
+
alias_method :filter_enum_eq, :filter_eq
|
29
29
|
|
30
30
|
def filter_not_eq(scope, attribute, value)
|
31
31
|
scope.where.not(attribute => value)
|
32
32
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
alias_method :filter_integer_not_eq, :filter_not_eq
|
34
|
+
alias_method :filter_float_not_eq, :filter_not_eq
|
35
|
+
alias_method :filter_big_decimal_not_eq, :filter_not_eq
|
36
|
+
alias_method :filter_date_not_eq, :filter_not_eq
|
37
|
+
alias_method :filter_boolean_not_eq, :filter_not_eq
|
38
|
+
alias_method :filter_uuid_not_eq, :filter_not_eq
|
39
|
+
alias_method :filter_enum_not_eq, :filter_not_eq
|
40
40
|
|
41
41
|
def filter_string_eq(scope, attribute, value, is_not: false)
|
42
42
|
column = column_for(scope, attribute)
|
@@ -122,40 +122,40 @@ module Graphiti
|
|
122
122
|
column = column_for(scope, attribute)
|
123
123
|
scope.where(column.gt_any(value))
|
124
124
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
alias_method :filter_integer_gt, :filter_gt
|
126
|
+
alias_method :filter_float_gt, :filter_gt
|
127
|
+
alias_method :filter_big_decimal_gt, :filter_gt
|
128
|
+
alias_method :filter_datetime_gt, :filter_gt
|
129
|
+
alias_method :filter_date_gt, :filter_gt
|
130
130
|
|
131
131
|
def filter_gte(scope, attribute, value)
|
132
132
|
column = column_for(scope, attribute)
|
133
133
|
scope.where(column.gteq_any(value))
|
134
134
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
alias_method :filter_integer_gte, :filter_gte
|
136
|
+
alias_method :filter_float_gte, :filter_gte
|
137
|
+
alias_method :filter_big_decimal_gte, :filter_gte
|
138
|
+
alias_method :filter_datetime_gte, :filter_gte
|
139
|
+
alias_method :filter_date_gte, :filter_gte
|
140
140
|
|
141
141
|
def filter_lt(scope, attribute, value)
|
142
142
|
column = column_for(scope, attribute)
|
143
143
|
scope.where(column.lt_any(value))
|
144
144
|
end
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
145
|
+
alias_method :filter_integer_lt, :filter_lt
|
146
|
+
alias_method :filter_float_lt, :filter_lt
|
147
|
+
alias_method :filter_big_decimal_lt, :filter_lt
|
148
|
+
alias_method :filter_datetime_lt, :filter_lt
|
149
|
+
alias_method :filter_date_lt, :filter_lt
|
150
150
|
|
151
151
|
def filter_lte(scope, attribute, value)
|
152
152
|
column = column_for(scope, attribute)
|
153
153
|
scope.where(column.lteq_any(value))
|
154
154
|
end
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
155
|
+
alias_method :filter_integer_lte, :filter_lte
|
156
|
+
alias_method :filter_float_lte, :filter_lte
|
157
|
+
alias_method :filter_big_decimal_lte, :filter_lte
|
158
|
+
alias_method :filter_date_lte, :filter_lte
|
159
159
|
|
160
160
|
# Ensure fractional seconds don't matter
|
161
161
|
def filter_datetime_eq(scope, attribute, value, is_not: false)
|
@@ -184,8 +184,11 @@ module Graphiti
|
|
184
184
|
end
|
185
185
|
|
186
186
|
# (see Adapters::Abstract#paginate)
|
187
|
-
def paginate(scope, current_page, per_page)
|
188
|
-
scope.page(current_page)
|
187
|
+
def paginate(scope, current_page, per_page, offset)
|
188
|
+
scope = scope.page(current_page) if current_page
|
189
|
+
scope = scope.per(per_page) if per_page
|
190
|
+
scope = scope.padding(offset) if offset
|
191
|
+
scope
|
189
192
|
end
|
190
193
|
|
191
194
|
# (see Adapters::Abstract#count)
|
@@ -302,6 +305,14 @@ module Graphiti
|
|
302
305
|
::ActiveRecord::Base.clear_active_connections!
|
303
306
|
end
|
304
307
|
|
308
|
+
def can_group?
|
309
|
+
true
|
310
|
+
end
|
311
|
+
|
312
|
+
def group(scope, attribute)
|
313
|
+
scope.group(attribute)
|
314
|
+
end
|
315
|
+
|
305
316
|
private
|
306
317
|
|
307
318
|
def column_for(scope, name)
|
@@ -314,7 +325,7 @@ module Graphiti
|
|
314
325
|
end
|
315
326
|
|
316
327
|
def sanitized_like_for(scope, attribute, value, &block)
|
317
|
-
escape_char =
|
328
|
+
escape_char = "\\"
|
318
329
|
column = column_for(scope, attribute)
|
319
330
|
map = value.map { |v|
|
320
331
|
v = v.downcase
|
@@ -5,22 +5,20 @@ module Graphiti
|
|
5
5
|
def process_belongs_to(persistence, attributes)
|
6
6
|
parents = [].tap do |processed|
|
7
7
|
persistence.iterate(only: [:polymorphic_belongs_to, :belongs_to]) do |x|
|
8
|
-
|
9
|
-
|
10
|
-
x[:
|
11
|
-
|
8
|
+
id = x.dig(:attributes, :id)
|
9
|
+
x[:object] = x[:resource]
|
10
|
+
.persist_with_relationships(x[:meta], x[:attributes], x[:relationships])
|
11
|
+
processed << x
|
12
|
+
rescue Graphiti::Errors::RecordNotFound
|
13
|
+
if Graphiti.config.raise_on_missing_sidepost
|
14
|
+
path = "relationships/#{x.dig(:meta, :jsonapi_type)}"
|
15
|
+
raise Graphiti::Errors::RecordNotFound.new(x[:sideload].name, id, path)
|
16
|
+
else
|
17
|
+
pointer = "data/relationships/#{x.dig(:meta, :jsonapi_type)}"
|
18
|
+
object = Graphiti::Errors::NullRelation.new(id.to_s, pointer)
|
19
|
+
object.errors.add(:base, :not_found, message: "could not be found")
|
20
|
+
x[:object] = object
|
12
21
|
processed << x
|
13
|
-
rescue Graphiti::Errors::RecordNotFound
|
14
|
-
if Graphiti.config.raise_on_missing_sidepost
|
15
|
-
path = "relationships/#{x.dig(:meta, :jsonapi_type)}"
|
16
|
-
raise Graphiti::Errors::RecordNotFound.new(x[:sideload].name, id, path)
|
17
|
-
else
|
18
|
-
pointer = "data/relationships/#{x.dig(:meta, :jsonapi_type)}"
|
19
|
-
object = Graphiti::Errors::NullRelation.new(id.to_s, pointer)
|
20
|
-
object.errors.add(:base, :not_found, message: "could not be found")
|
21
|
-
x[:object] = object
|
22
|
-
processed << x
|
23
|
-
end
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -14,11 +14,21 @@ module Graphiti
|
|
14
14
|
links[:self] = pagination_link(current_page)
|
15
15
|
links[:first] = pagination_link(1)
|
16
16
|
links[:last] = pagination_link(last_page)
|
17
|
-
links[:prev] = pagination_link(current_page - 1)
|
18
|
-
links[:next] = pagination_link(current_page + 1)
|
17
|
+
links[:prev] = pagination_link(current_page - 1) if has_previous_page?
|
18
|
+
links[:next] = pagination_link(current_page + 1) if has_next_page?
|
19
19
|
end.select { |k, v| !v.nil? }
|
20
20
|
end
|
21
21
|
|
22
|
+
def has_next_page?
|
23
|
+
current_page != last_page && last_page.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
def has_previous_page?
|
27
|
+
current_page != 1 ||
|
28
|
+
!!pagination_params.try(:[], :page).try(:[], :after) ||
|
29
|
+
!!pagination_params.try(:[], :page).try(:[], :offset)
|
30
|
+
end
|
31
|
+
|
22
32
|
private
|
23
33
|
|
24
34
|
def pagination_params
|
@@ -30,13 +40,14 @@ module Graphiti
|
|
30
40
|
|
31
41
|
uri = URI(@proxy.resource.endpoint[:url].to_s)
|
32
42
|
|
43
|
+
page_params = {
|
44
|
+
number: page,
|
45
|
+
size: page_size
|
46
|
+
}
|
47
|
+
page_params[:offset] = offset if offset
|
48
|
+
|
33
49
|
# Overwrite the pagination query params with the desired page
|
34
|
-
uri.query = pagination_params.merge(
|
35
|
-
page: {
|
36
|
-
number: page,
|
37
|
-
size: page_size
|
38
|
-
}
|
39
|
-
}).to_query
|
50
|
+
uri.query = pagination_params.merge(page: page_params).to_query
|
40
51
|
uri.to_s
|
41
52
|
end
|
42
53
|
|
@@ -46,8 +57,11 @@ module Graphiti
|
|
46
57
|
elsif page_size == 0 || item_count == 0
|
47
58
|
return nil
|
48
59
|
end
|
49
|
-
|
50
|
-
|
60
|
+
|
61
|
+
count = item_count
|
62
|
+
count = item_count - offset if offset
|
63
|
+
@last_page = (count / page_size)
|
64
|
+
@last_page += 1 if count % page_size > 0
|
51
65
|
@last_page
|
52
66
|
end
|
53
67
|
|
@@ -82,6 +96,12 @@ module Graphiti
|
|
82
96
|
@current_page ||= (page_param[:number] || 1).to_i
|
83
97
|
end
|
84
98
|
|
99
|
+
def offset
|
100
|
+
@offset ||= if (value = page_param[:offset])
|
101
|
+
value.to_i
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
85
105
|
def page_size
|
86
106
|
@page_size ||= (page_param[:size] ||
|
87
107
|
@proxy.resource.default_page_size ||
|