apollo_upload_server 1.0.0 → 2.0.0.alpha.1

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: 013e8d44965539f6c6497711dd03d89bfcade844
4
- data.tar.gz: ff865ced6a90b5dbda49d9532146fe234147f3cf
3
+ metadata.gz: 56d9a1cede8b8618901f4b4ebf80557c2676fe18
4
+ data.tar.gz: 07b2468de665b6c48e42f50c682c98a01bb547e6
5
5
  SHA512:
6
- metadata.gz: 38cb39ad98899d62e66ef5062da999ae9205dc10e3fcf9a7ea7affb3430c2bb0dc8ff0de7d0ebecf460394a74201236ccc7a711f96b1d576c30580e140a91cec
7
- data.tar.gz: 7a25372d926e596e3658660edf053b3bd5e36e07083b57bf814e7942d798270fd26f6f3f4451932bd1b8fd7a039d1a3931e67791c3623dc257b44427ea06ba02
6
+ metadata.gz: fc9d2bdefd35a214560ffa68781eac2b7129c2658b32494fe89adbe869c5fbc6c19fa2a94c3ce5f2bfa86a5aae1e9a4af80d67d69061627a5c43623d7b803de8
7
+ data.tar.gz: 2b796b2080b4feb1dd0676f47f71b3fda31635e59e7add4b641ed1c6ec5f3f8a39d1deae2c422eb3bc39fcd7ef3f337f155cacf5e1fa59c05ee0504130469495
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apollo_upload_server (0.1.0)
4
+ apollo_upload_server (2.0.0.alpha.1)
5
5
  graphql (~> 1.7)
6
6
  rails (~> 5.0)
7
7
 
@@ -53,7 +53,7 @@ GEM
53
53
  erubi (1.7.0)
54
54
  globalid (0.4.1)
55
55
  activesupport (>= 4.2.0)
56
- graphql (1.7.7)
56
+ graphql (1.7.8)
57
57
  i18n (0.9.1)
58
58
  concurrent-ruby (~> 1.0)
59
59
  loofah (2.1.1)
@@ -64,8 +64,8 @@ GEM
64
64
  method_source (0.9.0)
65
65
  mini_mime (1.0.0)
66
66
  mini_portile2 (2.3.0)
67
- minitest (5.10.3)
68
- nio4r (2.1.0)
67
+ minitest (5.11.1)
68
+ nio4r (2.2.0)
69
69
  nokogiri (1.8.1)
70
70
  mini_portile2 (~> 2.3.0)
71
71
  rack (2.0.3)
@@ -99,7 +99,7 @@ GEM
99
99
  rspec-core (~> 3.7.0)
100
100
  rspec-expectations (~> 3.7.0)
101
101
  rspec-mocks (~> 3.7.0)
102
- rspec-core (3.7.0)
102
+ rspec-core (3.7.1)
103
103
  rspec-support (~> 3.7.0)
104
104
  rspec-expectations (3.7.0)
105
105
  diff-lcs (>= 1.2.0, < 2.0)
@@ -133,4 +133,4 @@ DEPENDENCIES
133
133
  rspec (~> 3.5)
134
134
 
135
135
  BUNDLED WITH
