artemis 0.5.2 → 0.6.0

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: 165436feafc8c76f46453a3c25d9dbd4029c2ce7d77a6920ce1795e05cc1637d
4
- data.tar.gz: bee99e318ec86563b2a30e368d6ef085cab8cfb284584e94f4e0f2a1ebb2d4c3
3
+ metadata.gz: 0a0f96c5c92adae8e2b52b173e05240aaa8967d8184887f25e3b986abe7db6a6
4
+ data.tar.gz: bf731d81af95a1ae12c6cc0d1bc01b4f0b13e3d563717d7ee97d3bdbbbc2c18f
5
5
  SHA512:
6
- metadata.gz: c4040a5a7074baec1939cb163838409c573a70ea21a23fc327f2781951c59cdbfe720c3d91d538e9b0fdc26a780edde0c1b1cfec82a321f8a1d2277ca6983926
7
- data.tar.gz: 61126510087da4bdb782aa5a86cc0404839326915fc9c3e44c8fec7a91290de0a4a806c64612d6d4a248269d49131552f190c1b274c3b73a4bedf351ab1c2b46
6
+ metadata.gz: 448933d593a7cb931dca4fb128e4a7052792e2c6405f42a797e9f1e9f4bde557fb6845f123a0132e89a53b6f56310c2c0585af74a87acace334dd34d5f74b105
7
+ data.tar.gz: 6865a729838c972eda26707ea12cddb846a21aea6d1b2c0cd252054054f2f5758b2c81bdd543ddbac5dfc1fd6ca127c31fd83a5a67f6e847230d7eec787d7375
@@ -0,0 +1,53 @@
1
+ name: build
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ build:
9
+ strategy:
10
+ matrix:
11
+ ruby_version:
12
+ - '3.0'
13
+ - '2.7'
14
+ - '2.6'
15
+ - '2.5'
16
+ # - 'jruby-9.2.17.0'
17
+ gemfile:
18
+ - gemfiles/rails_61.gemfile
19
+ - gemfiles/rails_60.gemfile
20
+ - gemfiles/rails_52.gemfile
21
+ - gemfiles/rails_51.gemfile
22
+ - gemfiles/rails_50.gemfile
23
+ # - gemfiles/rails_edge.gemfile
24
+ exclude:
25
+ - ruby_version: '3.0'
26
+ gemfile: gemfiles/rails_52.gemfile
27
+ - ruby_version: '3.0'
28
+ gemfile: gemfiles/rails_51.gemfile
29
+ - ruby_version: '3.0'
30
+ gemfile: gemfiles/rails_50.gemfile
31
+ - ruby_version: '2.7'
32
+ gemfile: gemfiles/rails_52.gemfile
33
+ - ruby_version: '2.7'
34
+ gemfile: gemfiles/rails_51.gemfile
35
+ - ruby_version: '2.7'
36
+ gemfile: gemfiles/rails_50.gemfile
37
+ # - ruby_version: '2.6'
38
+ # gemfile: gemfiles/rails_edge.gemfile
39
+ # - ruby_version: '2.5'
40
+ # gemfile: gemfiles/rails_edge.gemfile
41
+ runs-on: ubuntu-18.04
42
+ env:
43
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
44
+ steps:
45
+ - uses: actions/checkout@v2
46
+ - name: Install curl
47
+ run: sudo apt-get install curl libcurl4-openssl-dev
48
+ - name: Set up Ruby
49
+ uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: ${{ matrix.ruby_version }}
52
+ bundler-cache: true
53
+ - run: bundle exec rake
data/Appraisals CHANGED
@@ -6,6 +6,12 @@ appraise "rails_edge" do
6
6
  end
7
7
  end
8
8
 
9
+ appraise "rails_61" do
10
+ gem "rails", '~> 6.1.0'
11
+ gem "railties", '~> 6.1.0'
12
+ gem "activesupport", '~> 6.1.0'
13
+ end
14
+
9
15
  appraise "rails_60" do
10
16
  gem "rails", '~> 6.0.0.rc1'
11
17
  gem "railties", '~> 6.0.0.rc1'
@@ -30,23 +36,3 @@ appraise "rails_50" do
30
36
  gem "activesupport", '~> 5.0.0'
