apollo_upload_server 2.0.0.alpha.1 → 2.0.0.alpha.2
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.
Potentially problematic release.
This version of apollo_upload_server might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/apollo_upload_server/graphql_data_builder.rb +23 -8
- data/lib/apollo_upload_server/middleware.rb +7 -2
- data/lib/apollo_upload_server/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f4d76e5ca733dd6fa8bd2ebc54dbfc355bd6588
|
4
|
+
data.tar.gz: 90cfc63714bac37890f794821f7abfec4cf099fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7671994289526ee7330d52ee47e1cf5a901394fa72d451059df80c3307d688a2c9f1452f5cf276b66f96f062f8a42c169fae7cf8d9b5d325640eb05af930b456
|
7
|
+
data.tar.gz: f4e457e5e4d6c89a2d741c7f5294d2525df2fbb0d4650bb675b0fa75a37a97dc95e3f01cff35d6fe65f4d351969ca33dfffe7cae2e5468bf7b87a296554da1ae
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -7,25 +7,40 @@ module ApolloUploadServer
|
|
7
7
|
file_mapper = safe_json_parse(params['map'])
|
8
8
|
|
9
9
|
return nil if operations.nil? || file_mapper.nil?
|
10
|
-
|
11
|
-
|
10
|
+
if operations.is_a?(Hash)
|
11
|
+
single_transformation(file_mapper, operations, params)
|
12
|
+
else
|
13
|
+
{ '_json' => multiple_transformation(file_mapper, operations, params) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def single_transformation(file_mapper, operations, params)
|
20
|
+
operations = operations.dup
|
21
|
+
file_mapper.each do |file_index, paths|
|
12
22
|
paths.each do |path|
|
13
23
|
splited_path = path.split('.')
|
14
|
-
if single_operation
|
15
24
|
# splited_path => 'variables.input.profile_photo'; splited_path[0..-2] => ['variables', 'input']
|
16
25
|
# dig from first to penultimate key, and merge last key with value as file
|
17
26
|
operations.dig(*splited_path[0..-2]).merge!(splited_path.last => params[file_index])
|
18
|
-
|
27
|
+
end
|
28
|
+
end
|
29
|
+
operations
|
30
|
+
end
|
31
|
+
|
32
|
+
def multiple_transformation(file_mapper, operations, params)
|
33
|
+
operations = operations.dup
|
34
|
+
file_mapper.each do |file_index, paths|
|
35
|
+
paths.each do |path|
|
36
|
+
splited_path = path.split('.')
|
19
37
|
# dig from second to penultimate key, and merge last key with value as file to operation with first key index
|
20
38
|
operations[splited_path.first.to_i].dig(*splited_path[1..-2]).merge!(splited_path.last => params[file_index])
|
21
|
-
end
|
22
39
|
end
|
23
40
|
end
|
24
|
-
|
41
|
+
operations
|
25
42
|
end
|
26
43
|
|
27
|
-
private
|
28
|
-
|
29
44
|
def safe_json_parse(data)
|
30
45
|
JSON.parse(data)
|
31
46
|
rescue JSON::ParserError
|
@@ -8,8 +8,13 @@ module ApolloUploadServer
|
|
8
8
|
|
9
9
|
def call(env)
|
10
10
|
request = ActionDispatch::Request.new(env)
|
11
|
-
|
12
|
-
|
11
|
+
params = request.params
|
12
|
+
|
13
|
+
if env['CONTENT_TYPE'].to_s.include?('multipart/form-data') && params['operations'].present? && params['map'].present?
|
14
|
+
result = GraphQLDataBuilder.new.call(request.params)
|
15
|
+
result&.each do |key, value|
|
16
|
+
request.update_param(key, value)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
@app.call(env)
|