136
- 1.16.0
136
+ 1.16.1
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Middleware which allows you to upload files using [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), [apollo-upload-client](https://github.com/jaydenseric/apollo-upload-client) and Ruby on Rails.
4
4
 
5
- Note: this implementation uses [v1 of the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v1.0.0), so you should use apollo-upload-client library v5.1.1.
6
-
5
+ Note: this implementation uses [v2 of the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v2.0.0-alpha.2), so you should use apollo-upload-client library >= v7.0.0-alpha.3. If you need support for [v1 of the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v1.0.0), you must
6
+ use [version 1.0.0](https://github.com/jetruby/apollo_upload_server-ruby/tree/1.0.0) of this gem.
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
@@ -25,7 +25,7 @@ Middleware will be used automatically.
25
25
  Gem adds custom `Upload` type to your GraphQL types.
26
26
  Use `ApolloUploadServer::Upload` type for your file as input field:
27
27
  ```ruby
28
- input_field :file, !ApolloUploadServer::Upload
28
+ input_field :file, ApolloUploadServer::Upload
29
29
  ```
30
30
 
31
31
  That's all folks!
@@ -1,52 +1,35 @@
1
1
  require 'json'
2
- require 'active_support'
3
2
 
4
3
  module ApolloUploadServer
5
4
  class GraphQLDataBuilder
6
5
  def call(params)
7
- operations = begin
8
- JSON.parse(params['operations'])
9
- rescue JSON::ParserError
10
- nil
11
- end
12
- return unless operations.is_a?(Array)
6
+ operations = safe_json_parse(params['operations'])
7
+ file_mapper = safe_json_parse(params['map'])
13
8
 
14
- files = transform(convert_to_hash(select_files(params)))
15
- operations.zip(files).map do |data, file|
16
- if file.nil?
17
- data
18
- else
19
- data.deep_merge(file)
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|
12
+ paths.each do |path|
13
+ splited_path = path.split('.')
14
+ if single_operation
15
+ # splited_path => 'variables.input.profile_photo'; splited_path[0..-2] => ['variables', 'input']
16
+ # dig from first to penultimate key, and merge last key with value as file
17
+ operations.dig(*splited_path[0..-2]).merge!(splited_path.last => params[file_index])
18
+ else
19
+ # dig from second to penultimate key, and merge last key with value as file to operation with first key index
20
+ operations[splited_path.first.to_i].dig(*splited_path[1..-2]).merge!(splited_path.last => params[file_index])
21
+ end
20
22
  end
21
23
  end
24
+ single_operation ? [operations] : operations
22
25
  end
23
26
 
24
27
  private
25
28
 
26
- def select_files(params)
27
- params.select do |key, _value|
28
- key.include?('.variables') # && value.is_a?(ActionDispatch::Http::UploadedFile)
29
- end
30
- end
31
-
32
- def convert_to_hash(params)
33
- params.reduce({}) do |memo, (key, value)|
34
- memo.deep_merge(key.split('.').reverse.inject(value) { |hash, name| { name => hash } })
35
- end
36
- end
37
-
38
- def transform(hash)
39
- if hash.is_a?(Hash)
40
- if hash.keys.all? { |key| key.to_i.to_s == key }
41
- hash.keys.each_with_object([]) do |index, memo|
42
- memo[index.to_i] = transform(hash[index])
43
- end
44
- else
45
- hash.map { |k, v| [k, transform(v)] }.to_h
46
- end
47
- else
48
- hash
49
- end
29
+ def safe_json_parse(data)
30
+ JSON.parse(data)
31
+ rescue JSON::ParserError
32
+ nil
50
33
  end
51
34
  end
52
35
  end
@@ -8,8 +8,7 @@ module ApolloUploadServer
8
8
 
9
9
  def call(env)
10
10
  request = ActionDispatch::Request.new(env)
11
-
12
- if env['CONTENT_TYPE'].to_s.include?('multipart/form-data') && request.params['operations'].present?
11
+ if env['CONTENT_TYPE'].to_s.include?('multipart/form-data') && request.params['operations'].present? && request.params['map'].present?
13
12
  request.update_param('_json', GraphQLDataBuilder.new.call(request.params))
14
13
  end
15
14
 
@@ -1,3 +1,3 @@
1
1
  module ApolloUploadServer
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '2.0.0.alpha.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo_upload_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - JetRuby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-04 00:00:00.000000000 Z
11
+ date: 2018-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -121,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - ">="
124
+ - - ">"
125
125
  - !ruby/object:Gem::Version
126
- version: '0'
126
+ version: 1.3.1
127
127
  requirements: []
128
128
  rubyforge_project:
129
129
  rubygems_version: 2.6.11