apollo_fetch_upload_rails_middleware 0.2.0.alpha
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 +7 -0
- data/.gitignore +28 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/apollo_fetch_upload_rails_middleware.gemspec +28 -0
- data/lib/apollo_fetch_upload_rails_middleware/middleware.rb +73 -0
- data/lib/apollo_fetch_upload_rails_middleware/railtie.rb +7 -0
- data/lib/apollo_fetch_upload_rails_middleware/version.rb +3 -0
- data/lib/apollo_fetch_upload_rails_middleware.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c45b7a219023f114244d9d561288f5f073823f1
|
4
|
+
data.tar.gz: f8c9bf9b2f05f8b0eec9e9aeb732d84777c76eed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17fc13fdadcdfcf28f0f1447db947cc4534263f0730f347021717299634bc1949b16c3330b39562761946f30e3322e069e248db19ed39f3c989fcc336bf1afba
|
7
|
+
data.tar.gz: 0e38e114ec355ef32a44dc0fc6cd5aafe671e7af11240b7bd1b2fd8498b72d4cd097d9f0d163a6bafeadbfc6a34473d94d0a554b65eeba53f27ba3c578f4a0f2
|
data/.gitignore
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Ignore bundler config.
|
2
|
+
/.bundle
|
3
|
+
|
4
|
+
# Ignore all logfiles and tempfiles.
|
5
|
+
/log/*
|
6
|
+
/tmp/*
|
7
|
+
!/log/.keep
|
8
|
+
!/tmp/.keep
|
9
|
+
|
10
|
+
/node_modules
|
11
|
+
/yarn-error.log
|
12
|
+
|
13
|
+
.byebug_history
|
14
|
+
/public/packs
|
15
|
+
/public/packs-test
|
16
|
+
/node_modules
|
17
|
+
|
18
|
+
/vendor
|
19
|
+
|
20
|
+
# flow-typed
|
21
|
+
flow-typed/npm/*
|
22
|
+
|
23
|
+
# OS X
|
24
|
+
.DS_STORE
|
25
|
+
|
26
|
+
*~
|
27
|
+
|
28
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Abe Land
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# [Apollo Fetch Upload Rails Middleware](http://abe.land/ruby/rails/code/2017/11/05/rails-apollo-fetch-upload-middleware.html)
|
2
|
+
|
3
|
+
**NOTE: This does not support batching!**
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'apollo_fetch_upload_rails_middleware'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then do:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install apollo_fetch_upload_rails_middleware
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Using `Railtie`, this gem installs its middleware in your application. It will populate the GraphQL mutation inputs with the appropriate file metadata as described in the [apollo-fetch-upload](https://github.com/apollographql/apollo-fetch/tree/master/packages/apollo-fetch-upload) documentation.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/apollo_fetch_upload_rails_middleware.
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'apollo_fetch_upload_rails_middleware/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'apollo_fetch_upload_rails_middleware'
|
8
|
+
spec.version = ApolloFetchUploadRailsMiddleware::VERSION
|
9
|
+
spec.authors = ['Abe Land']
|
10
|
+
spec.email = ['abe@lostfoundlabs.com']
|
11
|
+
|
12
|
+
spec.summary = 'Rails middleware for using the apollo-fetch-upload npm package on the client.'
|
13
|
+
spec.homepage = 'https://github.com/abeland/apollo-fetch-upload-rails-middleware'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.add_dependency 'rails', '~> 5'
|
17
|
+
spec.required_ruby_version = '>= 2.2.2'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ApolloFetchUploadRailsMiddleware
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
request = Rack::Request.new(env)
|
9
|
+
if request.content_type.try(:start_with?, 'multipart/form-data') && request.params.key?('operations')
|
10
|
+
gql_operations = JSON.parse(request.params['operations'])
|
11
|
+
request.update_param('query', gql_operations['query'])
|
12
|
+
request.update_param('variables', gql_operations['variables'])
|
13
|
+
request.update_param('operationName', gql_operations['operationName'])
|
14
|
+
|
15
|
+
# Gather the param key/value pairs for which the values are File instances (sent as part
|
16
|
+
# of the Form POST from apollo fetch upload client-side middleware,
|
17
|
+
# cf. https://github.com/apollographql/apollo-fetch/blob/master/packages/apollo-fetch-upload/src/index.ts).
|
18
|
+
file_kv_pairs = []
|
19
|
+
request.params.each do |k, v|
|
20
|
+
next unless k.start_with?('variables.') &&
|
21
|
+
v.is_a?(Hash) &&
|
22
|
+
v.key?(:tempfile) &&
|
23
|
+
v[:tempfile].is_a?(Tempfile)
|
24
|
+
|
25
|
+
file_kv_pairs << [k, v]
|
26
|
+
end
|
27
|
+
|
28
|
+
variables_wrapper = ActiveSupport::HashWithIndifferentAccess.new(
|
29
|
+
variables: gql_operations['variables'],
|
30
|
+
)
|
31
|
+
|
32
|
+
file_kv_pairs.each do |kv_pair|
|
33
|
+
path, file = kv_pair
|
34
|
+
|
35
|
+
file_info = {
|
36
|
+
name: file[:filename],
|
37
|
+
path: file[:tempfile].path,
|
38
|
+
size: file[:tempfile].size,
|
39
|
+
type: file[:type],
|
40
|
+
}
|
41
|
+
|
42
|
+
pathset(
|
43
|
+
variables_wrapper,
|
44
|
+
path.split('.'), # path_components
|
45
|
+
file_info,
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
request.update_param('variables', variables_wrapper[:variables])
|
50
|
+
end
|
51
|
+
|
52
|
+
@app.call(env)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def pathset(h, path_components, val_h)
|
58
|
+
if path_components.blank?
|
59
|
+
h.merge!(val_h)
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
curr_path_component = path_components.shift
|
64
|
+
if h.key?(curr_path_component)
|
65
|
+
raise 'Invalid path' unless h[curr_path_component].is_a?(Hash)
|
66
|
+
else
|
67
|
+
h[curr_path_component] = {}
|
68
|
+
end
|
69
|
+
|
70
|
+
pathset(h[curr_path_component], path_components, val_h)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apollo_fetch_upload_rails_middleware
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abe Land
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- abe@lostfoundlabs.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- apollo_fetch_upload_rails_middleware.gemspec
|
68
|
+
- lib/apollo_fetch_upload_rails_middleware.rb
|
69
|
+
- lib/apollo_fetch_upload_rails_middleware/middleware.rb
|
70
|
+
- lib/apollo_fetch_upload_rails_middleware/railtie.rb
|
71
|
+
- lib/apollo_fetch_upload_rails_middleware/version.rb
|
72
|
+
homepage: https://github.com/abeland/apollo-fetch-upload-rails-middleware
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.2.2
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.1
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.11
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Rails middleware for using the apollo-fetch-upload npm package on the client.
|
96
|
+
test_files: []
|