graphoid 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphoid/drivers/active_record.rb +20 -2
- data/lib/graphoid/drivers/mongoid.rb +13 -7
- data/lib/graphoid/queries/processor.rb +0 -4
- data/lib/graphoid/utils.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34f70b682b22f97dbe9d9f23cc51db8cb3e7ab30ce5b0ed545916a671f312601
|
4
|
+
data.tar.gz: ef6d309e4c7310c397aedfcba0b037a283b0b30675688c64b1455de78438e9db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cbfea735f3a72fd1b6842c914a1128eec1cc0e61982a565a179b57a4c5e49a25b0d24563a57f39ba9e72c7252b0f8b2fad42237361080b299c3529e1511126
|
7
|
+
data.tar.gz: e20edd2b6ade55cd0a26090945ff0a19794f8f4ebcd9c1636dddd5b9fcdfaeffe309aeb1b1d4a53221140851949f2bc35e3c212660c0b75490080d6ae58fecee
|
@@ -83,8 +83,26 @@ module Graphoid
|
|
83
83
|
relation.class
|
84
84
|
end
|
85
85
|
|
86
|
-
def
|
87
|
-
|
86
|
+
def generate_array(nodes)
|
87
|
+
include_array = []
|
88
|
+
nodes.each do |node|
|
89
|
+
children = node.selections.select!{ |n| !n.selections.empty? }
|
90
|
+
|
91
|
+
if children.empty?
|
92
|
+
include_array.push(node.name.to_sym)
|
93
|
+
else
|
94
|
+
include_array.push(node.name.to_sym => generate_array(children))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
include_array
|
99
|
+
end
|
100
|
+
|
101
|
+
def eager_load(selection, model)
|
102
|
+
nodes = selection.ast_node.selections.first.selections
|
103
|
+
nodes.select!{ |n| !n.selections.empty? }
|
104
|
+
include_array = generate_array(nodes)
|
105
|
+
include_array.empty? ? model : model.includes(*include_array)
|
88
106
|
end
|
89
107
|
|
90
108
|
def execute_and(scope, parsed)
|
@@ -114,7 +114,7 @@ module Graphoid
|
|
114
114
|
relation.relation
|
115
115
|
end
|
116
116
|
|
117
|
-
def eager_load(selection, model)
|
117
|
+
def eager_load(selection, model, first = true)
|
118
118
|
referenced_relations = [
|
119
119
|
mongo_constants[:many_to_many],
|
120
120
|
mongo_constants[:has_many],
|
@@ -122,21 +122,27 @@ module Graphoid
|
|
122
122
|
mongo_constants[:belongs_to]
|
123
123
|
]
|
124
124
|
|
125
|
-
properties =
|
125
|
+
properties = first ? Utils.first_children_of(selection) : Utils.children_of(selection)
|
126
126
|
inclusions = Utils.symbolize(properties)
|
127
127
|
|
128
128
|
Relation.relations_of(model).each do |name, relation|
|
129
129
|
name = relation.name
|
130
|
-
next if inclusions.exclude?(name) || referenced_relations.exclude?(
|
130
|
+
next if inclusions.exclude?(name) || referenced_relations.exclude?(relation.relation)
|
131
131
|
|
132
132
|
subselection = properties[name.to_s.camelize(:lower)]
|
133
|
-
|
134
|
-
|
133
|
+
subproperties = Utils.children_of(subselection)
|
134
|
+
subchildren = Utils.symbolize(subproperties)
|
135
|
+
subrelations = relation.class_name.constantize.relations.values.map(&:name)
|
135
136
|
|
136
|
-
if (
|
137
|
+
if (subrelations & subchildren).empty?
|
137
138
|
model = model.includes(name)
|
138
139
|
else
|
139
|
-
|
140
|
+
begin
|
141
|
+
gem "mongoid_includes"
|
142
|
+
model = model.includes(name, with: ->(instance) { eager_load(subselection, instance, false) })
|
143
|
+
rescue Gem::LoadError
|
144
|
+
model = model.includes(name)
|
145
|
+
end
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
data/lib/graphoid/utils.rb
CHANGED
@@ -17,7 +17,15 @@ module Graphoid
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def symbolize(fields)
|
20
|
-
fields.keys.map
|
20
|
+
fields.keys.map { |f| f.underscore.to_sym }
|
21
|
+
end
|
22
|
+
|
23
|
+
def children_of(selection)
|
24
|
+
selection.scoped_children.values.first
|
25
|
+
end
|
26
|
+
|
27
|
+
def first_children_of(selection)
|
28
|
+
selection.scoped_children.values.first.values.first.scoped_children.values.first
|
21
29
|
end
|
22
30
|
|
23
31
|
def underscore(props, fields = [])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maximiliano Perez Coto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|