graphql-query-resolver 0.1.2 → 0.2.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: 429a72429319c57704d27e0184b3b2e669395791
4
- data.tar.gz: 585ba11a9b7aeb30c936c56072bca5f0515e3852
3
+ metadata.gz: fe385f7548bf76fbe709841b30b4c8e4229179f5
4
+ data.tar.gz: 594ce130dac75e88001a3cd3808ab6506690e352
5
5
  SHA512:
6
- metadata.gz: 2f95bdb5bda299d7fc64a41ca438b4af5a19ce4afacb38cabafbf1357d859f238c43bc5a04e85ccb9f80650450b073fa8faf2a277d11781835c17ae5a045d1f9
7
- data.tar.gz: ebc1dc739958c988e0c0d99e2b5201b3988eb15ea5f158417f4558969eefba5d513c04b764dbb7b4ac9b43ddf0989d53af119135785c570e86c6735b5818a7ea
6
+ metadata.gz: f5d97a60410f4f09778bf85940f55e5cf4193629161b17fa81da0080acc445125b5347905824dcef48e095cdff5093ee921f876f1b6b6cd8e39373ea517b96d9
7
+ data.tar.gz: 81c5d0a41f415f28a51463404a986b13ea958a014beefb0ac1e39a7a8181f2badbcccf7908e0c6cfcd1a705ea8ccbb2a8502b2d72147d600db64b19043efb163
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .byebug_history
11
+ .idea
@@ -1,3 +1,6 @@
1
+ # 0.2.0
2
+ - Add support to Relay style pagination
3
+
1
4
  # 0.1.2
2
5
  - Acceptany version of graphql-ruby over 1.0.0
3
6
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # GraphQL::QueryResolver
2
2
  [![Build Status](https://travis-ci.org/nettofarah/graphql-query-resolver.svg?branch=master)](https://travis-ci.org/nettofarah/graphql-query-resolver)
3
3
 
4
- GraphQL::QueryResolver is an add-on to [graphql-ruby](https://github.com/rmosologo/graphql-ruby)
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.map_dependencies(class_name, ast_node)
26
- dependencies = {}
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 class_name.reflections.with_indifferent_access[selection.name].present?
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
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module QueryResolver
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.2
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-04-10 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql