apollo_upload_server 2.0.5 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28de01ef8ade8b660d60ba6f27c259e47d53d680ebd5271025f6943b0829ed6e
4
- data.tar.gz: 98879e0bb8bfe463b6174337eca9fe83269b7364e46642de3c067a198f2e9c07
3
+ metadata.gz: 295058d02fd7c1a31a61dd8e74d194637dd451404007bdc434d4488a314d92f1
4
+ data.tar.gz: f2473ad8f37131eb293ac05b6e98770cf516b2472c09bdeb97fe8cc2dd0df756
5
5
  SHA512:
6
- metadata.gz: 22ce039d4b7962fd6494476c22da5a9de0f97779798584d376e59564895efec81af01848abc190d68a08191980ed99df04490ef3f2949f95b9f15c82a7052f05
7
- data.tar.gz: 6902346ec482512cea834ada0acaafe8f3faf2e14bf150aa5459cfa82ccfc7d1c11d688bfaa6ee45f6dac72004b942bb4af600f48c050aa5fe3fb0cbb6ee080a
6
+ metadata.gz: be95ceec730a81dbdc9bc3ce9b1e0e3c95342cfb7ce9cdd0902bc3bf538ce693c8100964792773dc594bcb36ba7486d08e55fad4e11bc3d2eec0bc7057642a62
7
+ data.tar.gz: 5683e72d706155e0a69723d2423dcb36f5894b8824dd71d42efa83c0dc93c5d479d7a2f91b80a0a63737e974de1974fe0079f3bd3911650c279a43d4450a8da6
data/Gemfile.lock CHANGED
@@ -1,122 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- apollo_upload_server (2.0.0.beta.3)
4
+ apollo_upload_server (2.1.2)
5
+ activesupport (>= 7.0.3.1)
5
6
  graphql (>= 1.8)
