graphql-association_batch_resolver 0.1.1 → 0.1.11
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/lib/graphql/association_batch_resolver/association_loader.rb +18 -13
- data/lib/graphql/association_batch_resolver/association_resolver.rb +1 -1
- data/lib/graphql/association_batch_resolver/column_aggregator.rb +2 -2
- data/lib/graphql/association_batch_resolver/column_aggregators/mysql_column_aggregator.rb +2 -2
- data/lib/graphql/association_batch_resolver/column_aggregators/postgres_column_aggregator.rb +1 -1
- data/lib/graphql/association_batch_resolver/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81c7c496fd558d2f36960ae703d3b785a59a843bfde46fbc8cd286a82c47a7e1
|
4
|
+
data.tar.gz: eeacd401c91ea7cc795d9d02d362a16d8eb07ed8f4a86e9096a0a23383fda773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0cb7ca2b4d67e15f175578bbe21ed20a57f1548eb7b2adc379606069950ac281b0293a77587696c84531a512f29ca7e44106186451c5d659935290c933ba044
|
7
|
+
data.tar.gz: 100dbcdc2189b2d55a17386ddcff89fc2410337a080335b4fcf2a377555b0211e0418ac97ff9f04a83151a2a4a777003b1b6b1fe5ea5b46b26c1672ed9db0f21
|
@@ -49,30 +49,35 @@ module GraphQL
|
|
49
49
|
raise ArgumentError, "No association #{association_name} on #{model}" unless association_exists
|
50
50
|
end
|
51
51
|
|
52
|
-
# rubocop:disable Metrics/AbcSize
|
53
52
|
def preload_association(records)
|
54
|
-
|
55
|
-
|
56
|
-
association_records = model.where(model_primary_key => records)
|
57
|
-
.joins(association_name)
|
58
|
-
.select(association_model.arel_table[Arel.star])
|
59
|
-
.select(select_model_primary_keys.as('model_primary_keys'))
|
60
|
-
.group(association_model.arel_table[association_primary_key])
|
61
|
-
|
53
|
+
association_records = associations_for(records)
|
62
54
|
association_records = options[:scope].call(association_records, context) if options[:scope].respond_to?(:call)
|
55
|
+
find_by_sql = association_records.to_sql
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
self.scope = if find_by_sql.present?
|
58
|
+
association_model.find_by_sql(find_by_sql).to_a
|
59
|
+
else
|
60
|
+
[]
|
61
|
+
end
|
67
62
|
end
|
68
63
|
|
64
|
+
# rubocop:disable Metrics/AbcSize
|
65
|
+
def associations_for(records)
|
66
|
+
select_model_primary_keys = ColumnAggregator.aggregate([model.arel_table[model_primary_key]])
|
67
|
+
self.scope = model.where(model_primary_key => records)
|
68
|
+
.joins(association_name)
|
69
|
+
.select(association_model.arel_table[Arel.star])
|
70
|
+
.select(select_model_primary_keys.as('model_primary_keys'))
|
71
|
+
.group(association_model.arel_table[association_primary_key])
|
72
|
+
end
|
69
73
|
# rubocop:enable Metrics/AbcSize
|
70
74
|
|
71
75
|
def read_association(model_record)
|
72
76
|
key = model_record.send(model_primary_key)
|
73
77
|
|
78
|
+
type = model.type_for_attribute(model_primary_key)
|
74
79
|
association_scope = scope.select do |association_record|
|
75
|
-
ColumnAggregator.deserialize(association_record.model_primary_keys).include?(key
|
80
|
+
ColumnAggregator.deserialize(association_record.model_primary_keys, type).include?(key)
|
76
81
|
end
|
77
82
|
|
78
83
|
is_collection ? association_scope : association_scope.first
|
@@ -34,7 +34,7 @@ module GraphQL
|
|
34
34
|
def initialize(*args, loader_class: GraphQL::AssociationBatchResolver.configuration.loader, **keywargs, &block)
|
35
35
|
super(*args, **keywargs, &block)
|
36
36
|
initialization_arguments = [model, association]
|
37
|
-
initialization_arguments << options if
|
37
|
+
initialization_arguments << options if options
|
38
38
|
|
39
39
|
@loader = loader_class.for(*initialization_arguments)
|
40
40
|
@loader.context = context if @loader.respond_to?(:context=)
|