graphql_grpc 0.1.6 → 0.1.7

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
- SHA256:
3
- metadata.gz: 593b582c7e454dbcf1849b16d5daa512c4abfa7d3d9b04d151a870725085733a
4
- data.tar.gz: 17b255ab2f960b8ec6732896be4040284079ddf0f5d8ad8cca9b9740b418fdae
2
+ SHA1:
3
+ metadata.gz: 0efccd3cccd29bee78a1fbb8ecd4bcdf284adec9
4
+ data.tar.gz: 387a5b92c9340125a2a55c7285893b03923d8908
5
5
  SHA512:
6
- metadata.gz: c29bd0da85d80e02ad9152461751ad67f744b16b2636253d4fc13c5e8929b62b01c5a6b9964139d644ee04145d3b55ed6f3f2cb8b3360ce2be4f66813a0f763a
7
- data.tar.gz: 2fd992ef70fa8ca9fa56bdc36795605f9fcd88a4b029bf3d1797d4add4116bb105dccb434ec612b5b536236cd32ebb673a67c793c2de28e9d0910690db866bba
6
+ metadata.gz: 8bd721c5f59eecdde11f37e968022a26b67d9de207598c885900c4135d8044d2ad489f0e71531e32c4a71640ff273cdd32f8639757bb0ecb7e2cf51d3f78c14a
7
+ data.tar.gz: 39d04021b1376ca2dfe9af9293a042311c221570d5d8bb3d058378b62b16208fb360221c6acbb76f2b3d196a9adb14ffef13ff98666005ed8d6c64ea48dafa5c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_grpc (0.1.6)
4
+ graphql_grpc (0.1.7)
5
5
  activesupport
6
6
  graphql
7
7
  grpc
@@ -164,4 +164,4 @@ DEPENDENCIES
164
164
  wirble
165
165
 
166
166
  BUNDLED WITH
167
- 1.16.2
167
+ 1.17.3
@@ -39,7 +39,7 @@ module GraphqlGrpc
39
39
  input.map { |i| arrayify_hashes(i) }
40
40
  when :Hash
41
41
  input_types = input.keys.map(&:class).compact.sort.uniq
42
- if input_types.inject(true) { |tf, val| val.ancestors.include?(Integer) && tf }
42
+ if input_types.inject(true) { |tf, val| val.ancestors.include?(numeric_klass) && tf }
43
43
  arr = input.to_a.map { |e| { key: e.first, value: e.last } }
44
44
  arrayify_hashes(arr)
45
45
  else
@@ -49,5 +49,11 @@ module GraphqlGrpc
49
49
  input
50
50
  end
51
51
  end
52
+
53
+ def numeric_klass
54
+ @numeric_klass ||= begin
55
+ Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0') ? Fixnum : Integer
56
+ end
57
+ end
52
58
  end
53
59
  end
@@ -60,7 +60,10 @@ module GraphqlGrpc
60
60
  end
61
61
 
62
62
  def output_type
63
- rpc_desc.output.to_s.split(':').last
63
+ out_type = begin
64
+ streaming? ? rpc_desc.output.type : rpc_desc.output
65
+ end.to_s.split(':').last
66
+ streaming? ? "[#{out_type}]" : out_type
64
67
  end
65
68
 
66
69
  def to_query_type
@@ -84,12 +87,23 @@ module GraphqlGrpc
84
87
 
85
88
  def call(params = {}, metadata = {})
86
89
  args = [name, arg(params || {}), metadata: metadata]
87
- result_hash = @service_stub.send(*args).to_hash
88
- arrayify_hashes(result_hash)
90
+ arrayify_hashes normalize_result @service_stub.send(*args)
89
91
  end
90
92
 
91
93
  private
92
94
 
95
+ def normalize_result(result)
96
+ if result.is_a?(Enumerator)
97
+ [].tap { |arr| result.each { |e| arr << e } }
98
+ else
99
+ result.to_hash
100
+ end
101
+ end
102
+
103
+ def streaming?
104
+ rpc_desc.output.is_a?(GRPC::RpcDesc::Stream)
105
+ end
106
+
93
107
  # Build arguments to a func
94
108
  def arg(params)
95
109
  rpc_desc.input.decode_json(params.reject { |k, _v| k == :selections }.to_json)
@@ -8,7 +8,8 @@ module GraphqlGrpc
8
8
 
9
9
  def call(_type, field, obj, args, ctx)
10
10
  if obj
11
- value = obj[field.name.to_sym]
11
+ field_sym = field.name.to_sym
12
+ value = obj.try(field_sym) || obj[field_sym]
12
13
  return value.is_a?(Symbol) ? value.to_s : value
13
14
  end
14
15
  proxy.invoke(field, args, ctx)
@@ -37,20 +37,18 @@ module GraphqlGrpc
37
37
  end
38
38
 
39
39
  def gql_mutations
40
- @function_map.reject do |name_sym, rpc_desc|
41
- query?(name_sym, rpc_desc) || streaming_response?(rpc_desc)
42
- end
40
+ @function_map.reject { |name_sym, rpc_desc| query?(name_sym, rpc_desc) }
43
41
  end
44
42
 
45
43
  def gql_queries
46
- @function_map.select do |name_sym, rpc_desc|
47
- query?(name_sym, rpc_desc) && !streaming_response?(rpc_desc)
48
- end
44
+ @function_map.select { |name_sym, rpc_desc| query?(name_sym, rpc_desc) }
49
45
  end
50
46
 
51
47
  def to_schema_types
52
48
  function_output_types = @function_map.values.map do |function|
53
- function.rpc_desc.output
49
+ function.rpc_desc.output.is_a?(
50
+ GRPC::RpcDesc::Stream
51
+ ) ? function.rpc_desc.output.type : function.rpc_desc.output
54
52
  end.flatten.uniq
55
53
  output_types = TypeLibrary.new(function_output_types)
56
54
  function_input_types = @function_map.values.map do |function|
@@ -1,3 +1,3 @@
1
1
  module GraphqlGrpc
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_grpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zane Claes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-01-08 00:00:00.000000000 Z
12
+ date: 2019-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  requirements: []
217
217
  rubyforge_project:
218
- rubygems_version: 2.7.7
218
+ rubygems_version: 2.5.1
219
219
  signing_key:
220
220
  specification_version: 4
221
221
  summary: Gem for building GraphQL-to-gRPC gateways (usually using Ruby on Rails).