graphql_preload_queries 0.2.0 → 0.2.1
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/CHANGELOG.md +9 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/README.md +16 -8
- data/config/initializers/add_preload_field.rb +1 -1
- data/lib/graphql_preload_queries/extensions/preload.rb +2 -2
- data/lib/graphql_preload_queries/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f78c5c6117d7157d648c6a1cdc325978bd74e0c8c068ab990be2e51817828923
|
4
|
+
data.tar.gz: 2228f1f4c97aa0a29aca63bac1303c425e4a12e1b128dcc9e2d858fbb5067da9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75f1393282b95a5f31202aae32634b042ef8ecd9bcf6bf947e3755fbc410994547177df7f3f924cf34b4d01298ae16da39ee216665b23ccf3de3f7460ad3d80
|
7
|
+
data.tar.gz: 772e252ce3c527b5326b0c504f50bc897076721f7f3bc76cd2debec645da9ea8269d81aa6d8d31491ef9d4b6cb4bd5682fe652c7de505227d7391969f867d491
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
## 0.2.1 (21-01-2021)
|
2
|
+
- fix: add default preload to key
|
3
|
+
- fix: fix invalid key when deep preloading
|
4
|
+
|
5
|
+
## 0.2.0 (02-12-2020)
|
6
|
+
- Refactor: Preload associations when iterating activeRecord::Relation
|
7
|
+
|
8
|
+
## 0.1.0 (10-11-2020
|
9
|
+
- Add rails query preload support for queries, mutations and gql object types.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,32 +15,40 @@ This gem helps you to define all nested preloads to be added when required for g
|
|
15
15
|
end
|
16
16
|
```
|
17
17
|
Examples:
|
18
|
-
* ```add_preload
|
18
|
+
* ```add_preload(:friends)```
|
19
19
|
```:friends``` association will be preloaded if query includes ```friends```, like: ```user(id: 10) { friends { ... } }```
|
20
20
|
|
21
|
-
* ```add_preload
|
21
|
+
* ```add_preload(:allFriends, :friends)```
|
22
22
|
```:friends``` association will be preloaded if query includes ```allFriends```, like: ```user(id: 10) { allFriends { ... } }```
|
23
23
|
|
24
|
-
* ```add_preload
|
24
|
+
* ```add_preload(:allFriends, { preload: :friends, parents: :parents })```
|
25
25
|
```:preload``` key can be used to indicate the association name when defining nested preloads, like: ```user(id: 10) { allFriends { id parents { ... } } }```
|
26
26
|
|
27
|
-
* ```add_preload
|
27
|
+
* ```add_preload(:friends, { allParents: :parents })```
|
28
28
|
(Nested 1 lvl preloading) ```friends: :parents``` association will be preloaded if query includes ```allParents```, like: ```user(id: 10) { friends { allParents { ... } } }```
|
29
29
|
|
30
|
-
* ```add_preload
|
30
|
+
* ```add_preload(:friends, { allParents: { preload: :parents, friends: :friends } })```
|
31
31
|
(Nested 2 levels preloading) ```friends: { parents: :friends }``` association will be preloaded if query includes ```friends``` inside ```parents```, like: ```user(id: 10) { friends { allParents { { friends { ... } } } } }```
|
32
32
|
|
33
|
-
* ```add_preload
|
33
|
+
* ```add_preload('friends|allFriends', :friends)```
|
34
34
|
(Multiple gql queries) ```:friends``` association will be preloaded if query includes ```friends``` or ```allFriends```, like: ```user(id: 10) { friends { ... } }``` OR ```user(id: 10) { allFriends { ... } }```
|
35
35
|
|
36
|
-
* ```add_preload
|
36
|
+
* ```add_preload('ignoredFriends', 'ignored_friends.user')```
|
37
37
|
(Deep preloading) ```{ ignored_friends: :user }``` association will be preloaded if query includes ```inogredFriends```, like: ```user(id: 10) { ignoredFriends { ... } }```
|
38
38
|
|
39
39
|
* Preloads in query results
|
40
40
|
```ruby
|
41
41
|
# queries/users.rb
|
42
42
|
def user(id:)
|
43
|
+
# includes all preloads defined in user type
|
44
|
+
# Sample: user(id: 10){ friends { id } }
|
45
|
+
# :friends will be preloaded inside "user" sql query
|
43
46
|
user = include_gql_preloads(:user, User.where(id: id))
|
47
|
+
|
48
|
+
# does not include user type preloads (only sub query preloads will be applied)
|
49
|
+
# Sample: user(id: 10){ friends { id parents { ... } } }
|
50
|
+
# Only :parents will be preloaded inside "friends" sql query
|
51
|
+
user = User.find(id)
|
44
52
|
end
|
45
53
|
```
|
46
54
|
- include_gql_preloads: Will preload all preloads configured in UserType based on the gql query.
|
@@ -53,7 +61,7 @@ This gem helps you to define all nested preloads to be added when required for g
|
|
53
61
|
def resolve(ids:)
|
54
62
|
affected_users = User.where(id: ids)
|
55
63
|
affected_users = include_gql_preloads(:users, affected_users)
|
56
|
-
puts affected_users.first&.friends
|
64
|
+
puts affected_users.first&.friends # will print preloaded friends data
|
57
65
|
{ users: affected_users }
|
58
66
|
end
|
59
67
|
```
|
@@ -22,7 +22,7 @@ Rails.application.config.to_prepare do
|
|
22
22
|
# add_preload(:allUsers, { preload: :users, 'allComments|comments' => :comments } })
|
23
23
|
## preload key can be omitted to use the same name as the key
|
24
24
|
# add_preload(:users, { 'allComments|comments' => :comments } })
|
25
|
-
def add_preload(key, preload)
|
25
|
+
def add_preload(key, preload = key)
|
26
26
|
preload ||= key
|
27
27
|
raise('Invalid preload query key') if [String, Symbol].exclude?(key.class)
|
28
28
|
raise('Invalid preload preload key') if [String, Symbol, Hash].exclude?(preload.class)
|
@@ -36,12 +36,12 @@ module GraphqlPreloadQueries
|
|
36
36
|
sub_node = sub_node(node, key)
|
37
37
|
multiple_preload = preload_conf.is_a?(Hash)
|
38
38
|
return unless sub_node
|
39
|
-
return add_preload_key(root, preload_conf,
|
39
|
+
return add_preload_key(root, preload_conf, {}) unless multiple_preload
|
40
40
|
|
41
41
|
child_root = nested_hash
|
42
42
|
association_name = preload_conf[:preload] || key.to_s.underscore
|
43
43
|
filter_preloads(sub_node, preload_conf, child_root)
|
44
|
-
add_preload_key(root, association_name, child_root.presence ||
|
44
|
+
add_preload_key(root, association_name, child_root.presence || {})
|
45
45
|
end
|
46
46
|
|
47
47
|
def sub_node(node, key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql_preload_queries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- owen2345
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- ".gitignore"
|
121
121
|
- ".rspec"
|
122
122
|
- ".rubocop.yml"
|
123
|
+
- CHANGELOG.md
|
123
124
|
- Gemfile
|
124
125
|
- Gemfile.lock
|
125
126
|
- MIT-LICENSE
|