graphiti 1.2.44 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +5 -1
- data/lib/graphiti/adapters/active_record.rb +42 -34
- data/lib/graphiti/adapters/persistence/associations.rb +13 -15
- data/lib/graphiti/delegates/pagination.rb +14 -6
- 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 +71 -68
- 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/paginate.rb +28 -2
- 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
|
@@ -415,6 +415,10 @@ module Graphiti
|
|
415
415
|
[:eq, :not_eq, :gt, :gte, :lt, :lte].freeze
|
416
416
|
end
|
417
417
|
|
418
|
+
def can_group?
|
419
|
+
false
|
420
|
+
end
|
421
|
+
|
418
422
|
private
|
419
423
|
|
420
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)
|
@@ -305,6 +305,14 @@ module Graphiti
|
|
305
305
|
::ActiveRecord::Base.clear_active_connections!
|
306
306
|
end
|
307
307
|
|
308
|
+
def can_group?
|
309
|
+
true
|
310
|
+
end
|
311
|
+
|
312
|
+
def group(scope, attribute)
|
313
|
+
scope.group(attribute)
|
314
|
+
end
|
315
|
+
|
308
316
|
private
|
309
317
|
|
310
318
|
def column_for(scope, name)
|
@@ -317,7 +325,7 @@ module Graphiti
|
|
317
325
|
end
|
318
326
|
|
319
327
|
def sanitized_like_for(scope, attribute, value, &block)
|
320
|
-
escape_char =
|
328
|
+
escape_char = "\\"
|
321
329
|
column = column_for(scope, attribute)
|
322
330
|
map = value.map { |v|
|
323
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
|
@@ -87,10 +97,8 @@ module Graphiti
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def offset
|
90
|
-
@offset ||=
|
91
|
-
|
92
|
-
value.to_i
|
93
|
-
end
|
100
|
+
@offset ||= if (value = page_param[:offset])
|
101
|
+
value.to_i
|
94
102
|
end
|
95
103
|
end
|
96
104
|
|
data/lib/graphiti/errors.rb
CHANGED
@@ -35,7 +35,7 @@ module Graphiti
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def message
|
38
|
-
|
38
|
+
<<~MSG
|
39
39
|
The adapter #{@adapter.class} does not implement method '#{@method}', which was requested for attribute '#{@attribute}'. Add this method to your adapter to support this filter operator.
|
40
40
|
MSG
|
41
41
|
end
|
@@ -49,7 +49,7 @@ module Graphiti
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def message
|
52
|
-
|
52
|
+
<<~MSG
|
53
53
|
#{@parent_resource_class} sideload :#{@name} - #{@message}
|
54
54
|
MSG
|
55
55
|
end
|
@@ -78,7 +78,7 @@ module Graphiti
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def message
|
81
|
-
|
81
|
+
<<~MSG
|
82
82
|
#{@resource_class}: Tried to pass block to .#{@method_name}, which only accepts a method name.
|
83
83
|
MSG
|
84
84
|
end
|
@@ -90,7 +90,7 @@ module Graphiti
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def message
|
93
|
-
|
93
|
+
<<~MSG
|
94
94
|
#{@resource_class}: Tried to perform write operation. Writes are not supported for remote resources - hit the endpoint directly.
|
95
95
|
MSG
|
96
96
|
end
|
@@ -105,7 +105,7 @@ module Graphiti
|
|
105
105
|
end
|
106
106
|
|
107
107
|
def message
|
108
|
-
|
108
|
+
<<~MSG
|
109
109
|
#{@resource.class}: Tried to filter #{@filter_name.inspect} on operator #{@operator.inspect}, but not supported! Supported operators are #{@supported}.
|
110
110
|
MSG
|
111
111
|
end
|
@@ -118,7 +118,7 @@ module Graphiti
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def message
|
121
|
-
|
121
|
+
<<~MSG
|
122
122
|
#{@sideload.parent_resource.class.name}: tried to sideload #{@sideload.name.inspect}, but more than one #{@sideload.parent_resource.model.name} was passed!
|
123
123
|
|
124
124
|
This is because you marked the sideload #{@sideload.name.inspect} with single: true
|
@@ -139,7 +139,7 @@ module Graphiti
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def message
|
142
|
-
|
142
|
+
<<~MSG
|
143
143
|
#{@resource.class.name}: tried to sort on attribute #{@attribute.inspect}, but passed #{@direction.inspect} when only #{@allowlist.inspect} is supported.
|
144
144
|
MSG
|
145
145
|
end
|
@@ -152,7 +152,7 @@ module Graphiti
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def message
|
155
|
-
|
155
|
+
<<~MSG
|
156
156
|
#{@resource_class.name}: called .on_extra_attribute #{@name.inspect}, but extra attribute #{@name.inspect} does not exist!
|
157
157
|
MSG
|
158
158
|
end
|
@@ -173,7 +173,7 @@ module Graphiti
|
|
173
173
|
else
|
174
174
|
"value #{@value.inspect}"
|
175
175
|
end
|
176
|
-
msg =
|
176
|
+
msg = <<~MSG
|
177
177
|
#{@resource.class.name}: tried to filter on #{@filter.keys[0].inspect}, but passed invalid #{value_string}.
|
178
178
|
MSG
|
179
179
|
msg << "\nAllowlist: #{allow.inspect}" if allow
|
@@ -190,7 +190,7 @@ module Graphiti
|
|
190
190
|
end
|
191
191
|
|
192
192
|
def message
|
193
|
-
|
193
|
+
<<~MSG
|
194
194
|
#{@resource_class.name} You declared an attribute or filter of type "#{@enum_type}" without providing a list of permitted values, which is required.
|
195
195
|
|
196
196
|
When declaring an attribute:
|
@@ -214,7 +214,7 @@ module Graphiti
|
|
214
214
|
end
|
215
215
|
|
216
216
|
def message
|
217
|
-
|
217
|
+
<<~MSG
|
218
218
|
#{@resource_class.name}: Cannot link to sideload #{@sideload.name.inspect}!
|
219
219
|
|
220
220
|
Make sure the endpoint "#{@sideload.resource.endpoint[:full_path]}" exists with action #{@action.inspect}, or customize the endpoint for #{@sideload.resource.class.name}.
|
@@ -733,6 +733,12 @@ module Graphiti
|
|
733
733
|
end
|
734
734
|
end
|
735
735
|
|
736
|
+
class UnsupportedBeforeCursor < Base
|
737
|
+
def message
|
738
|
+
"Passing in page[before] and page[number] is not supported. Please create an issue if you need it!"
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
736
742
|
class InvalidInclude < Base
|
737
743
|
def initialize(resource, relationship)
|
738
744
|
@resource = resource
|
@@ -13,7 +13,7 @@ module Graphiti
|
|
13
13
|
# Common interface for jsonapi-rb extensions
|
14
14
|
def as_jsonapi(*)
|
15
15
|
super.tap do |hash|
|
16
|
-
if (temp_id = @object.instance_variable_get(
|
16
|
+
if (temp_id = @object.instance_variable_get(:@_jsonapi_temp_id))
|
17
17
|
hash[:'temp-id'] = temp_id
|
18
18
|
end
|
19
19
|
end
|