graphql-query-resolver 0.1.2 → 0.2.0
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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/lib/graphql/query_resolver.rb +25 -4
- data/lib/graphql/query_resolver/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe385f7548bf76fbe709841b30b4c8e4229179f5
|
4
|
+
data.tar.gz: 594ce130dac75e88001a3cd3808ab6506690e352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d97a60410f4f09778bf85940f55e5cf4193629161b17fa81da0080acc445125b5347905824dcef48e095cdff5093ee921f876f1b6b6cd8e39373ea517b96d9
|
7
|
+
data.tar.gz: 81c5d0a41f415f28a51463404a986b13ea958a014beefb0ac1e39a7a8181f2badbcccf7908e0c6cfcd1a705ea8ccbb2a8502b2d72147d600db64b19043efb163
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# GraphQL::QueryResolver
|
2
2
|
[](https://travis-ci.org/nettofarah/graphql-query-resolver)
|
3
3
|
|
4
|
-
GraphQL::QueryResolver is an add-on to [graphql-ruby](https://github.com/
|
4
|
+
GraphQL::QueryResolver is an add-on to [graphql-ruby](https://github.com/rmosolgo/graphql-ruby)
|
5
5
|
that allows your field resolvers to minimize N+1 SELECTS issued by ActiveRecord.
|
6
6
|
|
7
7
|
GraphQL::QueryResolver will analyze the AST from incoming GraphQL queries and
|
@@ -22,12 +22,34 @@ module GraphQL
|
|
22
22
|
to_load
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.
|
26
|
-
|
25
|
+
def self.using_relay_pagination?(selection)
|
26
|
+
selection.name == 'edges'
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.map_relay_pagination_depencies(class_name, selection, dependencies)
|
30
|
+
node_selection = selection.selections.find { |sel| sel.name == 'node' }
|
31
|
+
|
32
|
+
if node_selection.present?
|
33
|
+
map_dependencies(class_name, node_selection, dependencies)
|
34
|
+
else
|
35
|
+
dependencies
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.has_reflection_with_name?(class_name, selection_name)
|
40
|
+
class_name.reflections.with_indifferent_access[selection_name].present?
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.map_dependencies(class_name, ast_node, dependencies={})
|
27
44
|
ast_node.selections.each do |selection|
|
28
45
|
name = selection.name
|
29
46
|
|
30
|
-
if
|
47
|
+
if using_relay_pagination?(selection)
|
48
|
+
map_relay_pagination_depencies(class_name, selection, dependencies)
|
49
|
+
next
|
50
|
+
end
|
51
|
+
|
52
|
+
if has_reflection_with_name?(class_name, name)
|
31
53
|
begin
|
32
54
|
current_class_name = selection.name.singularize.classify.constantize
|
33
55
|
dependencies[name] = map_dependencies(current_class_name, selection)
|
@@ -35,7 +57,6 @@ module GraphQL
|
|
35
57
|
selection_name = class_name.reflections.with_indifferent_access[selection.name].options[:class_name]
|
36
58
|
current_class_name = selection_name.singularize.classify.constantize
|
37
59
|
dependencies[selection.name.to_sym] = map_dependencies(current_class_name, selection)
|
38
|
-
|
39
60
|
next
|
40
61
|
end
|
41
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-query-resolver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nettofarah
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|