graphql-association_batch_resolver 0.1.12 → 0.1.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a23219b3c789d167221ad14d6981d977bee1eff3513a2a8de84c5a4715b8c498
|
4
|
+
data.tar.gz: 934720af04c05bc719c456b4e6b150ac948b7004e5bfb62fdc4ebebd78dfc0e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d18d6db0d2524bb24d61fd198ec06330c8089d681ad5deb98575dacb721fdd0baef36af5d76c354e1113f0a5a9aad0410a0b5a206f641d7997029c82f39623ca
|
7
|
+
data.tar.gz: 15071ae109da7449ac17b62c6545928118ca26f55c6af1cca98459d2eafcdc81f70c316fdaa93ad2a1f40e27374e428a52e8bc4a46d72f4ab973896782f9514e
|
@@ -7,7 +7,7 @@ module GraphQL
|
|
7
7
|
class AssociationLoader < GraphQL::Batch::Loader
|
8
8
|
attr_reader :model, :model_primary_key, :association_name, :is_collection, :association_model,
|
9
9
|
:association_primary_key, :options
|
10
|
-
attr_accessor :scope, :context, :args
|
10
|
+
attr_accessor :scope, :context, :args, :bucket
|
11
11
|
|
12
12
|
def self.validate(model, association_name, options = {})
|
13
13
|
new(model, association_name, options)
|
@@ -50,6 +50,7 @@ module GraphQL
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def preload_association(records)
|
53
|
+
self.bucket = {}
|
53
54
|
association_records = associations_for(records)
|
54
55
|
association_records = options[:scope].call(association_records, context, *args) if options[:scope].respond_to?(:call)
|
55
56
|
find_by_sql = association_records.to_sql
|
@@ -59,6 +60,13 @@ module GraphQL
|
|
59
60
|
else
|
60
61
|
[]
|
61
62
|
end
|
63
|
+
type = model.type_for_attribute(model_primary_key)
|
64
|
+
scope.each do |record|
|
65
|
+
ColumnAggregator.deserialize(record.model_primary_keys, type).each do |primary_key|
|
66
|
+
bucket[primary_key] ||= []
|
67
|
+
bucket[primary_key] << record
|
68
|
+
end
|
69
|
+
end
|
62
70
|
end
|
63
71
|
|
64
72
|
# rubocop:disable Metrics/AbcSize
|
@@ -74,11 +82,7 @@ module GraphQL
|
|
74
82
|
|
75
83
|
def read_association(model_record)
|
76
84
|
key = model_record.send(model_primary_key)
|
77
|
-
|
78
|
-
type = model.type_for_attribute(model_primary_key)
|
79
|
-
association_scope = scope.select do |association_record|
|
80
|
-
ColumnAggregator.deserialize(association_record.model_primary_keys, type).include?(key)
|
81
|
-
end
|
85
|
+
association_scope = bucket[key] || []
|
82
86
|
|
83
87
|
is_collection ? association_scope : association_scope.first
|
84
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-association_batch_resolver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Derenge
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|