hq-graphql 2.1.5 → 2.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 212005e9fc2e97777c5853273618ff5608c310db175324ac75a2e594cb3fa862
4
- data.tar.gz: 2b656d56fee16a199bc865370fcdaa4f3460414909b07b2086d9df82c56d2738
3
+ metadata.gz: 6bec5e8d7faf20cfc45c6420b0f989aee48ca2b5c6f72a3d2a9ff1d4be030530
4
+ data.tar.gz: 6d71560948e242279e32ec521a86c351e7c2278af78694581f5e1bf27b5807a5
5
5
  SHA512:
6
- metadata.gz: 65e69ef87752fcd9322b06001fb8bd5dd91e7e6e234c43738776681c96d333d7729d3de88118ac1e7829b24d2c139aa71cb3affb055def6a5a63a63af3379079
7
- data.tar.gz: 42016b3a7db045b5a768abb5217b9e68baf6b1d8b29e25b758f25c2c559190d2569671a297c0bf423518dae1f20130541904f87b74608105279a237a3677b8ad
6
+ metadata.gz: c62a8b032a5f43dd27c8a50685739cc6a07d21bab55a7b4a6dc750377080f9a3440c6954a129ef56c1c4bd60a90f4d390efae6937875d949c66a5b26b5ab918b
7
+ data.tar.gz: 40966a645c6777ee54311a8e8eb3f7df001413fdd91d1bcb21e1928c947299a331e69a18960fba6f0102996559f06c2dc56bdeb7ba611b5707b3f7830e61553d
@@ -77,6 +77,7 @@ require "hq/graphql/input_object"
77
77
  require "hq/graphql/mutation"
78
78
  require "hq/graphql/object"
79
79
  require "hq/graphql/paginated_association_loader"
80
+ require "hq/graphql/record_loader"
80
81
  require "hq/graphql/resource"
81
82
  require "hq/graphql/root_mutation"
82
83
  require "hq/graphql/root_query"
@@ -64,7 +64,6 @@ module HQ
64
64
 
65
65
  inside_scope = default_scope.
66
66
  select(inner_table[::Arel.star]).
67
- from(inner_table).
68
67
  where(lateral_join_table[target_join_key].eq(from_table[target_join_key])).
69
68
  reorder(arel_order(inner_table)).
70
69
  limit(@limit).
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HQ
4
+ module GraphQL
5
+ class RecordLoader < ::GraphQL::Batch::Loader
6
+ def initialize(model, column: model.primary_key, where: nil)
7
+ @model = model
8
+ @column = column.to_s
9
+ @column_type = model.type_for_attribute(@column)
10
+ @where = where
11
+ end
12
+
13
+ def load(key)
14
+ super(@column_type.cast(key))
15
+ end
16
+
17
+ def perform(keys)
18
+ query(keys).each { |record| fulfill(record.public_send(@column), record) }
19
+ keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
20
+ end
21
+
22
+ private
23
+
24
+ def query(keys)
25
+ scope = @model
26
+ scope = scope.where(@where) if @where
27
+ scope.where(@column => keys)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module HQ
4
4
  module GraphQL
5
- VERSION = "2.1.5"
5
+ VERSION = "2.1.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-08 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -264,6 +264,7 @@ files:
264
264
  - lib/hq/graphql/object.rb
265
265
  - lib/hq/graphql/object_association.rb
266
266
  - lib/hq/graphql/paginated_association_loader.rb
267
+ - lib/hq/graphql/record_loader.rb
267
268
  - lib/hq/graphql/resource.rb
268
269
  - lib/hq/graphql/resource/auto_mutation.rb
269
270
  - lib/hq/graphql/root_mutation.rb