graphiti 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/gemfiles/rails_6.gemfile +1 -1
- data/lib/graphiti/errors.rb +22 -0
- data/lib/graphiti/scoping/default_filter.rb +1 -1
- data/lib/graphiti/scoping/filter.rb +1 -1
- data/lib/graphiti/scoping/paginate.rb +1 -1
- data/lib/graphiti/scoping/sort.rb +1 -1
- data/lib/graphiti/sideload/polymorphic_belongs_to.rb +9 -0
- data/lib/graphiti/util/relationship_payload.rb +1 -1
- data/lib/graphiti/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 501d03b06258694566979a6f54104d8da41a44ab6dadec078e7b84ef047de364
|
4
|
+
data.tar.gz: cb85e65ffb73f9294cd0173eee9a0f2e8239697dac1a83adbe58a2faf9c6cbe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 917d60f26882a2efbcebcf80279aa624b795628d6ad6fdc201dd8c4511e3a7caf6979fbf24c870aa176827dfe7daeffef0a1b5e5e73cec8d83bec98761ad1a9f
|
7
|
+
data.tar.gz: 1028dc0fe60eb8b4b54f119ccb12308390ff849c48047f6597e4149dbf6123aae296299d231fde9fa3469c023d7caa86b9e5ce334dc079547932ba886512e38e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.0.3
|
2
|
+
|
3
|
+
Fixes:
|
4
|
+
|
5
|
+
- [#130](https://github.com/graphiti-api/graphiti/pull/130) Run query
|
6
|
+
blocks in resource context.
|
7
|
+
|
1
8
|
## 1.0.2
|
2
9
|
|
3
10
|
Fixes:
|
@@ -13,6 +20,11 @@ Fixes:
|
|
13
20
|
|
14
21
|
### master (unreleased)
|
15
22
|
|
23
|
+
Misc:
|
24
|
+
|
25
|
+
- [#123](https://github.com/graphiti-api/graphiti/pull/123) Throw
|
26
|
+
better error when polymorphic type not found.
|
27
|
+
|
16
28
|
<!-- ### [version (YYYY-MM-DD)](diff_link) -->
|
17
29
|
<!-- Breaking changes:-->
|
18
30
|
<!-- Features:-->
|
data/gemfiles/rails_6.gemfile
CHANGED
data/lib/graphiti/errors.rb
CHANGED
@@ -561,6 +561,28 @@ module Graphiti
|
|
561
561
|
end
|
562
562
|
end
|
563
563
|
|
564
|
+
class PolymorphicSideloadTypeNotFound < Base
|
565
|
+
def initialize(sideload, name)
|
566
|
+
@sideload = sideload
|
567
|
+
@name = name
|
568
|
+
end
|
569
|
+
|
570
|
+
def message
|
571
|
+
<<~MSG
|
572
|
+
#{@sideload.parent_resource}: Tried to find a Resource with type '#{@name.inspect}', but did not find one!
|
573
|
+
|
574
|
+
This is because either a Resource with that type doesn't exist, or it's not registered on the sideload. The below example shows how to register a Resource with this sideload. Make sure one of the registered Resources has type '#{@name.inspect}'
|
575
|
+
|
576
|
+
polymorphic_belongs_to #{@sideload.name.inspect} do
|
577
|
+
group_by(#{@sideload.grouper.field_name.inspect}) do
|
578
|
+
on(:foo)
|
579
|
+
on(:foo).belongs_to :foo, resource: FooResource # (long-hand example)
|
580
|
+
end
|
581
|
+
end
|
582
|
+
MSG
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
564
586
|
class PolymorphicSideloadChildNotFound < Base
|
565
587
|
def initialize(sideload, name)
|
566
588
|
@sideload = sideload
|
@@ -38,7 +38,7 @@ module Graphiti
|
|
38
38
|
def apply
|
39
39
|
resource.default_filters.each_pair do |name, opts|
|
40
40
|
next if overridden?(name)
|
41
|
-
@scope =
|
41
|
+
@scope = resource.instance_exec(@scope, resource.context, &opts[:filter])
|
42
42
|
end
|
43
43
|
|
44
44
|
@scope
|
@@ -23,7 +23,7 @@ module Graphiti
|
|
23
23
|
|
24
24
|
def filter_scope(filter, operator, value)
|
25
25
|
if (custom_scope = filter.values[0][:operators][operator])
|
26
|
-
|
26
|
+
@resource.instance_exec(@scope, value, resource.context, &custom_scope)
|
27
27
|
else
|
28
28
|
filter_via_adapter(filter, operator, value)
|
29
29
|
end
|
@@ -99,6 +99,15 @@ class Graphiti::Sideload::PolymorphicBelongsTo < Graphiti::Sideload::BelongsTo
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
def child_for_type!(type)
|
103
|
+
if (child = child_for_type(type))
|
104
|
+
child
|
105
|
+
else
|
106
|
+
err = ::Graphiti::Errors::PolymorphicSideloadTypeNotFound
|
107
|
+
raise err.new(self, type)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
102
111
|
def resolve(parents, query, graph_parent)
|
103
112
|
parents.group_by(&grouper.field_name).each_pair do |group_name, group|
|
104
113
|
next if group_name.nil? || grouper.ignore?(group_name)
|
@@ -47,7 +47,7 @@ module Graphiti
|
|
47
47
|
|
48
48
|
# For polymorphic *sideloads*, grab the correct child sideload
|
49
49
|
if sideload.resource.type != type && sideload.type == :polymorphic_belongs_to
|
50
|
-
sideload = sideload.child_for_type(type)
|
50
|
+
sideload = sideload.child_for_type!(type)
|
51
51
|
end
|
52
52
|
|
53
53
|
# For polymorphic *resources*, grab the correct child resource
|
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.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Richmond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsonapi-serializable
|