6
- rails (>= 4.2)
7
+ rack (>= 2.2.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- actioncable (6.0.2.2)
12
- actionpack (= 6.0.2.2)
13
- nio4r (~> 2.0)
14
- websocket-driver (>= 0.6.1)
15
- actionmailbox (6.0.2.2)
16
- actionpack (= 6.0.2.2)
17
- activejob (= 6.0.2.2)
18
- activerecord (= 6.0.2.2)
19
- activestorage (= 6.0.2.2)
20
- activesupport (= 6.0.2.2)
21
- mail (>= 2.7.1)
22
- actionmailer (6.0.2.2)
23
- actionpack (= 6.0.2.2)
24
- actionview (= 6.0.2.2)
25
- activejob (= 6.0.2.2)
26
- mail (~> 2.5, >= 2.5.4)
27
- rails-dom-testing (~> 2.0)
28
- actionpack (6.0.2.2)
29
- actionview (= 6.0.2.2)
30
- activesupport (= 6.0.2.2)
31
- rack (~> 2.0, >= 2.0.8)
32
- rack-test (>= 0.6.3)
33
- rails-dom-testing (~> 2.0)
34
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
- actiontext (6.0.2.2)
36
- actionpack (= 6.0.2.2)
37
- activerecord (= 6.0.2.2)
38
- activestorage (= 6.0.2.2)
39
- activesupport (= 6.0.2.2)
40
- nokogiri (>= 1.8.5)
41
- actionview (6.0.2.2)
42
- activesupport (= 6.0.2.2)
43
- builder (~> 3.1)
44
- erubi (~> 1.4)
45
- rails-dom-testing (~> 2.0)
46
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
- activejob (6.0.2.2)
48
- activesupport (= 6.0.2.2)
49
- globalid (>= 0.3.6)
50
- activemodel (6.0.2.2)
51
- activesupport (= 6.0.2.2)
52
- activerecord (6.0.2.2)
53
- activemodel (= 6.0.2.2)
54
- activesupport (= 6.0.2.2)
55
- activestorage (6.0.2.2)
56
- actionpack (= 6.0.2.2)
57
- activejob (= 6.0.2.2)
58
- activerecord (= 6.0.2.2)
59
- marcel (~> 0.3.1)
60
- activesupport (6.0.2.2)
12
+ activesupport (7.0.3.1)
61
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
62
- i18n (>= 0.7, < 2)
63
- minitest (~> 5.1)
64
- tzinfo (~> 1.1)
65
- zeitwerk (~> 2.2)
66
- builder (3.2.4)
67
- concurrent-ruby (1.1.6)
68
- crass (1.0.6)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ concurrent-ruby (1.1.10)
69
18
  diff-lcs (1.3)
70
- erubi (1.9.0)
71
- globalid (0.4.2)
72
- activesupport (>= 4.2.0)
73
- graphql (1.8.13)
74
- i18n (1.8.2)
19
+ graphql (2.0.12)
20
+ i18n (1.12.0)
75
21
  concurrent-ruby (~> 1.0)
76
- loofah (2.4.0)
77
- crass (~> 1.0.2)
78
- nokogiri (>= 1.5.9)
79
- mail (2.7.1)
80
- mini_mime (>= 0.1.1)
81
- marcel (0.3.3)
82
- mimemagic (~> 0.3.2)
83
- method_source (1.0.0)
84
- mimemagic (0.3.4)
85
- mini_mime (1.0.2)
86
- mini_portile2 (2.4.0)
87
- minitest (5.14.0)
88
- nio4r (2.5.2)
89
- nokogiri (1.10.9)
90
- mini_portile2 (~> 2.4.0)
91
- rack (2.2.2)
92
- rack-test (1.1.0)
93
- rack (>= 1.0, < 3)
94
- rails (6.0.2.2)
95
- actioncable (= 6.0.2.2)
96
- actionmailbox (= 6.0.2.2)
97
- actionmailer (= 6.0.2.2)
98
- actionpack (= 6.0.2.2)
99
- actiontext (= 6.0.2.2)
100
- actionview (= 6.0.2.2)
101
- activejob (= 6.0.2.2)
102
- activemodel (= 6.0.2.2)
103
- activerecord (= 6.0.2.2)
104
- activestorage (= 6.0.2.2)
105
- activesupport (= 6.0.2.2)
106
- bundler (>= 1.3.0)
107
- railties (= 6.0.2.2)
108
- sprockets-rails (>= 2.0.0)
109
- rails-dom-testing (2.0.3)
110
- activesupport (>= 4.2.0)
111
- nokogiri (>= 1.6)
112
- rails-html-sanitizer (1.3.0)
113
- loofah (~> 2.3)
114
- railties (6.0.2.2)
115
- actionpack (= 6.0.2.2)
116
- activesupport (= 6.0.2.2)
117
- method_source
118
- rake (>= 0.8.7)
119
- thor (>= 0.20.3, < 2.0)
22
+ minitest (5.16.2)
23
+ rack (2.2.4)
120
24
  rake (13.0.1)
121
25
  rspec (3.8.0)
122
26
  rspec-core (~> 3.8.0)
@@ -131,21 +35,8 @@ GEM
131
35
  diff-lcs (>= 1.2.0, < 2.0)
132
36
  rspec-support (~> 3.8.0)
133
37
  rspec-support (3.8.0)
134
- sprockets (4.0.0)
38
+ tzinfo (2.0.5)
135
39
  concurrent-ruby (~> 1.0)
136
- rack (> 1, < 3)
137
- sprockets-rails (3.2.1)
138
- actionpack (>= 4.0)
139
- activesupport (>= 4.0)
140
- sprockets (>= 3.0.0)
141
- thor (1.0.1)
142
- thread_safe (0.3.6)
143
- tzinfo (1.2.6)
144
- thread_safe (~> 0.1)
145
- websocket-driver (0.7.1)
146
- websocket-extensions (>= 0.1.0)
147
- websocket-extensions (0.1.4)
148
- zeitwerk (2.3.0)
149
40
 
150
41
  PLATFORMS
151
42
  ruby
@@ -157,4 +48,4 @@ DEPENDENCIES
157
48
  rspec (~> 3.5)
158
49
 
159
50
  BUNDLED WITH
160
- 2.1.4
51
+ 2.3.17
data/README.md CHANGED
@@ -4,12 +4,13 @@ Middleware which allows you to upload files using [graphql-ruby](https://github.
4
4
 
5
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
6
  use [version 1.0.0](https://github.com/jetruby/apollo_upload_server-ruby/tree/1.0.0) of this gem.
7
+
7
8
  ## Installation
8
9
 
9
10
  Add this line to your application's Gemfile:
10
11
 
11
12
  ```ruby
12
- gem 'apollo_upload_server', '2.0.5'
13
+ gem 'apollo_upload_server', '2.1'
13
14
  ```
14
15
 
15
16
  And then execute:
@@ -24,12 +25,45 @@ Middleware will be used automatically.
24
25
 
25
26
  Gem adds custom `Upload` type to your GraphQL types.
26
27
  Use `ApolloUploadServer::Upload` type for your file as input field:
28
+
27
29
  ```ruby
28
30
  input_field :file, ApolloUploadServer::Upload
29
31
  ```
30
32
 
31
33
  That's all folks!
32
34
 
35
+ ## Configuration
36
+
37
+ The following configuration options are supported:
38
+
39
+ ### Strict Mode
40
+
41
+ This can be set on `ApolloUploadServer::Middleware`:
42
+
43
+ ```ruby
44
+ ApolloUploadServer::Middleware.strict_mode = true
45
+ ```
46
+
47
+ Doing so ensures that all mapped array values are present in the input. If this
48
+ is set to `true`, then for following request:
49
+
50
+ ```json
51
+ {
52
+ "operations": {
53
+ "query": "mutation { ... }",
54
+ "operationName": "SomeOperation",
55
+ "variables": {
56
+ "input": { "id": "123", "avatars": [null, null] }
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ A mapping for `variables.input.avatars.0` or `variables.input.avatars.1`, will work, but one for
63
+ `variables.input.avatars.100` will not, and will raise an error.
64
+
65
+ In strict mode, passing empty destination arrays will always fail.
66
+
33
67
  ## Contributing
34
68
 
35
69
  Bug reports and pull requests are welcome on GitHub at https://github.com/jetruby/apollo_upload_server-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -43,6 +77,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
43
77
  Everyone interacting in the ApolloUploadServer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jetruby/apollo_upload_server-ruby/blob/master/CODE_OF_CONDUCT.md).
44
78
 
45
79
  ## About JetRuby
80
+
46
81
  ApolloUploadServer is maintained and founded by JetRuby Agency.
47
82
 
48
83
  We love open source software!
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  end
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'actionpack', '>= 4.2'
21
+ spec.add_dependency 'rack', '>= 2.2.1'
22
22
  spec.add_dependency 'graphql', '>= 1.8'
23
+ spec.add_dependency 'activesupport', '>= 7.0.3.1'
23
24
 
24
25
  spec.add_development_dependency 'bundler', '~> 2.1'
25
26
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -5,6 +5,12 @@ require 'apollo_upload_server/wrappers/uploaded_file'
5
5
 
6
6
  module ApolloUploadServer
7
7
  class GraphQLDataBuilder
8
+ OutOfBounds = Class.new(ArgumentError)
9
+
10
+ def initialize(strict_mode: false)
11
+ @strict_mode = strict_mode
12
+ end
13
+
8
14
  def call(params)
9
15
  operations = safe_json_parse(params['operations'])
10
16
  file_mapper = safe_json_parse(params['map'])
@@ -36,17 +42,26 @@ module ApolloUploadServer
36
42
 
37
43
  def multiple_transformation(file_mapper, operations, params)
38
44
  operations = operations.dup
45
+
39
46
  file_mapper.each do |file_index, paths|
40
47
  paths.each do |path|
41
48
  splited_path = path.split('.')
42
49
  # dig from second to penultimate key, and merge last key with value as file to operation with first key index
43
50
  field = operations[splited_path.first.to_i].dig(*splited_path[1..-2])
51
+
44
52
  assign_file(field, splited_path, params[file_index])
45
53
  end
46
54
  end
47
55
  operations
48
56
  end
49
57
 
58
+ def verify_array_index!(path, index, size)
59
+ return unless @strict_mode
60
+ return if 0 <= index && index < size
61
+
62
+ raise OutOfBounds, "Path #{path.join('.')} maps to out-of-bounds index: #{index}"
63
+ end
64
+
50
65
  def safe_json_parse(data)
51
66
  JSON.parse(data)
52
67
  rescue JSON::ParserError
@@ -73,8 +88,18 @@ module ApolloUploadServer
73
88
  if field.is_a? Hash
74
89
  field.merge!(splited_path.last => wrapped_file)
75
90
  elsif field.is_a? Array
76
- field[splited_path.last.to_i] = wrapped_file
91
+ index = parse_array_index(splited_path)
92
+ verify_array_index!(splited_path, index, field.size)
93
+ field[index] = wrapped_file
77
94
  end
78
95
  end
96
+
97
+ def parse_array_index(path)
98
+ return path.last.to_i unless @strict_mode
99
+
100
+ Integer(path.last)
101
+ rescue ArgumentError
102
+ raise OutOfBounds, "Not a valid path to an array value: #{path.join('.')}"
103
+ end
79
104
  end
80
105
  end
@@ -1,7 +1,16 @@
1
1
  require 'apollo_upload_server/graphql_data_builder'
2
+ require "active_support/configurable"
3
+ require 'rack'
2
4
 
3
5
  module ApolloUploadServer
4
6
  class Middleware
7
+ include ActiveSupport::Configurable
8
+
9
+ # Strict mode requires that all mapped files are present in the mapping arrays.
10
+ config_accessor :strict_mode do
11
+ false
12
+ end
13
+
5
14
  def initialize(app)
6
15
  @app = app
7
16
  end
@@ -11,11 +20,11 @@ module ApolloUploadServer
11
20
  return @app.call(env)
12
21
  end
13
22
 
14
- request = ActionDispatch::Request.new(env)
23
+ request = Rack::Request.new(env)
15
24
  params = request.params
16
25
 
17
26
  if params['operations'].present? && params['map'].present?
18
- result = GraphQLDataBuilder.new.call(request.params)
27
+ result = GraphQLDataBuilder.new(strict_mode: self.class.strict_mode).call(request.params)
19
28
  result&.each do |key, value|
20
29
  request.update_param(key, value)
21
30
  end
@@ -1,3 +1,3 @@
1
1
  module ApolloUploadServer
2
- VERSION = '2.0.5'.freeze
2
+ VERSION = '2.1.2'.freeze
3
3
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'delegate'
4
- require 'action_dispatch/http/upload'
4
+ require 'rack'
5
5
 
6
6
  module ApolloUploadServer
7
7
  module Wrappers
8
- class UploadedFile < DelegateClass(::ActionDispatch::Http::UploadedFile)
8
+ class UploadedFile < DelegateClass(Rack::Multipart::UploadedFile)
9
9
  def initialize(wrapped_foo)
10
10
  super
11
11
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apollo_upload_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JetRuby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: actionpack
14
+ name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: 2.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: 2.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: graphql
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 7.0.3.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 7.0.3.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -125,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
139
  - !ruby/object:Gem::Version
126
140
  version: '0'
127
141
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.7.3
142
+ rubygems_version: 3.3.15
130
143
  signing_key:
131
144
  specification_version: 4
132
145
  summary: Middleware which allows you to upload files using graphql and multipart/form-data.