31
37
  gem "minitest", '5.10.3'
32
38
  end
33
-
34
- appraise "rails_42" do
35
- gem "rails", '~> 4.2.0'
36
- gem "railties", '~> 4.2.0'
37
- gem "activesupport", '~> 4.2.0'
38
- gem "minitest", '5.10.3'
39
- end
40
-
41
- appraise "rails_41" do
42
- gem "rails", '~> 4.1.0'
43
- gem "railties", '~> 4.1.0'
44
- gem "activesupport", '~> 4.1.0'
45
- gem "minitest", '5.10.3'
46
- end
47
-
48
- appraise "rails_40" do
49
- gem "rails", '~> 4.0.0'
50
- gem "railties", '~> 4.0.0'
51
- gem "activesupport", '~> 4.0.0'
52
- end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## v0.6.0
2
+
3
+ _<sup>(unreleased)</sup>_
4
+
5
+ #### Features
6
+
7
+ * Add support for Ruby 3.0 and Rails 6.0, 6.1
8
+ * Add the multi domain adapter (744b8ea3)
9
+
10
+ #### Fixes
11
+
12
+ * ~~Generate fixture YAML files on `rails g artemis:query queryName` (#78)~~ Removed due to a bug for now.
13
+ * Address warnings from Ruby 2.7 (408adcb3)
14
+ * Avoid crashing when config/graphql.yml does not exist (@dlackty, #76)
15
+
16
+ ## [v0.5.2](https://github.com/yuki24/artemis/tree/v0.5.2)
17
+
18
+ _<sup>released at 2019-07-26 03:21:43 UTC</sup>_
19
+
20
+ #### Fixes
21
+
22
+ - Fixes an issue where fixtures can not be looked up properly when the client has two or more words in its name ([@JanStevens](https://github.com/JanStevens), issue: [#72](https://github.com/yuki24/artemis/issues/72), PR: [#73](https://github.com/yuki24/artemis/pull/73))
23
+
1
24
  ## [v0.5.1](https://github.com/yuki24/artemis/tree/v0.5.1)
2
25
 
3
26
  _<sup>released at 2019-07-01 14:25:35 UTC</sup>_
data/Gemfile CHANGED
@@ -7,3 +7,5 @@ gemspec
7
7
 
8
8
  gem 'pry'
9
9
  gem 'pry-byebug', platforms: :mri
10
+ gem 'curb', '>= 0.9.6' if RUBY_ENGINE == 'ruby'
11
+ gem 'webrick' if RUBY_VERSION >= '3.0.0'
data/README.md CHANGED
@@ -51,7 +51,7 @@ query($id: String!) {
51
51
  }
52
52
  ```
53
53
 
54
- Then you could the class method that has the matching name `artist`:
54
+ Then you could call the class method that has the matching name `artist`:
55
55
 
56
56
  ```ruby
57
57
  Artsy.artist(id: "pablo-picasso")
@@ -94,7 +94,7 @@ Artemis assumes that the files related to GraphQL are organized in a certain way
94
94
 
95
95
  ## Callbacks
96
96
 
97
- Youcan use the `before_execute` callback to intercept outgoing requests and the `after_execute` callback to observe the
97
+ You can use the `before_execute` callback to intercept outgoing requests and the `after_execute` callback to observe the
98
98
  response. A common operation that's done in the `before_execute` hook is assigning a token to the header:
99
99
 
100
100
  ```ruby
@@ -145,7 +145,7 @@ There are four adapter options available. Choose the adapter that best fits on y
145
145
  | `:net_http_persistent` | HTTP/1.1 only | **Yes** | **Fast** | [`net-http-persistent 3.0.0+`][nhp]
146
146
  | `:test` | N/A (See Testing)
147
147
 
148
- ### Third-party adapters
148
+ #### Third-party adapters
149
149
 
150
150
  This is a comminuty-maintained adapter. Want to add yours? Send us a pull request!
151
151
 
@@ -153,7 +153,7 @@ This is a comminuty-maintained adapter. Want to add yours? Send us a pull reques
153
153
  | ---------------------- | ------------|
154
154
  | [`:net_http_hmac`](https://github.com/JanStevens/artemis-api-auth/tree/master) | provides a new Adapter for the Artemis GraphQL ruby client to support HMAC Authentication using [ApiAuth](https://github.com/mgomes/api_auth). |
155
155
 
156
- ### Writing your own adapter
156
+ #### Writing your own adapter
157
157
 
158
158
  When the built-in adapters do not satisfy your needs, you may want to implement your own adapter. You could do so by following the steps below. Let's implement the [`:net_http_hmac`](https://github.com/JanStevens/artemis-api-auth/tree/master) adapter as an example.
159
159
 
data/artemis.gemspec CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "appraisal", ">= 2.2"
24
24
  spec.add_development_dependency "bundler", ">= 1.16"
25
- spec.add_development_dependency "curb", ">= 0.9.6"
26
25
  spec.add_development_dependency "net-http-persistent", ">= 3.0"
27
26
  spec.add_development_dependency "rake", ">= 10.0"
28
27
  spec.add_development_dependency "rspec", ">= 3.8"
@@ -2,9 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0"
6
5
  gem "pry"
7
6
  gem "pry-byebug", platforms: :mri
7
+ gem "curb", ">= 0.9.6"
8
+ gem "webrick"
9
+ gem "rails", "~> 5.0.0"
8
10
  gem "railties", "~> 5.0.0"
9
11
  gem "activesupport", "~> 5.0.0"
10
12
  gem "minitest", "5.10.3"
@@ -2,9 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.1.0"
6
5
  gem "pry"
7
6
  gem "pry-byebug", platforms: :mri
7
+ gem "curb", ">= 0.9.6"
8
+ gem "webrick"
9
+ gem "rails", "~> 5.1.0"
8
10
  gem "railties", "~> 5.1.0"
9
11
  gem "activesupport", "~> 5.1.0"
10
12
 
@@ -2,9 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.2.0"
6
5
  gem "pry"
7
6
  gem "pry-byebug", platforms: :mri
7
+ gem "curb", ">= 0.9.6"
8
+ gem "webrick"
9
+ gem "rails", "~> 5.2.0"
8
10
  gem "railties", "~> 5.2.0"
9
11
  gem "activesupport", "~> 5.2.0"
10
12
 
@@ -2,9 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 6.0.0.rc1"
6
5
  gem "pry"
7
6
  gem "pry-byebug", platforms: :mri
7
+ gem "curb", ">= 0.9.6"
8
+ gem "webrick"
9
+ gem "rails", "~> 6.0.0.rc1"
8
10
  gem "railties", "~> 6.0.0.rc1"
9
11
  gem "activesupport", "~> 6.0.0.rc1"
10
12
 
@@ -2,10 +2,12 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.0.0"
6
5
  gem "pry"
7
6
  gem "pry-byebug", platforms: :mri
8
- gem "railties", "~> 4.0.0"
9
- gem "activesupport", "~> 4.0.0"
7
+ gem "curb", ">= 0.9.6"
8
+ gem "webrick"
9
+ gem "rails", "~> 6.1.0"
10
+ gem "railties", "~> 6.1.0"
11
+ gem "activesupport", "~> 6.1.0"
10
12
 
11
13
  gemspec path: "../"
@@ -10,5 +10,6 @@ end
10
10
 
11
11
  gem "pry"
12
12
  gem "pry-byebug", platforms: :mri
13
+ gem "curb", ">= 0.9.6"
13
14
 
14
15
  gemspec path: "../"
@@ -15,7 +15,7 @@ module Artemis
15
15
  "Content-Type" => "application/json"
16
16
  }.freeze
17
17
 
18
- def initialize(uri, service_name: , timeout: , pool_size: )
18
+ def initialize(uri, service_name: , timeout: , pool_size: , adapter_options: {})
19
19
  raise ArgumentError, "url is required (given `#{uri.inspect}')" if uri.blank?
20
20
 
21
21
  super(uri) # Do not pass in the block to avoid getting #headers and #connection overridden.
@@ -13,7 +13,7 @@ module Artemis
13
13
  class CurbAdapter < AbstractAdapter
14
14
  attr_reader :multi
15
15
 
16
- def initialize(uri, service_name: , timeout: , pool_size: )
16
+ def initialize(uri, service_name: , timeout: , pool_size: , adapter_options: {})
17
17
  super
18
18
 
19
19
  @multi = Curl::Multi.new
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'artemis/adapters/abstract_adapter'
4
+
5
+ module Artemis
6
+ module Adapters
7
+ class MultiDomainAdapter < AbstractAdapter
8
+ attr_reader :adapter
9
+
10
+ def initialize(_uri, service_name: , timeout: , pool_size: , adapter_options: {})
11
+ @connection_by_url = {}
12
+ @service_name = service_name.to_s
13
+ @timeout = timeout
14
+ @pool_size = pool_size
15
+ @adapter = adapter_options[:adapter] || :net_http
16
+ @mutex_for_connection = Mutex.new
17
+ end
18
+
19
+ # Makes an HTTP request for GraphQL query.
20
+ def execute(document:, operation_name: nil, variables: {}, context: {})
21
+ url = context[:url]
22
+
23
+ if url.nil?
24
+ raise ArgumentError, 'The MultiDomain adapter requires a url on every request. Please specify a url with a context: ' \
25
+ 'Client.with_context(url: "https://awesomeshop.domain.conm")'
26
+ end
27
+
28
+ connection_for_url(url).execute(document: document, operation_name: operation_name, variables: variables, context: context)
29
+ end
30
+
31
+ def connection
32
+ raise NotImplementedError, "Calling the #connection method without a URI is not supported. Please use the " \
33
+ "#connection_for_url(uri) instead."
34
+ end
35
+
36
+ def connection_for_url(url)
37
+ @connection_by_url[url.to_s] || @mutex_for_connection.synchronize do
38
+ @connection_by_url[url.to_s] ||= ::Artemis::Adapters.lookup(adapter).new(url, service_name: service_name, timeout: timeout, pool_size: pool_size)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -12,7 +12,7 @@ module Artemis
12
12
  class NetHttpPersistentAdapter < NetHttpAdapter
13
13
  attr_reader :_connection, :raw_connection
14
14
 
15
- def initialize(uri, service_name: , timeout: , pool_size: )
15
+ def initialize(uri, service_name: , timeout: , pool_size: , adapter_options: {})
16
16
  super
17
17
 
18
18
  @raw_connection = Net::HTTP::Persistent.new(name: service_name, pool_size: pool_size)
@@ -22,7 +22,7 @@ module Artemis
22
22
  self.requests << Request.new(*arguments.values_at(:document, :operation_name, :variables, :context))
23
23
 
24
24
  response = responses.detect do |mock|
25
- arguments[:operation_name] == mock.operation_name && mock.arguments == :__unspecified__ || arguments[:variables] == mock.arguments
25
+ arguments[:operation_name] == mock.operation_name && (mock.arguments == :__unspecified__ || arguments[:variables] == mock.arguments)
26
26
  end
27
27
 
28
28
  response&.data || {
@@ -7,6 +7,7 @@ module Artemis
7
7
  extend ActiveSupport::Autoload
8
8
 
9
9
  autoload :CurbAdapter
10
+ autoload :MultiDomainAdapter
10
11
  autoload :NetHttpAdapter
11
12
  autoload :NetHttpPersistentAdapter
12
13
  autoload :TestAdapter
@@ -248,9 +248,9 @@ module Artemis
248
248
  # Github.user # => delegates to Github.new(default_context).user
249
249
  #
250
250
  # @api private
251
- def method_missing(method_name, *arguments, &block)
251
+ def method_missing(method_name, **arguments, &block)
252
252
  if resolve_graphql_file_path(method_name)
253
- new(default_context).public_send(method_name, *arguments, &block)
253
+ new(default_context).public_send(method_name, **arguments, &block)
254
254
  else
255
255
  super
256
256
  end
@@ -33,7 +33,7 @@ module Artemis
33
33
  end
34
34
 
35
35
  def register!(service_name, configurations)
36
- ENDPOINT_INSTANCES[service_name.to_s.underscore] = new(service_name.to_s, configurations.symbolize_keys)
36
+ ENDPOINT_INSTANCES[service_name.to_s.underscore] = new(service_name.to_s, **configurations.symbolize_keys)
37
37
  end
38
38
 
39
39
  ##
@@ -44,10 +44,16 @@ module Artemis
44
44
  end
45
45
  end
46
46
 
47
- attr_reader :name, :url, :adapter, :timeout, :schema_path, :pool_size
47
+ attr_reader :name, :url, :adapter, :timeout, :schema_path, :pool_size, :adapter_options
48
48
 
49
- def initialize(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25)
50
- @name, @url, @adapter, @timeout, @schema_path, @pool_size = name.to_s, url, adapter, timeout, schema_path, pool_size
49
+ def initialize(name, url: nil, adapter: :net_http, timeout: 10, schema_path: nil, pool_size: 25, adapter_options: {})
50
+ @name = name.to_s
51
+ @url = url
52
+ @adapter = adapter
53
+ @timeout = timeout
54
+ @schema_path = schema_path
55
+ @pool_size = pool_size
56
+ @adapter_options = adapter_options
51
57
 
52
58
  @mutex_for_schema = Mutex.new
53
59
  @mutex_for_connection = Mutex.new
@@ -66,7 +72,7 @@ module Artemis
66
72
 
67
73
  def connection
68
74
  @connection || @mutex_for_connection.synchronize do
69
- @connection ||= ::Artemis::Adapters.lookup(adapter).new(url, service_name: name, timeout: timeout, pool_size: pool_size)
75
+ @connection ||= ::Artemis::Adapters.lookup(adapter).new(url, service_name: name, timeout: timeout, pool_size: pool_size, adapter_options: adapter_options)
70
76
  end
71
77
  end
72
78
  end
@@ -57,8 +57,8 @@ module Artemis
57
57
 
58
58
  initializer 'graphql.client.preload', after: 'graphql.client.load_config' do |app|
59
59
  if app.config.eager_load && app.config.cache_classes
60
- Artemis.config_for_graphql(app).keys.each do |endpoint_name|
61
- endpoint_name.to_s.camelize.constantize.preload!
60
+ Artemis::GraphQLEndpoint.registered_services.each do |endpoint_name|
61
+ endpoint_name.camelize.constantize.preload!
62
62
  end
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module Artemis
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- mutation<%= arguments.present? && "(#{ arguments.map {|name, type| "$#{name}: #{type.type}" }.join(", ") })" %> {
1
+ mutation<%= arguments.present? && "(#{ arguments.map {|name, type| "$#{name}: #{type.type.to_type_signature}" }.join(", ") })" %> {
2
2
  <%= target_mutation.name %><%= arguments.present? && "(#{ arguments.map {|name, type| "#{name}: $#{name}" }.join(", ") })" %> {
3
3
  # Add fields here...
4
4
  }
@@ -14,6 +14,10 @@ class Artemis::QueryGenerator < Rails::Generators::Base
14
14
  template "query.graphql", graphql_file_path
15
15
  end
16
16
 
17
+ # def generate_text_fixture_file
18
+ # template "fixture.yml", text_fixture_path
19
+ # end
20
+
17
21
  private
18
22
 
19
23
  def query_name
@@ -21,7 +25,11 @@ class Artemis::QueryGenerator < Rails::Generators::Base
21
25
  end
22
26
 
23
27
  def graphql_file_path
24
- "app/operations/#{service_name.underscore}/#{graphql_file_name.presence || query_name}.graphql"
28
+ "app/operations/#{service_name.underscore}/#{qualified_name}.graphql"
29
+ end
30
+
31
+ def text_fixture_path
32
+ File.join(Artemis::Railtie.config.artemis.fixture_path, service_name.underscore, "#{qualified_name}.yml")
25
33
  end
26
34
 
27
35
  def arguments
@@ -49,4 +57,8 @@ class Artemis::QueryGenerator < Rails::Generators::Base
49
57
  end
50
58
  end
51
59
  end
60
+
61
+ def qualified_name
62
+ graphql_file_name.presence || query_name
63
+ end
52
64
  end
@@ -0,0 +1,19 @@
1
+ # You can stub GraphQL queries by calling the `stub_graphql' method in test:
2
+ #
3
+ # stub_graphql(<%= service_name.camelize %>, :<%= qualified_name.underscore %>).to_return(:<%= target_query.name %>_1)
4
+ #
5
+ # Or with a arguments matcher:
6
+ #
7
+ # stub_graphql(<%= service_name.camelize %>, :<%= qualified_name.underscore %>, <%= arguments.map {|name, _| "#{name}: \"...\"" }.join(", ") %>).to_return(:<%= target_query.name %>_2)
8
+ #
9
+
10
+ <%= target_query.name %>_1:
11
+ data:
12
+ <% target_query.type.fields.values.each do |field| -%>
13
+ <%= field.name %>: # type: <%= field.type.to_type_signature %>
14
+ <% end %>
15
+ <%= target_query.name %>_2:
16
+ data:
17
+ <% target_query.type.fields.values.each do |field| -%>
18
+ <%= field.name %>: # type: <%= field.type.to_type_signature %>
19
+ <% end %>
@@ -1,4 +1,4 @@
1
- query<%= arguments.present? && "(#{ arguments.map {|name, type| "$#{name}: #{type.type}" }.join(", ") })" %> {
1
+ query<%= arguments.present? && "(#{ arguments.map {|name, type| "$#{name}: #{type.type.to_type_signature}" }.join(", ") })" %> {
2
2
  <%= target_query.name %><%= arguments.present? && "(#{ arguments.map {|name, type| "#{name}: $#{name}" }.join(", ") })" %> {
3
3
  # Add fields here...
4
4
  }
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'rack'
3
+ require 'webrick'
3
4
 
4
5
  describe 'Adapters' do
5
6
  FakeServer = ->(env) {
@@ -10,6 +11,16 @@ describe 'Adapters' do
10
11
  [200, {}, ['{}']]
11
12
  when '/500'
12
13
  [500, {}, ['Server error']]
14
+ when '/test_multi_domain'
15
+ body = {
16
+ data: {
17
+ body: "Endpoint switched.",
18
+ },
19
+ errors: [],
20
+ extensions: {}
21
+ }.to_json
22
+
23
+ [200, {}, [body]]
13
24
  else
14
25
  body = {
15
26
  data: {
@@ -102,15 +113,48 @@ describe 'Adapters' do
102
113
 
103
114
  describe Artemis::Adapters::NetHttpPersistentAdapter do
104
115
  let(:adapter) { Artemis::Adapters::NetHttpPersistentAdapter.new('http://localhost:8000', service_name: nil, timeout: 0.5, pool_size: 5) }
105
- let(:timeout_error) { Net::HTTP::Persistent::Error }
116
+ let(:timeout_error) { Net::ReadTimeout }
106
117
 
107
118
  it_behaves_like 'an adapter'
108
119
  end
109
120
 
110
- describe Artemis::Adapters::CurbAdapter do
111
- let(:adapter) { Artemis::Adapters::CurbAdapter.new('http://localhost:8000', service_name: nil, timeout: 2, pool_size: 5) }
112
- let(:timeout_error) { Curl::Err::TimeoutError }
121
+ describe Artemis::Adapters::MultiDomainAdapter do
122
+ let(:adapter) { Artemis::Adapters::MultiDomainAdapter.new('ignored', service_name: nil, timeout: 0.5, pool_size: 5, adapter_options: { adapter: :net_http }) }
113
123
 
114
- it_behaves_like 'an adapter'
124
+ it 'makes an actual HTTP request' do
125
+ response = adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/test_multi_domain' })
126
+
127
+ expect(response['data']['body']).to eq("Endpoint switched.")
128
+ expect(response['errors']).to eq([])
129
+ expect(response['extensions']).to eq({})
130
+ end
131
+
132
+ it 'raises an error when context.url is not specified' do
133
+ expect do
134
+ adapter.execute(document: GraphQL::Client::IntrospectionDocument)
135
+ end.to raise_error(ArgumentError, 'The MultiDomain adapter requires a url on every request. Please specify a ' \
136
+ 'url with a context: Client.with_context(url: "https://awesomeshop.domain.conm")')
137
+ end
138
+
139
+ it 'raises an error when it receives a server error' do
140
+ expect do
141
+ adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/500' })
142
+ end.to raise_error(Artemis::GraphQLServerError, "Received server error status 500: Server error")
143
+ end
144
+
145
+ it 'allows for overriding timeout' do
146
+ expect do
147
+ adapter.execute(document: GraphQL::Client::IntrospectionDocument, context: { url: 'http://localhost:8000/slow_server' })
148
+ end.to raise_error(Net::ReadTimeout)
149
+ end
150
+ end
151
+
152
+ if RUBY_ENGINE == 'ruby'
153
+ describe Artemis::Adapters::CurbAdapter do
154
+ let(:adapter) { Artemis::Adapters::CurbAdapter.new('http://localhost:8000', service_name: nil, timeout: 2, pool_size: 5) }
155
+ let(:timeout_error) { Curl::Err::TimeoutError }
156
+
157
+ it_behaves_like 'an adapter'
158
+ end
115
159
  end
116
160
  end
@@ -70,6 +70,15 @@ describe Artemis::TestHelper do
70
70
  expect(yoshiki.data.artist.name).to eq("Artist Yoshiki")
71
71
  end
72
72
 
73
+ it "can mock separate GraphQL queries with the same arguments" do
74
+ stub_graphql("SpotifyClient", :artist, id: "yoshiki").to_return(:yoshiki)
75
+ stub_graphql(Metaphysics, :artist, id: "yoshiki").to_return(:yoshiki)
76
+
77
+ yoshiki = Metaphysics.artist(id: "yoshiki")
78
+
79
+ expect(yoshiki.data.artist.name).to eq("Artist Yoshiki")
80
+ end
81
+
73
82
  it "allows to get raw fixture data as a Hash" do
74
83
  data = stub_graphql("SpotifyClient", :artist).get(:yoshiki)
75
84
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artemis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Allured
8
8
  - Yuki Nishijima
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-26 00:00:00.000000000 Z
12
+ date: 2021-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -95,20 +95,6 @@ dependencies:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '1.16'
98
- - !ruby/object:Gem::Dependency
99
- name: curb
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: 0.9.6
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: 0.9.6
112
98
  - !ruby/object:Gem::Dependency
113
99
  name: net-http-persistent
114
100
  requirement: !ruby/object:Gem::Requirement
@@ -159,9 +145,9 @@ executables: []
159
145
  extensions: []
160
146
  extra_rdoc_files: []
161
147
  files:
148
+ - ".github/workflows/ruby.yml"
162
149
  - ".gitignore"
163
150
  - ".rspec"
164
- - ".travis.yml"
165
151
  - Appraisals
166
152
  - CHANGELOG.md
167
153
  - CODE_OF_CONDUCT.md
@@ -176,18 +162,17 @@ files:
176
162
  - doc/CHANGELOG.md.erb
177
163
  - doc/changelog_generator.rb
178
164
  - gemfiles/.bundle/config
179
- - gemfiles/rails_40.gemfile
180
- - gemfiles/rails_41.gemfile
181
- - gemfiles/rails_42.gemfile
182
165
  - gemfiles/rails_50.gemfile
183
166
  - gemfiles/rails_51.gemfile
184
167
  - gemfiles/rails_52.gemfile
185
168
  - gemfiles/rails_60.gemfile
169
+ - gemfiles/rails_61.gemfile
186
170
  - gemfiles/rails_edge.gemfile
187
171
  - lib/artemis.rb
188
172
  - lib/artemis/adapters.rb
189
173
  - lib/artemis/adapters/abstract_adapter.rb
190
174
  - lib/artemis/adapters/curb_adapter.rb
175
+ - lib/artemis/adapters/multi_domain_adapter.rb
191
176
  - lib/artemis/adapters/net_http_adapter.rb
192
177
  - lib/artemis/adapters/net_http_persistent_adapter.rb
193
178
  - lib/artemis/adapters/test_adapter.rb
@@ -207,6 +192,7 @@ files:
207
192
  - lib/generators/artemis/mutation/templates/mutation.graphql
208
193
  - lib/generators/artemis/query/USAGE
209
194
  - lib/generators/artemis/query/query_generator.rb
195
+ - lib/generators/artemis/query/templates/fixture.yml
210
196
  - lib/generators/artemis/query/templates/query.graphql
211
197
  - lib/tasks/artemis.rake
212
198
  - spec/adapters_spec.rb
@@ -230,7 +216,7 @@ homepage: https://github.com/yuki24/artemis
230
216
  licenses:
231
217
  - MIT
232
218
  metadata: {}
233
- post_install_message:
219
+ post_install_message:
234
220
  rdoc_options: []
235
221
  require_paths:
236
222
  - lib
@@ -245,8 +231,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
231
  - !ruby/object:Gem::Version
246
232
  version: '0'
247
233
  requirements: []
248
- rubygems_version: 3.0.3
249
- signing_key:
234
+ rubygems_version: 3.2.26
235
+ signing_key:
250
236
  specification_version: 4
251
237
  summary: GraphQL on Rails
252
238
  test_files: []
data/.travis.yml DELETED
@@ -1,69 +0,0 @@
1
- language: ruby
2
- script: bundle exec rake
3
- cache: bundler
4
- sudo: false
5
-
6
- before_install: gem install bundler -v 1.17.3
7
-
8
- rvm:
9
- - 2.6.2
10
- - 2.5.5
11
- - 2.4.5
12
- - 2.3.8
13
- - ruby-head
14
- # - jruby-9.2.3.0
15
- # - jruby-head
16
-
17
- gemfile:
18
- - gemfiles/rails_60.gemfile
19
- - gemfiles/rails_52.gemfile
20
- - gemfiles/rails_51.gemfile
21
- - gemfiles/rails_50.gemfile
22
- - gemfiles/rails_42.gemfile
23
- - gemfiles/rails_41.gemfile
24
- - gemfiles/rails_40.gemfile
25
- - gemfiles/rails_edge.gemfile
26
-
27
- matrix:
28
- allow_failures:
29
- - rvm: ruby-head
30
- # - rvm: jruby-9.2.3.0
31
- # - rvm: jruby-head
32
- - gemfile: gemfiles/rails_edge.gemfile
33
- - gemfile: gemfiles/rails_41.gemfile
34
- - gemfile: gemfiles/rails_40.gemfile
35
- exclude:
36
- - rvm: ruby-head
37
- gemfile: gemfiles/rails_40.gemfile
38
- - rvm: ruby-head
39
- gemfile: gemfiles/rails_41.gemfile
40
- - rvm: ruby-head
41
- gemfile: gemfiles/rails_42.gemfile
42
- - rvm: 2.6.2
43
- gemfile: gemfiles/rails_50.gemfile
44
- - rvm: 2.6.2
45
- gemfile: gemfiles/rails_42.gemfile
46
- - rvm: 2.6.2
47
- gemfile: gemfiles/rails_41.gemfile
48
- - rvm: 2.6.2
49
- gemfile: gemfiles/rails_40.gemfile
50
- - rvm: 2.5.5
51
- gemfile: gemfiles/rails_50.gemfile
52
- - rvm: 2.5.5
53
- gemfile: gemfiles/rails_42.gemfile
54
- - rvm: 2.5.5
55
- gemfile: gemfiles/rails_41.gemfile
56
- - rvm: 2.5.5
57
- gemfile: gemfiles/rails_40.gemfile
58
- - rvm: 2.4.5
59
- gemfile: gemfiles/rails_edge.gemfile
60
- - rvm: 2.4.5
61
- gemfile: gemfiles/rails_60.gemfile
62
- - rvm: 2.4.5
63
- gemfile: gemfiles/rails_41.gemfile
64
- - rvm: 2.4.5
65
- gemfile: gemfiles/rails_40.gemfile
66
- - rvm: 2.3.8
67
- gemfile: gemfiles/rails_edge.gemfile
68
- - rvm: 2.3.8
69
- gemfile: gemfiles/rails_60.gemfile
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.1.0"
6
- gem "pry"
7
- gem "pry-byebug", platforms: :mri
8
- gem "railties", "~> 4.1.0"
9
- gem "activesupport", "~> 4.1.0"
10
- gem "minitest", "5.10.3"
11
-
12
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.2.0"
6
- gem "pry"
7
- gem "pry-byebug", platforms: :mri
8
- gem "railties", "~> 4.2.0"
9
- gem "activesupport", "~> 4.2.0"
10
- gem "minitest", "5.10.3"
11
-
12
- gemspec path: "../"