graphql_includable 0.2.4 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6545a0cd3202a2d518e38696954b7797fd185684
4
- data.tar.gz: 484b44d89aacbc52585f73657646fd12cd770ef6
3
+ metadata.gz: 68ed67aff6a6c72245d963362927b0b158365688
4
+ data.tar.gz: 6b516166e7cb3ec68774b254fbcd0c9be873acc6
5
5
  SHA512:
6
- metadata.gz: 8c3562e409a36d572f2899d21317a382eacda8d0c8f5413f0faa37423a5161c83278b7182dd99146c1bc3be095bfddd5419fa3ae279056b50964f5a66407b900
7
- data.tar.gz: afe70bfba8d8f6459ff67301e44de68a5bcb66309ef9c293e803b8e77a6a05f05c5a812a2f55d99a56d2968d538f50a3d727c2011f1b6a47ca3b8e0aeba76922
6
+ metadata.gz: dc502e27199ca5db0f5a5e4d3880c1b91906ba5dd055a3532dd29098060f57dc06c88a27af7afcef9200ae3f6e03a3aa608c11fb6a29df652009b60ccf8a0fa4
7
+ data.tar.gz: f9f6ca1b322ad37b6b81cdeae850f62223cf474ab29ee1090737cb11682a6309f99236490847dbdfebfe98e11f926a8edc995839154b0d3cb26acf7f997cbcdb
@@ -1,11 +1,16 @@
1
1
  module GraphQLIncludable
2
2
  class Edge < GraphQL::Relay::Edge
3
3
  def edge
4
+ return @edge if @edge
4
5
  join_chain = joins_along_edge
5
6
  edge_class_name = join_chain.shift
6
7
  edge_class = str_to_class(edge_class_name)
7
8
 
8
9
  root_association_key = class_to_str(parent.class).to_sym
10
+ unless edge_class.reflections.keys.include?(root_association_key)
11
+ is_polymorphic = true
12
+ root_association_key = edge_class.reflections.select { |k, r| r.polymorphic? }.keys.first.to_sym
13
+ end
9
14
  root_node = { root_association_key => [parent] }
10
15
  terminal_node = { class_to_str(node.class) => node }
11
16
  join_chain.reverse.each do |rel_name|
@@ -15,7 +20,8 @@ module GraphQLIncludable
15
20
  search_hash = root_node.merge(terminal_node)
16
21
  edge_includes = join_chain.map { |s| s.to_s.singularize }
17
22
  edge_class = edge_class.includes(*edge_includes) unless edge_includes.empty?
18
- @edge ||= edge_class.joins(root_association_key).find_by(search_hash)
23
+ edge_class = edge_class.joins(root_association_key) unless is_polymorphic
24
+ @edge ||= edge_class.find_by(search_hash)
19
25
  end
20
26
 
21
27
  def method_missing(method_name, *args, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_includable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Rouse
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-04-09 00:00:00.000000000 Z
12
+ date: 2018-05-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: