artemis 0.9.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +17 -7
- data/Appraisals +15 -6
- data/CHANGELOG.md +32 -5
- data/Rakefile +1 -4
- data/artemis.gemspec +1 -2
- data/bin/console +3 -3
- data/gemfiles/graphql_2_0.gemfile +15 -0
- data/gemfiles/rails_60.gemfile +3 -3
- data/gemfiles/rails_71.gemfile +3 -3
- data/lib/artemis/railtie.rb +6 -8
- data/lib/artemis/version.rb +1 -1
- metadata +8 -37
- data/spec/adapters_spec.rb +0 -278
- data/spec/autoloading_spec.rb +0 -152
- data/spec/callbacks_spec.rb +0 -60
- data/spec/client_spec.rb +0 -228
- data/spec/endpoint_spec.rb +0 -49
- data/spec/fixtures/github/_repository_fields.graphql +0 -12
- data/spec/fixtures/github/repository.graphql +0 -6
- data/spec/fixtures/github/schema.json +0 -165225
- data/spec/fixtures/github/user.graphql +0 -6
- data/spec/fixtures/github/user_repositories.graphql +0 -13
- data/spec/fixtures/github.rb +0 -2
- data/spec/fixtures/responses/github/repository.yml +0 -17
- data/spec/fixtures/responses/github/user.json +0 -10
- data/spec/fixtures/responses/spotify_client/artist.yml +0 -5
- data/spec/spec_helper.rb +0 -49
- data/spec/test_helper_spec.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a7d1c38990ead32932786f4a3981d3e7a8db1914ffac704bd14fec1511e9a6
|
4
|
+
data.tar.gz: 6a3150492d60d3f94baff965a514b2392c0bdfc9c34d51cca540b7156cf4b1ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 594a2346bfc01cf7d8ca53c7359693f4e43e38dea0a5e65d36faf51851a55665839436078b7d1aaf6a20441edb949e24f0f406c0612928f00c850e552d4e829d
|
7
|
+
data.tar.gz: 9a19609908348342985afa0ef74e40133b1ea647fed58279b8c11efbc27e257e1086290932c3af2c0083c40cd0d5baa8b746929533c3d8f2a58d05ce1de4c0ab
|
data/.github/workflows/ruby.yml
CHANGED
@@ -2,18 +2,17 @@ name: build
|
|
2
2
|
|
3
3
|
on:
|
4
4
|
- push
|
5
|
-
- pull_request
|
6
5
|
|
7
6
|
jobs:
|
8
7
|
mri:
|
9
8
|
strategy:
|
10
9
|
matrix:
|
11
10
|
ruby_version:
|
11
|
+
- '3.3'
|
12
12
|
- '3.2'
|
13
13
|
- '3.1'
|
14
14
|
- '3.0'
|
15
15
|
- '2.7'
|
16
|
-
- '2.6'
|
17
16
|
gemfile:
|
18
17
|
- gemfiles/rails_71.gemfile
|
19
18
|
- gemfiles/rails_70.gemfile
|
@@ -22,7 +21,18 @@ jobs:
|
|
22
21
|
- gemfiles/rails_52.gemfile
|
23
22
|
- gemfiles/rails_51.gemfile
|
24
23
|
- gemfiles/rails_50.gemfile
|
24
|
+
- gemfiles/graphql_2_0.gemfile
|
25
25
|
exclude:
|
26
|
+
- ruby_version: '3.3'
|
27
|
+
gemfile: gemfiles/rails_61.gemfile
|
28
|
+
- ruby_version: '3.3'
|
29
|
+
gemfile: gemfiles/rails_60.gemfile
|
30
|
+
- ruby_version: '3.3'
|
31
|
+
gemfile: gemfiles/rails_52.gemfile
|
32
|
+
- ruby_version: '3.3'
|
33
|
+
gemfile: gemfiles/rails_51.gemfile
|
34
|
+
- ruby_version: '3.3'
|
35
|
+
gemfile: gemfiles/rails_50.gemfile
|
26
36
|
- ruby_version: '3.2'
|
27
37
|
gemfile: gemfiles/rails_61.gemfile
|
28
38
|
- ruby_version: '3.2'
|
@@ -49,6 +59,8 @@ jobs:
|
|
49
59
|
gemfile: gemfiles/rails_51.gemfile
|
50
60
|
- ruby_version: '3.0'
|
51
61
|
gemfile: gemfiles/rails_50.gemfile
|
62
|
+
- ruby_version: '3.0'
|
63
|
+
gemfile: gemfiles/graphql_2_0.gemfile
|
52
64
|
- ruby_version: '2.7'
|
53
65
|
gemfile: gemfiles/rails_71.gemfile
|
54
66
|
- ruby_version: '2.7'
|
@@ -57,10 +69,8 @@ jobs:
|
|
57
69
|
gemfile: gemfiles/rails_51.gemfile
|
58
70
|
- ruby_version: '2.7'
|
59
71
|
gemfile: gemfiles/rails_50.gemfile
|
60
|
-
- ruby_version: '2.
|
61
|
-
gemfile: gemfiles/
|
62
|
-
- ruby_version: '2.6'
|
63
|
-
gemfile: gemfiles/rails_70.gemfile
|
72
|
+
- ruby_version: '2.7'
|
73
|
+
gemfile: gemfiles/graphql_2_0.gemfile
|
64
74
|
runs-on: ubuntu-22.04
|
65
75
|
env:
|
66
76
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
@@ -88,7 +98,7 @@ jobs:
|
|
88
98
|
- name: Set up Ruby
|
89
99
|
uses: ruby/setup-ruby@v1
|
90
100
|
with:
|
91
|
-
ruby-version: 3.
|
101
|
+
ruby-version: 3.3
|
92
102
|
bundler-cache: true
|
93
103
|
- run: bundle exec rake || echo "Rails edge test is done."
|
94
104
|
|
data/Appraisals
CHANGED
@@ -8,10 +8,19 @@ appraise "rails_edge" do
|
|
8
8
|
gem "rackup"
|
9
9
|
end
|
10
10
|
|
11
|
+
appraise "graphql_2_0" do
|
12
|
+
gem "rails", '~> 7.1.0'
|
13
|
+
gem "railties", '~> 7.1.0'
|
14
|
+
gem "activesupport", '~> 7.1.0'
|
15
|
+
gem "rackup"
|
16
|
+
|
17
|
+
gem "graphql", "< 2.1"
|
18
|
+
end
|
19
|
+
|
11
20
|
appraise "rails_71" do
|
12
|
-
gem "rails", '~> 7.1.0
|
13
|
-
gem "railties", '~> 7.1.0
|
14
|
-
gem "activesupport", '~> 7.1.0
|
21
|
+
gem "rails", '~> 7.1.0'
|
22
|
+
gem "railties", '~> 7.1.0'
|
23
|
+
gem "activesupport", '~> 7.1.0'
|
15
24
|
gem "rackup"
|
16
25
|
end
|
17
26
|
|
@@ -28,9 +37,9 @@ appraise "rails_61" do
|
|
28
37
|
end
|
29
38
|
|
30
39
|
appraise "rails_60" do
|
31
|
-
gem "rails", '~> 6.0.0
|
32
|
-
gem "railties", '~> 6.0.0
|
33
|
-
gem "activesupport", '~> 6.0.0
|
40
|
+
gem "rails", '~> 6.0.0'
|
41
|
+
gem "railties", '~> 6.0.0'
|
42
|
+
gem "activesupport", '~> 6.0.0'
|
34
43
|
end
|
35
44
|
|
36
45
|
appraise "rails_52" do
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,40 @@
|
|
1
|
-
##
|
1
|
+
## v1.0.2
|
2
|
+
|
3
|
+
#### 🐞 Bug Fixes
|
4
|
+
|
5
|
+
- Fixes a bug where abstract client classes are not loaded correctly (#93, `494d30b`)
|
6
|
+
|
7
|
+
## v1.0.1
|
8
|
+
|
9
|
+
> Yanked due to inconsistent commit history.
|
10
|
+
|
11
|
+
## v1.0.0
|
12
|
+
|
13
|
+
#### 🚨 Breaking Changes
|
14
|
+
|
15
|
+
- Drop support for Ruby 2.6. For those of you looking to use Artemis on Ruby 2.6, please use the `artemis` version
|
16
|
+
`0.9.0` and the `graphql-client` version `0.17.0`.
|
17
|
+
|
18
|
+
#### ⭐️ New Features
|
19
|
+
|
20
|
+
- Add support for Ruby 3.3.
|
21
|
+
- Add support for the latest versinos of the `graphql` gem.
|
22
|
+
|
23
|
+
#### 🐞 Bug Fixes
|
24
|
+
|
25
|
+
- No bug fixes.
|
26
|
+
|
27
|
+
## [v0.9.0](https://github.com/yuki24/artemis/tree/v0.9.0)
|
28
|
+
|
29
|
+
_<sup>released at 2023-09-18 01:08:34 UTC</sup>_
|
2
30
|
|
3
31
|
#### New Features
|
4
32
|
|
5
|
-
- Rails 7.1.0.beta1 is now officially supported
|
33
|
+
- Rails 7.1.0.beta1 is now officially supported ([<tt>f25ba29</tt>](https://github.com/yuki24/artemis/commit/f25ba296f15b26ffba7e4ec0f5b4cbeb061c97a1))
|
6
34
|
|
7
35
|
#### Fixes
|
8
36
|
|
9
|
-
- Fixes an issue where `graphql` gem `2.1.0` may not work with `graphql-client` (
|
37
|
+
- Fixes an issue where `graphql` gem `2.1.0` may not work with `graphql-client` ([<tt>b144ee2</tt>](https://github.com/yuki24/artemis/commit/b144ee2fbca2c23b4aaed8236f6fc07f65d8239d))
|
10
38
|
|
11
39
|
## [v0.8.0](https://github.com/yuki24/artemis/tree/v0.8.0)
|
12
40
|
|
@@ -39,7 +67,6 @@ _<sup>released at 2021-09-03 04:17:55 UTC</sup>_
|
|
39
67
|
|
40
68
|
#### Fixes
|
41
69
|
|
42
|
-
- ~~Generate fixture YAML files on `rails g artemis:query queryName` ([#78](https://github.com/yuki24/artemis/pull/78))~~ Removed due to a bug for now.
|
43
70
|
- Address warnings from Ruby 2.7 ([<tt>408adcb</tt>](https://github.com/yuki24/artemis/commit/408adcb3f39912f7afb7b3690a52f1d593662b7b))
|
44
71
|
- Avoid crashing when config/graphql.yml does not exist ([@dlackty](https://github.com/dlackty), [#76](https://github.com/yuki24/artemis/pull/76))
|
45
72
|
|
@@ -107,5 +134,5 @@ _<sup>released at 2018-10-30 02:09:59 UTC</sup>_
|
|
107
134
|
|
108
135
|
_<sup>released at 2018-10-16 20:57:51 UTC</sup>_
|
109
136
|
|
110
|
-
First release of Artemis!
|
137
|
+
First release of Artemis! 🎉
|
111
138
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
|
-
require 'rspec/core/rake_task'
|
4
3
|
|
5
4
|
TESTS_IN_ISOLATION = ['test/railtie_test.rb', 'test/rake_tasks_test.rb']
|
6
5
|
|
@@ -16,6 +15,4 @@ Rake::TestTask.new('test:isolated') do |t|
|
|
16
15
|
t.warning = false
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
task default: ['spec', 'test', 'test:isolated']
|
18
|
+
task default: ['test', 'test:isolated']
|
data/artemis.gemspec
CHANGED
@@ -17,12 +17,11 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.add_dependency "activesupport", ">= 4.0.0"
|
19
19
|
spec.add_dependency "railties", ">= 4.0.0"
|
20
|
-
spec.add_dependency "graphql"
|
20
|
+
spec.add_dependency "graphql"
|
21
21
|
spec.add_dependency "graphql-client", ">= 0.13.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "appraisal", ">= 2.2"
|
24
24
|
spec.add_development_dependency "bundler", ">= 1.16"
|
25
25
|
spec.add_development_dependency "net-http-persistent", ">= 3.0"
|
26
26
|
spec.add_development_dependency "rake", ">= 10.0"
|
27
|
-
spec.add_development_dependency "rspec", ">= 3.8"
|
28
27
|
end
|
data/bin/console
CHANGED
@@ -4,9 +4,9 @@ require "bundler/setup"
|
|
4
4
|
require "artemis"
|
5
5
|
|
6
6
|
Artemis::Client.query_paths = [File.join(__dir__, '../spec/fixtures')]
|
7
|
-
Artemis::GraphQLEndpoint.register!(:
|
8
|
-
Artemis::GraphQLEndpoint.lookup(:
|
9
|
-
require_relative '../spec/fixtures/
|
7
|
+
Artemis::GraphQLEndpoint.register!(:github, adapter: :test, url: '', schema_path: 'spec/fixtures/github/schema.json')
|
8
|
+
Artemis::GraphQLEndpoint.lookup(:github).load_schema!
|
9
|
+
require_relative '../spec/fixtures/github'
|
10
10
|
|
11
11
|
require "pry"
|
12
12
|
Pry.start
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry"
|
6
|
+
gem "pry-byebug", platforms: :mri
|
7
|
+
gem "curb", ">= 0.9.6"
|
8
|
+
gem "webrick"
|
9
|
+
gem "rails", "~> 7.1.0"
|
10
|
+
gem "railties", "~> 7.1.0"
|
11
|
+
gem "activesupport", "~> 7.1.0"
|
12
|
+
gem "rackup"
|
13
|
+
gem "graphql", "< 2.1"
|
14
|
+
|
15
|
+
gemspec path: "../"
|
data/gemfiles/rails_60.gemfile
CHANGED
@@ -6,8 +6,8 @@ gem "pry"
|
|
6
6
|
gem "pry-byebug", platforms: :mri
|
7
7
|
gem "curb", ">= 0.9.6"
|
8
8
|
gem "webrick"
|
9
|
-
gem "rails", "~> 6.0.0
|
10
|
-
gem "railties", "~> 6.0.0
|
11
|
-
gem "activesupport", "~> 6.0.0
|
9
|
+
gem "rails", "~> 6.0.0"
|
10
|
+
gem "railties", "~> 6.0.0"
|
11
|
+
gem "activesupport", "~> 6.0.0"
|
12
12
|
|
13
13
|
gemspec path: "../"
|
data/gemfiles/rails_71.gemfile
CHANGED
@@ -6,9 +6,9 @@ gem "pry"
|
|
6
6
|
gem "pry-byebug", platforms: :mri
|
7
7
|
gem "curb", ">= 0.9.6"
|
8
8
|
gem "webrick"
|
9
|
-
gem "rails", "~> 7.1.0
|
10
|
-
gem "railties", "~> 7.1.0
|
11
|
-
gem "activesupport", "~> 7.1.0
|
9
|
+
gem "rails", "~> 7.1.0"
|
10
|
+
gem "railties", "~> 7.1.0"
|
11
|
+
gem "activesupport", "~> 7.1.0"
|
12
12
|
gem "rackup"
|
13
13
|
|
14
14
|
gemspec path: "../"
|
data/lib/artemis/railtie.rb
CHANGED
@@ -31,7 +31,9 @@ module Artemis
|
|
31
31
|
end
|
32
32
|
|
33
33
|
initializer 'graphql.client.set_reloader', after: 'graphql.client.set_query_paths' do |app|
|
34
|
-
|
34
|
+
not_on_zeitwerk = !defined?(Zeitwerk) || (app.config.respond_to?(:autoloader) && app.config.autoloader != :zeitwerk)
|
35
|
+
|
36
|
+
if not_on_zeitwerk
|
35
37
|
files_to_watch = Artemis::Client.query_paths.map {|path| [path, config.artemis.graphql_extentions] }.to_h
|
36
38
|
|
37
39
|
app.reloaders << ActiveSupport::FileUpdateChecker.new([], files_to_watch) do
|
@@ -58,14 +60,10 @@ module Artemis
|
|
58
60
|
end
|
59
61
|
|
60
62
|
initializer 'graphql.client.preload', after: 'graphql.client.load_config' do |app|
|
61
|
-
|
62
|
-
Artemis::GraphQLEndpoint.registered_services.each do |endpoint_name|
|
63
|
-
begin
|
64
|
-
require_dependency endpoint_name # Rails 7.0+ requires this.
|
65
|
-
rescue LoadError
|
66
|
-
# no-op...
|
67
|
-
end
|
63
|
+
not_on_zeitwerk = !defined?(Zeitwerk) || (app.config.respond_to?(:autoloader) && app.config.autoloader != :zeitwerk)
|
68
64
|
|
65
|
+
if app.config.eager_load && app.config.cache_classes && not_on_zeitwerk
|
66
|
+
Artemis::GraphQLEndpoint.registered_services.each do |endpoint_name|
|
69
67
|
endpoint_name.camelize.constantize.preload!
|
70
68
|
end
|
71
69
|
end
|
data/lib/artemis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artemis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Allured
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: graphql
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: graphql-client
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,20 +123,6 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '10.0'
|
126
|
-
- !ruby/object:Gem::Dependency
|
127
|
-
name: rspec
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
129
|
-
requirements:
|
130
|
-
- - ">="
|
131
|
-
- !ruby/object:Gem::Version
|
132
|
-
version: '3.8'
|
133
|
-
type: :development
|
134
|
-
prerelease: false
|
135
|
-
version_requirements: !ruby/object:Gem::Requirement
|
136
|
-
requirements:
|
137
|
-
- - ">="
|
138
|
-
- !ruby/object:Gem::Version
|
139
|
-
version: '3.8'
|
140
126
|
description: GraphQL client on Rails + Convention over Configuration = ❤️
|
141
127
|
email:
|
142
128
|
- jon.allured@gmail.com
|
@@ -162,6 +148,7 @@ files:
|
|
162
148
|
- doc/CHANGELOG.md.erb
|
163
149
|
- doc/changelog_generator.rb
|
164
150
|
- gemfiles/.bundle/config
|
151
|
+
- gemfiles/graphql_2_0.gemfile
|
165
152
|
- gemfiles/rails_50.gemfile
|
166
153
|
- gemfiles/rails_51.gemfile
|
167
154
|
- gemfiles/rails_52.gemfile
|
@@ -197,22 +184,6 @@ files:
|
|
197
184
|
- lib/generators/artemis/query/templates/fixture.yml
|
198
185
|
- lib/generators/artemis/query/templates/query.graphql
|
199
186
|
- lib/tasks/artemis.rake
|
200
|
-
- spec/adapters_spec.rb
|
201
|
-
- spec/autoloading_spec.rb
|
202
|
-
- spec/callbacks_spec.rb
|
203
|
-
- spec/client_spec.rb
|
204
|
-
- spec/endpoint_spec.rb
|
205
|
-
- spec/fixtures/github.rb
|
206
|
-
- spec/fixtures/github/_repository_fields.graphql
|
207
|
-
- spec/fixtures/github/repository.graphql
|
208
|
-
- spec/fixtures/github/schema.json
|
209
|
-
- spec/fixtures/github/user.graphql
|
210
|
-
- spec/fixtures/github/user_repositories.graphql
|
211
|
-
- spec/fixtures/responses/github/repository.yml
|
212
|
-
- spec/fixtures/responses/github/user.json
|
213
|
-
- spec/fixtures/responses/spotify_client/artist.yml
|
214
|
-
- spec/spec_helper.rb
|
215
|
-
- spec/test_helper_spec.rb
|
216
187
|
- tmp/.gitkeep
|
217
188
|
homepage: https://github.com/yuki24/artemis
|
218
189
|
licenses:
|
@@ -233,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
204
|
- !ruby/object:Gem::Version
|
234
205
|
version: '0'
|
235
206
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
207
|
+
rubygems_version: 3.5.9
|
237
208
|
signing_key:
|
238
209
|
specification_version: 4
|
239
210
|
summary: GraphQL on Rails
|
data/spec/adapters_spec.rb
DELETED
@@ -1,278 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'rack'
|
3
|
-
require 'webrick'
|
4
|
-
|
5
|
-
RACK_SERVER = begin
|
6
|
-
require 'rackup/handler/webrick'
|
7
|
-
Rackup::Handler::WEBrick
|
8
|
-
rescue LoadError
|
9
|
-
Rack::Handler::WEBrick
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'Adapters' do
|
13
|
-
FakeServer = ->(env) {
|
14
|
-
case env['PATH_INFO']
|
15
|
-
when '/slow_server'
|
16
|
-
sleep 2.1
|
17
|
-
|
18
|
-
[200, {}, ['{}']]
|
19
|
-
when '/500'
|
20
|
-
[500, {}, ['Server error']]
|
21
|
-
when '/test_multi_domain'
|
22
|
-
body = {
|
23
|
-
data: {
|
24
|
-
body: "Endpoint switched.",
|
25
|
-
headers: env.select {|key, val| key.match("^HTTP.*|^CONTENT.*|^AUTHORIZATION.*") }
|
26
|
-
.collect {|key, val| [key.gsub(/^HTTP_/, ''), val.downcase] }
|
27
|
-
.to_h,
|
28
|
-
},
|
29
|
-
errors: [],
|
30
|
-
extensions: {}
|
31
|
-
}.to_json
|
32
|
-
|
33
|
-
[200, {}, [body]]
|
34
|
-
else
|
35
|
-
request_body = JSON.parse(env['rack.input'].read)
|
36
|
-
|
37
|
-
response_body = if request_body['_json']
|
38
|
-
request_body['_json'].map do |query|
|
39
|
-
{
|
40
|
-
data: {
|
41
|
-
body: query,
|
42
|
-
headers: env.select {|key, val| key.match("^HTTP.*|^CONTENT.*|^AUTHORIZATION.*") }
|
43
|
-
.collect {|key, val| [key.gsub(/^HTTP_/, ''), val.downcase] }
|
44
|
-
.to_h,
|
45
|
-
},
|
46
|
-
errors: [],
|
47
|
-
extensions: {}
|
48
|
-
}
|
49
|
-
end.to_json
|
50
|
-
else
|
51
|
-
{
|
52
|
-
data: {
|
53
|
-
body: request_body,
|
54
|
-
headers: env.select {|key, val| key.match("^HTTP.*|^CONTENT.*|^AUTHORIZATION.*") }
|
55
|
-
.collect {|key, val| [key.gsub(/^HTTP_/, ''), val.downcase] }
|
56
|
-
.to_h,
|
57
|
-
},
|
58
|
-
errors: [],
|
59
|
-
extensions: {}
|
60
|
-
}.to_json
|
61
|
-
end
|
62
|
-
|
63
|
-
[200, {}, [response_body]]
|
64
|
-
end
|
65
|
-
}
|
66
|
-
|
67
|
-
before :all do
|
68
|
-
Artemis::Adapters::AbstractAdapter.send(:attr_writer, :uri, :timeout)
|
69
|
-
|
70
|
-
@server_thread = Thread.new do
|
71
|
-
RACK_SERVER.run(FakeServer, Port: 8000, Logger: WEBrick::Log.new('/dev/null'), AccessLog: [])
|
72
|
-
end
|
73
|
-
|
74
|
-
loop do
|
75
|
-
begin
|
76
|
-
TCPSocket.open('localhost', 8000)
|
77
|
-
break
|
78
|
-
rescue Errno::ECONNREFUSED
|
79
|
-
# no-op
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
after :all do
|
85
|
-
RACK_SERVER.shutdown
|
86
|
-
@server_thread.terminate
|
87
|
-
end
|
88
|
-
|
89
|
-
shared_examples 'an adapter' do
|
90
|
-
describe '#initialize' do
|
91
|
-
it 'requires an url' do
|
92
|
-
expect do
|
93
|
-
adapter.class.new(nil, service_name: nil, timeout: 2, pool_size: 5)
|
94
|
-
end.to raise_error(ArgumentError, "url is required (given `nil')")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe '#execute' do
|
99
|
-
it 'makes an actual HTTP request' do
|
100
|
-
response = adapter.execute(
|
101
|
-
document: GraphQL::Client::IntrospectionDocument,
|
102
|
-
operation_name: 'IntrospectionQuery',
|
103
|
-
variables: { id: 'yayoi-kusama' },
|
104
|
-
context: { user_id: 1 }
|
105
|
-
)
|
106
|
-
|
107
|
-
expect(response['data']['body']['query']).to eq(GraphQL::Client::IntrospectionDocument.to_query_string)
|
108
|
-
expect(response['data']['body']['variables']).to eq('id' => 'yayoi-kusama')
|
109
|
-
expect(response['data']['body']['operationName']).to eq('IntrospectionQuery')
|
110
|
-
expect(response['data']['headers']['CONTENT_TYPE']).to eq('application/json')
|
111
|
-
expect(response['data']['headers']['ACCEPT']).to eq('application/json')
|
112
|
-
expect(response['errors']).to eq([])
|
113
|
-
expect(response['extensions']).to eq({})
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'raises an error when it receives a server error' do
|
117
|
-
adapter.uri = URI.parse('http://localhost:8000/500')
|
118
|
-
|
119
|
-
expect do
|
120
|
-
adapter.execute(document: GraphQL::Client::IntrospectionDocument, operation_name: 'IntrospectionQuery')
|
121
|
-
end.to raise_error(Artemis::GraphQLServerError, "Received server error status 500: Server error")
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'allows for overriding timeout' do
|
125
|
-
adapter.uri = URI.parse('http://localhost:8000/slow_server')
|
126
|
-
|
127
|
-
expect do
|
128
|
-
adapter.execute(document: GraphQL::Client::IntrospectionDocument, operation_name: 'IntrospectionQuery')
|
129
|
-
end.to raise_error(timeout_error)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe '#multiplex' do
|
134
|
-
it 'makes an HTTP request with multiple queries' do
|
135
|
-
response = adapter.multiplex(
|
136
|
-
[
|
137
|
-
{
|
138
|
-
query: GraphQL::Client::IntrospectionDocument.to_query_string,
|
139
|
-
operationName: 'IntrospectionQuery',
|
140
|
-
variables: {
|
141
|
-
id: 'yayoi-kusama'
|
142
|
-
},
|
143
|
-
},
|
144
|
-
],
|
145
|
-
context: {
|
146
|
-
user_id: 1
|
147
|
-
}
|
148
|
-
)
|
149
|
-
|
150
|
-
introspection_query = response[0]
|
151
|
-
|
152
|
-
expect(introspection_query['data']['body']['query']).to eq(GraphQL::Client::IntrospectionDocument.to_query_string)
|
153
|
-
expect(introspection_query['data']['body']['variables']).to eq('id' => 'yayoi-kusama')
|
154
|
-
expect(introspection_query['data']['body']['operationName']).to eq('IntrospectionQuery')
|
155
|
-
expect(introspection_query['data']['headers']['CONTENT_TYPE']).to eq('application/json')
|
156
|
-
expect(introspection_query['data']['headers']['ACCEPT']).to eq('application/json')
|
157
|
-
expect(introspection_query['errors']).to eq([])
|
158
|
-
expect(introspection_query['extensions']).to eq({})
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'raises an error when it receives a server error' do
|
162
|
-
adapter.uri = URI.parse('http://localhost:8000/500')
|
163
|
-
|
164
|
-
expect do
|
165
|
-
adapter.multiplex([])
|
166
|
-
end.to raise_error(Artemis::GraphQLServerError, "Received server error status 500: Server error")
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'allows for overriding timeout' do
|
170
|
-
adapter.uri = URI.parse('http://localhost:8000/slow_server')
|
171
|
-
|
172
|
-
expect do
|
173
|
-
adapter.multiplex([])
|
174
|
-
end.to raise_error(timeout_error)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
describe Artemis::Adapters::NetHttpAdapter do
|
180
|
-
let(:adapter) { Artemis::Adapters::NetHttpAdapter.new('http://localhost:8000', service_name: nil, timeout: 0.5, pool_size: 5) }
|
181
|
-
let(:timeout_error) { Net::ReadTimeout }
|
182
|
-
|
183
|
-
it_behaves_like 'an adapter'
|
184
|
-
end
|
185
|
-
|
186
|
-
describe Artemis::Adapters::NetHttpPersistentAdapter do
|
187
|
-
let(:adapter) { Artemis::Adapters::NetHttpPersistentAdapter.new('http://localhost:8000', service_name: nil, timeout: 0.5, pool_size: 5) }
|
188
|
-
let(:timeout_error) { Net::ReadTimeout }
|
189
|
-
|
190
|
-
it_behaves_like 'an adapter'
|
191
|
-
end
|
192
|
-
|
193
|
-
describe Artemis::Adapters::MultiDomainAdapter do
|
194
|
-
let(:adapter) { Artemis::Adapters::MultiDomainAdapter.new('ignored', service_name: nil, timeout: 0.5, pool_size: 5, adapter_options: { adapter: :net_http }) }
|
195
|
-
|
196
|
-
it 'makes an actual HTTP request' do
|
197
|
-
response = adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/test_multi_domain' })
|
198
|
-
|
199
|
-
expect(response['data']['body']).to eq("Endpoint switched.")
|
200
|
-
expect(response['errors']).to eq([])
|
201
|
-
expect(response['extensions']).to eq({})
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'can make a multiplex (the graphql feature, not HTTP/2) request' do
|
205
|
-
response = adapter.multiplex(
|
206
|
-
[
|
207
|
-
{
|
208
|
-
query: GraphQL::Client::IntrospectionDocument.to_query_string,
|
209
|
-
operationName: 'IntrospectionQuery',
|
210
|
-
variables: {
|
211
|
-
id: 'yayoi-kusama'
|
212
|
-
},
|
213
|
-
},
|
214
|
-
],
|
215
|
-
context: {
|
216
|
-
url: 'http://localhost:8000/test_multi_domain'
|
217
|
-
}
|
218
|
-
)
|
219
|
-
|
220
|
-
expect(response['data']['body']).to eq("Endpoint switched.")
|
221
|
-
expect(response['errors']).to eq([])
|
222
|
-
expect(response['extensions']).to eq({})
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'can make a multiplex request with custom HTTP headers' do
|
226
|
-
response = adapter.multiplex(
|
227
|
-
[
|
228
|
-
{
|
229
|
-
query: GraphQL::Client::IntrospectionDocument.to_query_string,
|
230
|
-
operationName: 'IntrospectionQuery',
|
231
|
-
},
|
232
|
-
],
|
233
|
-
context: {
|
234
|
-
headers: {
|
235
|
-
Authorization: "Token token",
|
236
|
-
},
|
237
|
-
url: 'http://localhost:8000/test_multi_domain'
|
238
|
-
}
|
239
|
-
)
|
240
|
-
|
241
|
-
expect(response['data']['headers']['AUTHORIZATION']).to eq("token token")
|
242
|
-
end
|
243
|
-
|
244
|
-
it 'raises an error when adapter_options.adapter is set to :multi domain' do
|
245
|
-
expect do
|
246
|
-
Artemis::Adapters::MultiDomainAdapter.new('ignored', service_name: nil, timeout: 0.5, pool_size: 5, adapter_options: { adapter: :multi_domain })
|
247
|
-
end.to raise_error(ArgumentError, 'You can not use the :multi_domain adapter with the :multi_domain adapter.')
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'raises an error when context.url is not specified' do
|
251
|
-
expect do
|
252
|
-
adapter.execute(document: GraphQL::Client::IntrospectionDocument)
|
253
|
-
end.to raise_error(ArgumentError, 'The MultiDomain adapter requires a url on every request. Please specify a ' \
|
254
|
-
'url with a context: Client.with_context(url: "https://awesomeshop.domain.conm")')
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'raises an error when it receives a server error' do
|
258
|
-
expect do
|
259
|
-
adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/500' })
|
260
|
-
end.to raise_error(Artemis::GraphQLServerError, "Received server error status 500: Server error")
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'allows for overriding timeout' do
|
264
|
-
expect do
|
265
|
-
adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/slow_server' })
|
266
|
-
end.to raise_error(Net::ReadTimeout)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
if RUBY_ENGINE == 'ruby'
|
271
|
-
describe Artemis::Adapters::CurbAdapter do
|
272
|
-
let(:adapter) { Artemis::Adapters::CurbAdapter.new('http://localhost:8000', service_name: nil, timeout: 2, pool_size: 5) }
|
273
|
-
let(:timeout_error) { Curl::Err::TimeoutError }
|
274
|
-
|
275
|
-
it_behaves_like 'an adapter'
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|