artemis 1.0.0 → 1.1.0
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 +4 -4
- data/Appraisals +7 -0
- data/CHANGELOG.md +28 -4
- data/Gemfile +1 -0
- data/Rakefile +1 -4
- data/artemis.gemspec +0 -1
- data/gemfiles/graphql_2_0.gemfile +1 -0
- data/gemfiles/rails_50.gemfile +1 -1
- data/gemfiles/rails_51.gemfile +1 -0
- data/gemfiles/rails_52.gemfile +1 -0
- data/gemfiles/rails_60.gemfile +1 -0
- data/gemfiles/rails_61.gemfile +1 -0
- data/gemfiles/rails_70.gemfile +1 -0
- data/gemfiles/rails_71.gemfile +1 -0
- data/gemfiles/rails_72.gemfile +15 -0
- data/gemfiles/rails_edge.gemfile +1 -0
- data/lib/artemis/railtie.rb +6 -8
- data/lib/artemis/version.rb +1 -1
- metadata +4 -33
- 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: f28739ac0d67a5efdcce9e904d0650665a65c7f88bf00c1db9bcda5434a94757
|
4
|
+
data.tar.gz: db90cbdf7503158c27be28bf2cd3f942901d99d7894c3ac3a981981d02936d37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfdfe631667b33fd2253353a8aa7f772a36d74f4301d2e75c453669a4670b2f459abe224fc2b34c0df3b5fa1364d6ad1c687b1656a1bd2dd9458895cc56c8bfa
|
7
|
+
data.tar.gz: 751ed648e9e331b329b6dccb3503db458cad3cf7cdabbe0d27bf009262231b943e6c677d9ec97710b6dada3aa979c0b26a6bd7a7637689b45e0e7911c7c6c419
|
data/.github/workflows/ruby.yml
CHANGED
@@ -75,7 +75,7 @@ jobs:
|
|
75
75
|
env:
|
76
76
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
77
77
|
steps:
|
78
|
-
- uses: actions/checkout@
|
78
|
+
- uses: actions/checkout@v4
|
79
79
|
- name: Install curl
|
80
80
|
run: sudo apt-get install curl libcurl4-openssl-dev
|
81
81
|
- name: Set up Ruby
|
@@ -92,7 +92,7 @@ jobs:
|
|
92
92
|
env:
|
93
93
|
BUNDLE_GEMFILE: gemfiles/rails_edge.gemfile
|
94
94
|
steps:
|
95
|
-
- uses: actions/checkout@
|
95
|
+
- uses: actions/checkout@v4
|
96
96
|
- name: Install curl
|
97
97
|
run: sudo apt-get install curl libcurl4-openssl-dev
|
98
98
|
- name: Set up Ruby
|
@@ -116,7 +116,7 @@ jobs:
|
|
116
116
|
env:
|
117
117
|
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
118
118
|
steps:
|
119
|
-
- uses: actions/checkout@
|
119
|
+
- uses: actions/checkout@v4
|
120
120
|
- name: Install curl
|
121
121
|
run: sudo apt-get install curl libcurl4-openssl-dev
|
122
122
|
- name: Set up Ruby
|
@@ -141,7 +141,7 @@ jobs:
|
|
141
141
|
# env:
|
142
142
|
# BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
143
143
|
# steps:
|
144
|
-
# - uses: actions/checkout@
|
144
|
+
# - uses: actions/checkout@v4
|
145
145
|
# - name: Set up Ruby
|
146
146
|
# uses: ruby/setup-ruby@v1
|
147
147
|
# with:
|
data/Appraisals
CHANGED
@@ -17,6 +17,13 @@ appraise "graphql_2_0" do
|
|
17
17
|
gem "graphql", "< 2.1"
|
18
18
|
end
|
19
19
|
|
20
|
+
appraise "rails_72" do
|
21
|
+
gem "rails", '~> 7.2.0'
|
22
|
+
gem "railties", '~> 7.2.0'
|
23
|
+
gem "activesupport", '~> 7.2.0'
|
24
|
+
gem "rackup"
|
25
|
+
end
|
26
|
+
|
20
27
|
appraise "rails_71" do
|
21
28
|
gem "rails", '~> 7.1.0'
|
22
29
|
gem "railties", '~> 7.1.0'
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,38 @@
|
|
1
|
-
## v1.
|
1
|
+
## v1.1.0
|
2
|
+
|
3
|
+
_<sup>Unreleased</sup>_
|
4
|
+
|
5
|
+
#### ⭐️ New Features
|
6
|
+
|
7
|
+
- Add support for Ruby 3.3. (e05756768c1535babccfca71f32d5218dd4da626)
|
8
|
+
|
9
|
+
## [v1.0.2](https://github.com/yuki24/artemis/tree/v1.0.2)
|
10
|
+
|
11
|
+
_<sup>released at 2024-05-02 02:41:10 UTC</sup>_
|
12
|
+
|
13
|
+
#### 🐞 Bug Fixes
|
14
|
+
|
15
|
+
- Fixes a bug where abstract client classes are not loaded correctly ([#93](https://github.com/yuki24/artemis/issues/93), `494d30b`)
|
16
|
+
|
17
|
+
## [v1.0.1](https://github.com/yuki24/artemis/tree/v1.0.1)
|
18
|
+
|
19
|
+
_<sup>released at 2024-05-02 02:40:54 UTC</sup>_
|
20
|
+
|
21
|
+
> Yanked due to inconsistent commit history.
|
22
|
+
|
23
|
+
## [v1.0.0](https://github.com/yuki24/artemis/tree/v1.0.0)
|
24
|
+
|
25
|
+
_<sup>released at 2024-02-05 06:16:35 UTC</sup>_
|
2
26
|
|
3
27
|
#### 🚨 Breaking Changes
|
4
28
|
|
5
29
|
- Drop support for Ruby 2.6. For those of you looking to use Artemis on Ruby 2.6, please use the `artemis` version
|
6
|
-
`0.9.0` and the `graphql-client` version `0.17.0`.
|
30
|
+
`0.9.0` and the `graphql-client` version `0.17.0`. ([#90](https://github.com/yuki24/artemis/pull/90))
|
7
31
|
|
8
32
|
#### ⭐️ New Features
|
9
33
|
|
10
|
-
- Add support for Ruby 3.3.
|
11
|
-
- Add support for the latest
|
34
|
+
- Add support for Ruby 3.3. ([#91](https://github.com/yuki24/artemis/pull/91))
|
35
|
+
- Add support for the latest versions of the `graphql` gem. ([#92](https://github.com/yuki24/artemis/pull/92))
|
12
36
|
|
13
37
|
#### 🐞 Bug Fixes
|
14
38
|
|
data/Gemfile
CHANGED
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
@@ -24,5 +24,4 @@ Gem::Specification.new do |spec|
|
|
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/gemfiles/rails_50.gemfile
CHANGED
data/gemfiles/rails_51.gemfile
CHANGED
data/gemfiles/rails_52.gemfile
CHANGED
data/gemfiles/rails_60.gemfile
CHANGED
data/gemfiles/rails_61.gemfile
CHANGED
data/gemfiles/rails_70.gemfile
CHANGED
data/gemfiles/rails_71.gemfile
CHANGED
@@ -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 "minitest", "< 5.25.0"
|
10
|
+
gem "rails", "~> 7.2.0"
|
11
|
+
gem "railties", "~> 7.2.0"
|
12
|
+
gem "activesupport", "~> 7.2.0"
|
13
|
+
gem "rackup"
|
14
|
+
|
15
|
+
gemspec path: "../"
|
data/gemfiles/rails_edge.gemfile
CHANGED
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: 1.
|
4
|
+
version: 1.1.0
|
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: 2024-
|
12
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -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
|
@@ -170,6 +156,7 @@ files:
|
|
170
156
|
- gemfiles/rails_61.gemfile
|
171
157
|
- gemfiles/rails_70.gemfile
|
172
158
|
- gemfiles/rails_71.gemfile
|
159
|
+
- gemfiles/rails_72.gemfile
|
173
160
|
- gemfiles/rails_edge.gemfile
|
174
161
|
- lib/artemis.rb
|
175
162
|
- lib/artemis/adapters.rb
|
@@ -198,22 +185,6 @@ files:
|
|
198
185
|
- lib/generators/artemis/query/templates/fixture.yml
|
199
186
|
- lib/generators/artemis/query/templates/query.graphql
|
200
187
|
- lib/tasks/artemis.rake
|
201
|
-
- spec/adapters_spec.rb
|
202
|
-
- spec/autoloading_spec.rb
|
203
|
-
- spec/callbacks_spec.rb
|
204
|
-
- spec/client_spec.rb
|
205
|
-
- spec/endpoint_spec.rb
|
206
|
-
- spec/fixtures/github.rb
|
207
|
-
- spec/fixtures/github/_repository_fields.graphql
|
208
|
-
- spec/fixtures/github/repository.graphql
|
209
|
-
- spec/fixtures/github/schema.json
|
210
|
-
- spec/fixtures/github/user.graphql
|
211
|
-
- spec/fixtures/github/user_repositories.graphql
|
212
|
-
- spec/fixtures/responses/github/repository.yml
|
213
|
-
- spec/fixtures/responses/github/user.json
|
214
|
-
- spec/fixtures/responses/spotify_client/artist.yml
|
215
|
-
- spec/spec_helper.rb
|
216
|
-
- spec/test_helper_spec.rb
|
217
188
|
- tmp/.gitkeep
|
218
189
|
homepage: https://github.com/yuki24/artemis
|
219
190
|
licenses:
|
@@ -234,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
205
|
- !ruby/object:Gem::Version
|
235
206
|
version: '0'
|
236
207
|
requirements: []
|
237
|
-
rubygems_version: 3.5.
|
208
|
+
rubygems_version: 3.5.11
|
238
209
|
signing_key:
|
239
210
|
specification_version: 4
|
240
211
|
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
|