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 +5 -5
- data/Gemfile.lock +2 -2
- data/lib/graphql_grpc/arrayify.rb +7 -1
- data/lib/graphql_grpc/function.rb +17 -3
- data/lib/graphql_grpc/resolver.rb +2 -1
- data/lib/graphql_grpc/schema.rb +5 -7
- data/lib/graphql_grpc/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0efccd3cccd29bee78a1fbb8ecd4bcdf284adec9
|
4
|
+
data.tar.gz: 387a5b92c9340125a2a55c7285893b03923d8908
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bd721c5f59eecdde11f37e968022a26b67d9de207598c885900c4135d8044d2ad489f0e71531e32c4a71640ff273cdd32f8639757bb0ecb7e2cf51d3f78c14a
|
7
|
+
data.tar.gz: 39d04021b1376ca2dfe9af9293a042311c221570d5d8bb3d058378b62b16208fb360221c6acbb76f2b3d196a9adb14ffef13ff98666005ed8d6c64ea48dafa5c
|
data/Gemfile.lock
CHANGED
@@ -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?(
|
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
|
-
|
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
|
-
|
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
|
-
|
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)
|
data/lib/graphql_grpc/schema.rb
CHANGED
@@ -37,20 +37,18 @@ module GraphqlGrpc
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def gql_mutations
|
40
|
-
@function_map.reject
|
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
|
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|
|
data/lib/graphql_grpc/version.rb
CHANGED
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.
|
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-
|
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.
|
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).
|