graphql_preload_queries 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc56d2e745351d747e3bf8d1950761271b0bafea51732bbff4bc88af59f7cc51
4
- data.tar.gz: 290fea98e4ef1b1f1d1d5ae94a07be35409b314a5c1ce7ca98b38580baffcbd0
3
+ metadata.gz: f78c5c6117d7157d648c6a1cdc325978bd74e0c8c068ab990be2e51817828923
4
+ data.tar.gz: 2228f1f4c97aa0a29aca63bac1303c425e4a12e1b128dcc9e2d858fbb5067da9
5
5
  SHA512:
6
- metadata.gz: f857c894b252512962d6488bc131b19e3b91b3ea89845d644604bd93aa4503f192673b1e45ef4f2619726d02e740d0e9086eed88c3142d7f2f4ab2cd1e0137b3
7
- data.tar.gz: 9a10333cf145142d5e57890da59a90f2fc4ea755a2c0e412e8269e531850b62f132e63e5fe0eb5ff064f85c70fc6d26ebea7164badd73ce4177c688b172877e8
6
+ metadata.gz: d75f1393282b95a5f31202aae32634b042ef8ecd9bcf6bf947e3755fbc410994547177df7f3f924cf34b4d01298ae16da39ee216665b23ccf3de3f7460ad3d80
7
+ data.tar.gz: 772e252ce3c527b5326b0c504f50bc897076721f7f3bc76cd2debec645da9ea8269d81aa6d8d31491ef9d4b6cb4bd5682fe652c7de505227d7391969f867d491
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ ruby '2.6.5'
3
4
  source 'https://rubygems.org'
4
5
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
6
 
@@ -190,5 +190,8 @@ DEPENDENCIES
190
190
  rubocop-rspec
191
191
  sqlite3
192
192
 
193
+ RUBY VERSION
194
+ ruby 2.6.5p114
195
+
193
196
  BUNDLED WITH
194
197
  2.1.4
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 :friends```
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 :allFriends, :friends```
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 :allFriends, { preload: :friends, parents: :parents }```
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 :friends, { allParents: :parents }```
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 :friends, { allParents: { preload: :parents, friends: :friends } }```
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 'friends|allFriends', :friends```
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 'ignoredFriends', 'ignored_friends.user'```
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, []) unless multiple_preload
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlPreloadQueries
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
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.0
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: 2020-12-02 00:00:00.000000000 Z
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