apollo_upload_server 2.0.0.alpha.1 → 2.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of apollo_upload_server might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56d9a1cede8b8618901f4b4ebf80557c2676fe18
4
- data.tar.gz: 07b2468de665b6c48e42f50c682c98a01bb547e6
3
+ metadata.gz: 1f4d76e5ca733dd6fa8bd2ebc54dbfc355bd6588
4
+ data.tar.gz: 90cfc63714bac37890f794821f7abfec4cf099fa
5
5
  SHA512:
6
- metadata.gz: fc9d2bdefd35a214560ffa68781eac2b7129c2658b32494fe89adbe869c5fbc6c19fa2a94c3ce5f2bfa86a5aae1e9a4af80d67d69061627a5c43623d7b803de8
7
- data.tar.gz: 2b796b2080b4feb1dd0676f47f71b3fda31635e59e7add4b641ed1c6ec5f3f8a39d1deae2c422eb3bc39fcd7ef3f337f155cacf5e1fa59c05ee0504130469495
6
+ metadata.gz: 7671994289526ee7330d52ee47e1cf5a901394fa72d451059df80c3307d688a2c9f1452f5cf276b66f96f062f8a42c169fae7cf8d9b5d325640eb05af930b456
7
+ data.tar.gz: f4e457e5e4d6c89a2d741c7f5294d2525df2fbb0d4650bb675b0fa75a37a97dc95e3f01cff35d6fe65f4d351969ca33dfffe7cae2e5468bf7b87a296554da1ae
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apollo_upload_server (2.0.0.alpha.1)
4
+ apollo_upload_server (2.0.0.alpha.2)
5
5
  graphql (~> 1.7)
6
6
  rails (~> 5.0)
7
7
 
data/README.md CHANGED
@@ -9,7 +9,7 @@ use [version 1.0.0](https://github.com/jetruby/apollo_upload_server-ruby/tree/1.
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'apollo_upload_server'
12
+ gem 'apollo_upload_server', '2.0.0.alpha.1'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -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
- single_operation = operations.is_a?(Hash)
11
- file_mapper.to_a.each do |file_index, paths|
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
- else
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
- single_operation ? [operations] : operations
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
- if env['CONTENT_TYPE'].to_s.include?('multipart/form-data') && request.params['operations'].present? && request.params['map'].present?
12
- request.update_param('_json', GraphQLDataBuilder.new.call(request.params))
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)
@@ -1,3 +1,3 @@
1
1
  module ApolloUploadServer
2
- VERSION = '2.0.0.alpha.1'.freeze
2
+ VERSION = '2.0.0.alpha.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo_upload_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha.1
4
+ version: 2.0.0.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JetRuby