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 +4 -4
- data/graphql-preload.gemspec +1 -1
- data/lib/graphql/preload.rb +29 -14
- data/lib/graphql/preload/instrument.rb +1 -1
- data/lib/graphql/preload/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e0801c09f14a8e25bea9216908d7c29630d0fed
|
4
|
+
data.tar.gz: 753658b77f8f47724fa6766d7d04eb3adeeae217
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ed1b226a6a001dc9ea50cfadae9deb18ae2e12a3c72ee2bc07e6cf3d257dfb89fbe34ee57a7819cac0fbdb77474a01a2b90055938013d539d39e654a6d88b6
|
7
|
+
data.tar.gz: cc8eb3fa1b2451b9a1e4309884c960df09daccdd1c34b30a573bf10f42d1f3519f1357044ad00044a2fd02634ab122f73aee66c7ef3126fd5ef9a90e8eaa1f11
|
data/graphql-preload.gemspec
CHANGED
@@ -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.
|
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
|
|
data/lib/graphql/preload.rb
CHANGED
@@ -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
|
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
|
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-
|
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.
|
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.
|
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.
|
192
|
+
rubygems_version: 2.2.2
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Preload ActiveRecord associations with graphql-batch
|