apollo_upload_server 0.1.0

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.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a353875709de43bf043b7f1b1b40ccb83b0c28f
4
+ data.tar.gz: 4a3acc66e09237ab0f5425e13405da6ca0ceb67a
5
+ SHA512:
6
+ metadata.gz: f84d0d25df29b84565a7f2a9275e4e49cce7eb57f0606c704753df1eaacf645402b21f3eb3f4af37d36cb3f70007c1931df05dae0fdb087ee1993b057fa5e106
7
+ data.tar.gz: 5f9203e764265cae48c1d11809c5222239a0f22728bac0bf605a18164ca4ee0dfeb6bb0037b93eda7f66d18bdff339f0b6051af56a11b10c16e66a0a0f9dec30
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ifuelen@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in apollo_upload_server.gemspec
6
+ gemspec
@@ -0,0 +1,136 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ apollo_upload_server (0.1.0)
5
+ graphql (~> 1.7)
6
+ rails (~> 5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.1.4)
12
+ actionpack (= 5.1.4)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.4)
16
+ actionpack (= 5.1.4)
17
+ actionview (= 5.1.4)
18
+ activejob (= 5.1.4)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.4)
22
+ actionview (= 5.1.4)
23
+ activesupport (= 5.1.4)
24
+ rack (~> 2.0)
25
+ rack-test (>= 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.4)
29
+ activesupport (= 5.1.4)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.4)
35
+ activesupport (= 5.1.4)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.4)
38
+ activesupport (= 5.1.4)
39
+ activerecord (5.1.4)
40
+ activemodel (= 5.1.4)
41
+ activesupport (= 5.1.4)
42
+ arel (~> 8.0)
43
+ activesupport (5.1.4)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ arel (8.0.0)
49
+ builder (3.2.3)
50
+ concurrent-ruby (1.0.5)
51
+ crass (1.0.3)
52
+ diff-lcs (1.3)
53
+ erubi (1.7.0)
54
+ globalid (0.4.1)
55
+ activesupport (>= 4.2.0)
56
+ graphql (1.7.7)
57
+ i18n (0.9.1)
58
+ concurrent-ruby (~> 1.0)
59
+ loofah (2.1.1)
60
+ crass (~> 1.0.2)
61
+ nokogiri (>= 1.5.9)
62
+ mail (2.7.0)
63
+ mini_mime (>= 0.1.1)
64
+ method_source (0.9.0)
65
+ mini_mime (1.0.0)
66
+ mini_portile2 (2.3.0)
67
+ minitest (5.10.3)
68
+ nio4r (2.1.0)
69
+ nokogiri (1.8.1)
70
+ mini_portile2 (~> 2.3.0)
71
+ rack (2.0.3)
72
+ rack-test (0.8.2)
73
+ rack (>= 1.0, < 3)
74
+ rails (5.1.4)
75
+ actioncable (= 5.1.4)
76
+ actionmailer (= 5.1.4)
77
+ actionpack (= 5.1.4)
78
+ actionview (= 5.1.4)
79
+ activejob (= 5.1.4)
80
+ activemodel (= 5.1.4)
81
+ activerecord (= 5.1.4)
82
+ activesupport (= 5.1.4)
83
+ bundler (>= 1.3.0)
84
+ railties (= 5.1.4)
85
+ sprockets-rails (>= 2.0.0)
86
+ rails-dom-testing (2.0.3)
87
+ activesupport (>= 4.2.0)
88
+ nokogiri (>= 1.6)
89
+ rails-html-sanitizer (1.0.3)
90
+ loofah (~> 2.0)
91
+ railties (5.1.4)
92
+ actionpack (= 5.1.4)
93
+ activesupport (= 5.1.4)
94
+ method_source
95
+ rake (>= 0.8.7)
96
+ thor (>= 0.18.1, < 2.0)
97
+ rake (10.5.0)
98
+ rspec (3.7.0)
99
+ rspec-core (~> 3.7.0)
100
+ rspec-expectations (~> 3.7.0)
101
+ rspec-mocks (~> 3.7.0)
102
+ rspec-core (3.7.0)
103
+ rspec-support (~> 3.7.0)
104
+ rspec-expectations (3.7.0)
105
+ diff-lcs (>= 1.2.0, < 2.0)
106
+ rspec-support (~> 3.7.0)
107
+ rspec-mocks (3.7.0)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.7.0)
110
+ rspec-support (3.7.0)
111
+ sprockets (3.7.1)
112
+ concurrent-ruby (~> 1.0)
113
+ rack (> 1, < 3)
114
+ sprockets-rails (3.2.1)
115
+ actionpack (>= 4.0)
116
+ activesupport (>= 4.0)
117
+ sprockets (>= 3.0.0)
118
+ thor (0.20.0)
119
+ thread_safe (0.3.6)
120
+ tzinfo (1.2.4)
121
+ thread_safe (~> 0.1)
122
+ websocket-driver (0.6.5)
123
+ websocket-extensions (>= 0.1.0)
124
+ websocket-extensions (0.1.3)
125
+
126
+ PLATFORMS
127
+ ruby
128
+
129
+ DEPENDENCIES
130
+ apollo_upload_server!
131
+ bundler (~> 1.16)
132
+ rake (~> 10.0)
133
+ rspec (~> 3.5)
134
+
135
+ BUNDLED WITH
136
+ 1.16.0
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Artur Plysyuk
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # ApolloUploadServer
2
+
3
+ Middleware which allows you to upload files using [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), [apoll-upload-client](https://github.com/jaydenseric/apollo-upload-client) and Ruby on Rails.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'apollo_upload_server'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install apollo_upload_server
20
+
21
+ Middleware will be used automatically.
22
+
23
+ Gem adds custom `Upload` type to your GraphQL types.
24
+ Use `ApolloUploadServer::Upload` type for your file as input field:
25
+ ```ruby
26
+ input_field :file, !ApolloUploadServer::Upload
27
+ ```
28
+
29
+ That's all folks!
30
+
31
+ ## Contributing
32
+
33
+ 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ 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).
42
+
43
+ ## About JetRuby
44
+ ApolloUploadServer is maintained and founded by JetRuby Agency.
45
+
46
+ We love open source software!
47
+ See [our projects][portfolio] or
48
+ [contact us][contact] to design, develop, and grow your product.
49
+
50
+ [portfolio]: http://jetruby.com/portfolio/
51
+ [contact]: http://jetruby.com/#contactUs
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'apollo_upload_server/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'apollo_upload_server'
7
+ spec.version = ApolloUploadServer::VERSION
8
+ spec.authors = ['JetRuby']
9
+ spec.email = ['engineering@jetruby.com']
10
+
11
+ spec.summary = 'Middleware which allows you to upload files using graphql and multipart/form-data.'
12
+ spec.description = 'apollo-upload-server implementation for Ruby on Rails as middleware.'
13
+ spec.homepage = 'https://github.com/jetruby/apollo_upload_server-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'rails', '~> 5.0'
24
+ spec.add_dependency 'graphql', '~> 1.7'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.5'
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'apollo_upload_server'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'apollo_upload_server/graphql_data_builder'
2
+ require 'apollo_upload_server/middleware'
3
+ require 'apollo_upload_server/version'
4
+ require 'apollo_upload_server/railtie'
5
+ require 'apollo_upload_server/upload'
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+ require 'active_support'
3
+
4
+ module ApolloUploadServer
5
+ class GraphQLDataBuilder
6
+ 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)
13
+
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)
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
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
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ require 'apollo_upload_server/graphql_data_builder'
2
+
3
+ module ApolloUploadServer
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ request = ActionDispatch::Request.new(env)
11
+
12
+ if env['CONTENT_TYPE'].to_s.include?('multipart/form-data') && request.params['operations'].present?
13
+ request.update_param('_json', GraphQLDataBuilder.new.call(request.params))
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ require 'apollo_upload_server/middleware'
2
+
3
+ module ApolloUploadServer
4
+ class Railtie < Rails::Railtie
5
+ initializer 'apollo_upload_server.apply_middleware' do |app|
6
+ app.middleware.use Middleware
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module ApolloUploadServer
2
+ Upload = GraphQL::ScalarType.define do
3
+ name 'Upload'
4
+
5
+ coerce_input ->(value, _ctx) { value }
6
+ coerce_result ->(value, _ctx) { value }
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ApolloUploadServer
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: apollo_upload_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JetRuby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-03 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: graphql
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ description: apollo-upload-server implementation for Ruby on Rails as middleware.
84
+ email:
85
+ - engineering@jetruby.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - apollo_upload_server.gemspec
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/apollo_upload_server.rb
104
+ - lib/apollo_upload_server/graphql_data_builder.rb
105
+ - lib/apollo_upload_server/middleware.rb
106
+ - lib/apollo_upload_server/railtie.rb
107
+ - lib/apollo_upload_server/upload.rb
108
+ - lib/apollo_upload_server/version.rb
109
+ homepage: https://github.com/jetruby/apollo_upload_server-ruby
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.11
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Middleware which allows you to upload files using graphql and multipart/form-data.
133
+ test_files: []