rgraphql_preload_ar 1.0.1
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 +7 -0
- data/.bundle/config +2 -0
- data/.gitignore +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +33 -0
- data/lib/optimized_function.rb +42 -0
- data/lib/rgraphql_preload_ar.rb +1 -0
- data/rgraphql_preload_ar.gemspec +10 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 85da4412626a54bc84c1577a5df3bf16de61fd25abf636df5121a20de20f6c46
|
4
|
+
data.tar.gz: ecd2ae2db4c700c13497b208138e6082916b673d5e19b4c2f2f82e461949081d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fea77dc3e607513ed37aa1b3325c9e1bd1686aae4549e97707a8d36bf63be29457e5e1f417ecb930ecd86ca02542f3c8fa1de853dc1ed50e73b4b0b5337e1dc7
|
7
|
+
data.tar.gz: 4eb399aa8388c9b451afee739c673100067c3c9ecc2a05ccfbc2d1af20d0a12603e9763c38f0e2c131212dd15fe7f7abfce759aade7860b31767aed5e87a2e73
|
data/.bundle/config
ADDED
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://gems.ruby-china.com/
|
3
|
+
specs:
|
4
|
+
activemodel (5.2.3)
|
5
|
+
activesupport (= 5.2.3)
|
6
|
+
activerecord (5.2.3)
|
7
|
+
activemodel (= 5.2.3)
|
8
|
+
activesupport (= 5.2.3)
|
9
|
+
arel (>= 9.0)
|
10
|
+
activesupport (5.2.3)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
arel (9.0.0)
|
16
|
+
concurrent-ruby (1.1.5)
|
17
|
+
graphql (1.9.4)
|
18
|
+
i18n (1.6.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
minitest (5.11.3)
|
21
|
+
thread_safe (0.3.6)
|
22
|
+
tzinfo (1.2.5)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
activerecord (~> 5.2.1)
|
30
|
+
graphql (>= 1.8.11)
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
2.0.1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'graphql'
|
2
|
+
class OptimizedFunction < GraphQL::Function
|
3
|
+
def call(obj, args, ctx)
|
4
|
+
@ctx = ctx
|
5
|
+
@json_tree = {}
|
6
|
+
@result_tree = {}
|
7
|
+
_call obj, args, ctx
|
8
|
+
end
|
9
|
+
|
10
|
+
def includes_kclass klass
|
11
|
+
@init_klass = klass
|
12
|
+
recursion query_tree
|
13
|
+
gen_result_tree klass
|
14
|
+
klass.includes @result_tree
|
15
|
+
end
|
16
|
+
|
17
|
+
def query_tree
|
18
|
+
@ctx.query.document.children.first.selections.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def recursion node, tree = @json_tree
|
22
|
+
tree[node.name.underscore.to_sym] = {}
|
23
|
+
node.selections.each do |n|
|
24
|
+
recursion n, tree[node.name.underscore.to_sym]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def really_json_tree
|
29
|
+
@json_tree.values.first
|
30
|
+
end
|
31
|
+
|
32
|
+
def gen_result_tree klass = @init_klass, tree = really_json_tree, result_tree = @result_tree
|
33
|
+
tree.each do |k, v|
|
34
|
+
if v.present? && klass.reflect_on_all_associations.map(&:name).include?(k)
|
35
|
+
result_tree[k.to_sym] = {}
|
36
|
+
_klass = klass.reflections[k.to_s].class_name.constantize
|
37
|
+
gen_result_tree _klass, tree[k], result_tree[k.to_sym]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'optimized_function'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rgraphql_preload_ar'
|
3
|
+
s.version = "1.0.1"
|
4
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
5
|
+
s.summary = %q{rails graphql preload ar in resolver}
|
6
|
+
s.files = `git ls-files`.split($/)
|
7
|
+
s.authors = ["tinyfeng.hou"]
|
8
|
+
s.license = 'MIT'
|
9
|
+
s.add_dependency "graphql", ">=1.8.11"
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rgraphql_preload_ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tinyfeng.hou
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphql
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.11
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.11
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".bundle/config"
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- lib/optimized_function.rb
|
38
|
+
- lib/rgraphql_preload_ar.rb
|
39
|
+
- rgraphql_preload_ar.gemspec
|
40
|
+
homepage:
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.7.8
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: rails graphql preload ar in resolver
|
64
|
+
test_files: []
|