graphql-preload 2.0.1 → 2.1.0

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
  SHA1:
3
- metadata.gz: ba8ef1cfb79ea9620cb392101e7ba7157bd19082
4
- data.tar.gz: 96f464f9f3534d0b46328036ffc4a68166037c4b
3
+ metadata.gz: 3e0801c09f14a8e25bea9216908d7c29630d0fed
4
+ data.tar.gz: 753658b77f8f47724fa6766d7d04eb3adeeae217
5
5
  SHA512:
6
- metadata.gz: f9d0e48b413c217329464a1410394d6602a454d434ab7bca8898ce16fcdddbc635bdd07de12a68f2461357b5f60de82a655fdcb997337b62b0e832d1178739f4
7
- data.tar.gz: e4e1738b221ce13f6e42c1841b752bbfa9b4e6d63308a3f6f93085fc9f55e2a8b09edd8f701192b7740e8ec6df7e26bc44a81772712a9c817edf6dc6d1c932c0
6
+ metadata.gz: 31ed1b226a6a001dc9ea50cfadae9deb18ae2e12a3c72ee2bc07e6cf3d257dfb89fbe34ee57a7819cac0fbdb77474a01a2b90055938013d539d39e654a6d88b6
7
+ data.tar.gz: cc8eb3fa1b2451b9a1e4309884c960df09daccdd1c34b30a573bf10f42d1f3519f1357044ad00044a2fd02634ab122f73aee66c7ef3126fd5ef9a90e8eaa1f11
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_runtime_dependency 'activerecord', '>= 4.1', '< 6'
25
- spec.add_runtime_dependency 'graphql', '>= 1.5', '< 2'
25
+ spec.add_runtime_dependency 'graphql', '>= 1.8', '< 2'
26
26
  spec.add_runtime_dependency 'graphql-batch', '~> 0.3'
27
27
  spec.add_runtime_dependency 'promise.rb', '~> 0.7'
28
28
 
@@ -2,25 +2,40 @@ require 'graphql'
2
2
  require 'graphql/batch'
3
3
  require 'promise.rb'
4
4
 
5
- GraphQL::Field.accepts_definitions(
6
- preload: ->(type, *args) do
7
- type.metadata[:preload] ||= []
8
- type.metadata[:preload].concat(args)
9
- end,
10
- preload_scope: ->(type, arg) { type.metadata[:preload_scope] = arg }
11
- )
12
-
13
- GraphQL::Schema.accepts_definitions(
14
- enable_preloading: ->(schema) do
15
- schema.instrument(:field, GraphQL::Preload::Instrument.new)
16
- end
17
- )
18
-
19
5
  module GraphQL
20
6
  # Provides a GraphQL::Field definition to preload ActiveRecord::Associations
21
7
  module Preload
22
8
  autoload :Instrument, 'graphql/preload/instrument'
23
9
  autoload :Loader, 'graphql/preload/loader'
24
10
  autoload :VERSION, 'graphql/preload/version'
11
+
12
+ module SchemaMethods
13
+ def enable_preloading
14
+ instrument(:field, GraphQL::Preload::Instrument.new)
15
+ end
16
+ end
17
+
18
+ module FieldMetadata
19
+ def initialize(*args, preload: nil, preload_scope: nil, **kwargs, &block)
20
+ if preload
21
+ @preload ||= []
22
+ @preload.concat Array.wrap preload
23
+ end
24
+ if preload_scope
25
+ @preload_scope = preload_scope
26
+ end
27
+ super(*args, **kwargs, &block)
28
+ end
29
+
30
+ def to_graphql
31
+ field_defn = super
32
+ field_defn.metadata[:preload] = @preload
33
+ field_defn.metadata[:preload_scope] = @preload_scope
34
+ field_defn
35
+ end
36
+ end
25
37
  end
38
+
39
+ Schema.extend Preload::SchemaMethods
40
+ Schema::Field.prepend Preload::FieldMetadata
26
41
  end
@@ -13,7 +13,7 @@ module GraphQL
13
13
  scope = field.metadata[:preload_scope].call(args, ctx)
14
14
  end
15
15
 
16
- preload(obj, field.metadata[:preload], scope).then do
16
+ preload(obj.object, field.metadata[:preload], scope).then do
17
17
  old_resolver.call(obj, args, ctx)
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Preload
3
- VERSION = '2.0.1'.freeze
3
+ VERSION = '2.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-preload
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Foster, Etienne Tripier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-21 00:00:00.000000000 Z
11
+ date: 2018-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.5'
39
+ version: '1.8'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '1.5'
49
+ version: '1.8'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2'
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  version: '0'
190
190
  requirements: []
191
191
  rubyforge_project:
192
- rubygems_version: 2.6.12
192
+ rubygems_version: 2.2.2
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Preload ActiveRecord associations with graphql-batch