artemis 0.4.0 → 0.5.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: 0b5fc48841d80c3f0ebd0cc161938caf1044b09ce300bb55822df3ae1323aed2
4
- data.tar.gz: e42427484c1786929c66a2f8a7650cb2e631230155f92c92e5d36406a20a41b0
3
+ metadata.gz: fb8351e9d06cd0d45eec2321fbdea32691030d55b717145a8165df83d0fd91f3
4
+ data.tar.gz: 98f117a37598ece1f224b50cedbfa8587432c8440da16ca179460a9732604ed7
5
5
  SHA512:
6
- metadata.gz: 1b0625a78d265426de79dc77ace3f0ff2336e75a914b37b4179356ec3f0c69c2beda8658e1b0cabf914221aea92e6fb86c6510075b6ab9c9c0e9f04cb1c37368
7
- data.tar.gz: f80b1e917bfaac00586704ab09a3893f7d879b02a62b5693816f1c7977fed64233585b7e0d17ab8ae7877efdab2a5efc951eab4928f9120d90a41c9895cd0c93
6
+ metadata.gz: 2933d4c334cf13af3f923f7915c5eae745837667bb0f1322310944fb3a54ef117ab1666b38e242814bd433e27b8dfb96691b38e2aaa1e271882fe4e6c4952fa5
7
+ data.tar.gz: 9c780829798e9a3bff896bcf6b52aa97918eea1c93336f4295f0bf478030dbeeb53670d1f6f0b4c96776e59cb35cf6935ce61eec3ca9d538462d3527f50936a6
@@ -1,13 +1,13 @@
1
- nguage: ruby
1
+ language: ruby
2
2
  script: bundle exec rake
3
3
  cache: bundler
4
4
  sudo: false
5
5
 
6
- before_install: gem install bundler -v 1.16.1
6
+ before_install: gem install bundler -v 1.17.3
7
7
 
8
8
  rvm:
9
- - 2.6.0
10
- - 2.5.3
9
+ - 2.6.2
10
+ - 2.5.5
11
11
  - 2.4.5
12
12
  - 2.3.8
13
13
  - ruby-head
@@ -15,10 +15,13 @@ rvm:
15
15
  # - jruby-head
16
16
 
17
17
  gemfile:
18
+ - gemfiles/rails_60.gemfile
18
19
  - gemfiles/rails_52.gemfile
19
20
  - gemfiles/rails_51.gemfile
20
21
  - gemfiles/rails_50.gemfile
21
22
  - gemfiles/rails_42.gemfile
23
+ - gemfiles/rails_41.gemfile
24
+ - gemfiles/rails_40.gemfile
22
25
  - gemfiles/rails_edge.gemfile
23
26
 
24
27
  matrix:
@@ -27,8 +30,40 @@ matrix:
27
30
  # - rvm: jruby-9.2.3.0
28
31
  # - rvm: jruby-head
29
32
  - gemfile: gemfiles/rails_edge.gemfile
33
+ - gemfile: gemfiles/rails_41.gemfile
34
+ - gemfile: gemfiles/rails_40.gemfile
30
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
31
58
  - rvm: 2.4.5
32
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
33
66
  - rvm: 2.3.8
34
67
  gemfile: gemfiles/rails_edge.gemfile
68
+ - rvm: 2.3.8
69
+ gemfile: gemfiles/rails_60.gemfile
data/Appraisals CHANGED
@@ -1,32 +1,52 @@
1
1
  appraise "rails_edge" do
2
- git 'git://github.com/rails/rails.git' do
2
+ git 'https://github.com/rails/rails.git' do
3
3
  gem "rails"
4
4
  gem "railties"
5
5
  gem "activesupport"
6
6
  end
7
7
  end
8
8
 
9
+ appraise "rails_60" do
10
+ gem "rails", '~> 6.0.0.rc1'
11
+ gem "railties", '~> 6.0.0.rc1'
12
+ gem "activesupport", '~> 6.0.0.rc1'
13
+ end
14
+
9
15
  appraise "rails_52" do
10
- gem "rails", '~> 5.2'
11
- gem "railties", '~> 5.2'
12
- gem "activesupport", '~> 5.2'
16
+ gem "rails", '~> 5.2.0'
17
+ gem "railties", '~> 5.2.0'
18
+ gem "activesupport", '~> 5.2.0'
13
19
  end
14
20
 
15
21
  appraise "rails_51" do
16
- gem "rails", '~> 5.1'
17
- gem "railties", '~> 5.1'
18
- gem "activesupport", '~> 5.1'
22
+ gem "rails", '~> 5.1.0'
23
+ gem "railties", '~> 5.1.0'
24
+ gem "activesupport", '~> 5.1.0'
19
25
  end
20
26
 
21
27
  appraise "rails_50" do
22
- gem "rails", '~> 5.0'
23
- gem "railties", '~> 5.0'
24
- gem "activesupport", '~> 5.0'
28
+ gem "rails", '~> 5.0.0'
29
+ gem "railties", '~> 5.0.0'
30
+ gem "activesupport", '~> 5.0.0'
31
+ gem "minitest", '5.10.3'
25
32
  end
26
33
 
27
34
  appraise "rails_42" do
28
- gem "rails", '~> 4.2'
29
- gem "railties", '~> 4.2'
30
- gem "activesupport", '~> 4.2'
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'
31
45
  gem "minitest", '5.10.3'
32
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
@@ -1,8 +1,19 @@
1
- ## Unreleased
1
+ ## [v0.4.0](https://github.com/yuki24/artemis/tree/v0.4.0)
2
2
 
3
- * Add a new entry here
4
- * [#48](https://github.com/yuki24/artemis/pull/48): Do not transform keys of query variables [@erikdstock](https://github.com/erikdstock)
5
- * [#47](https://github.com/yuki24/artemis/pull/47): Fixes an issue where errors thrown from `config/graphql.yml` get swallowed
3
+ _<sup>released at 2019-01-30 03:42:14 UTC</sup>_
4
+
5
+ #### Features
6
+
7
+ - [<tt>48d052e</tt>](https://github.com/yuki24/artemis/commit/48d052e9819703f1cefa95fbdb431bd03928f4ed): Add an easy way to set up Rspec integration
8
+ - [<tt>0f7cd12</tt>](https://github.com/yuki24/artemis/commit/0f7cd120594a0dd2a4af2b2e5cf990891dd8de16): Make Artemis' Railtie configurable
9
+ - [<tt>6bd15e2</tt>](https://github.com/yuki24/artemis/commit/6bd15e20779e5a6f898e1aacf8237c94c8c46aba): Add the ability to use ERB in test fixtures
10
+ - [#49](https://github.com/yuki24/artemis/pull/49): Expose the TestAdapter as a public API
11
+
12
+ #### Bug fixes
13
+
14
+ - [<tt>b7ad4a4</tt>](https://github.com/yuki24/artemis/commit/b7ad4a481a43cadd9193076c0e44938e05e6d44b): Require `graphl >= 1.8` to fix a bug in the generator
15
+ - [#48](https://github.com/yuki24/artemis/pull/48): Do not transform keys of query variables ([@erikdstock](https://github.com/erikdstock))
16
+ - [#47](https://github.com/yuki24/artemis/pull/47): Fixes an issue where errors thrown from `config/graphql.yml` get swallowed
6
17
 
7
18
  ## [v0.2.0: New generators and small improvements](https://github.com/yuki24/artemis/tree/v0.2.0)
8
19
 
@@ -14,11 +25,11 @@ _<sup>released at 2018-10-30 02:09:59 UTC</sup>_
14
25
  - [#42](https://github.com/yuki24/artemis/pull/42): Allow for setting up the test adapter without `url`
15
26
  - [#41](https://github.com/yuki24/artemis/pull/41): Add a mutation generator
16
27
  - [#40](https://github.com/yuki24/artemis/pull/40): Add a query generator
17
- - [#39](https://github.com/yuki24/artemis/pull/39): Installer now adds a new service if config/graphql.yml is present
28
+ - [#39](https://github.com/yuki24/artemis/pull/39): Installer now adds a new service if `config/graphql.yml` is present
18
29
 
19
30
  ## [v0.1.0: First release!](https://github.com/yuki24/artemis/tree/v0.1.0)
20
31
 
21
32
  _<sup>released at 2018-10-16 20:57:51 UTC</sup>_
22
33
 
23
- First release of Artemis! <g-emoji class="g-emoji" alias="tada" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f389.png">&#127881;</g-emoji>
34
+ First release of Artemis! <g-emoji class="g-emoji" alias="tada" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f389.png">&#127881;</g-emoji>
24
35
 
data/Gemfile CHANGED
@@ -5,6 +5,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in artemis.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rails'
9
8
  gem 'pry'
10
9
  gem 'pry-byebug', platforms: :mri
data/README.md CHANGED
@@ -12,24 +12,7 @@ Artemis is a GraphQL client that is designed to fit well on Rails.
12
12
 
13
13
  <img width="24" height="24" src="https://avatars1.githubusercontent.com/u/541332?s=48&amp;v=4"> Battle-tested at [Artsy](https://www.artsy.net)
14
14
 
15
- ## Quick start
16
-
17
- You could set up Artemis with just a few commands. See it in action:
18
-
19
- ```bash
20
- $ bundle add artemis
21
- $ rails g artemis:install artsy https://metaphysics-production.artsy.net/
22
- $ echo '
23
- query($id: String!) {
24
- artist(id: $id) {
25
- name
26
- birthday
27
- }
28
- }' > app/operations/artsy/artist.graphql
29
- $ rails c
30
- > Artsy.artist(id: "leonardo-da-vinci").data.artist.name # => "Leonardo da Vinci"
31
- > Artsy.artist(id: "leonardo-da-vinci").data.artist.birthday # => "1452/04/15"
32
- ```
15
+ ![graphql-client vs Artemis](https://raw.githubusercontent.com/yuki24/artemis/master/banner.png "graphql-client vs Artemis")
33
16
 
34
17
  ## Getting started
35
18
 
@@ -39,20 +22,13 @@ Add this line to your application's Gemfile:
39
22
  gem 'artemis'
40
23
  ```
41
24
 
42
- And then execute:
43
-
44
- $ bundle
45
-
46
25
  Once you run `bundle install` on your Rails app, run the install command:
47
26
 
48
27
 
49
28
  ```sh
50
29
  $ rails g artemis:install artsy https://metaphysics-production.artsy.net/
51
- ```
52
-
53
- You could also use the `--authorization` option to assign a token so the installer can download the GraphQL schema:
54
30
 
55
- ```sh
31
+ # or if you need to specify the `--authorization` header:
56
32
  $ rails g artemis:install github https://api.github.com/graphql --authorization 'token ...'
57
33
  ```
58
34
 
@@ -169,14 +145,68 @@ There are four adapter options available. Choose the adapter that best fits on y
169
145
  | `:net_http_persistent` | HTTP/1.1 only | **Yes** | **Fast** | [`net-http-persistent 3.0.0+`][nhp]
170
146
  | `:test` | N/A (See Testing)
171
147
 
148
+ ### Third-party adapters
149
+
150
+ This is a comminuty-maintained adapter. Want to add yours? Send us a pull request!
151
+
152
+ | Adapter | Description |
153
+ | ---------------------- | ------------|
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
+
156
+ ### Writing your own adapter
157
+
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
+
160
+ 1. Define `NetHttpHmacAdapter` under the `Artemis::Adapters` namespace and implement [the `#execute` method](https://github.com/github/graphql-client/blob/master/guides/remote-queries.md):
161
+
162
+ ```ruby
163
+ # lib/artemis/adapters/net_http_hmac_adapter.rb
164
+ module Artemis::Adapters
165
+ class NetHttpHmacAdapter
166
+ def execute(document:, operation_name: nil, variables: {}, context: {})
167
+ # Makes an HTTP request for GraphQL query.
168
+ end
169
+ end
170
+ end
171
+ ```
172
+
173
+ 2. Load the adapter in `config/initializers/artemis.rb` (or any place that gets loaded before Rails runs initializers):
174
+
175
+ ```ruby
176
+ require 'artemis/adapters/net_http_hmac_adapter'
177
+ ```
178
+
179
+ 3. Specify the adapter name in `config/graphql.yml`:
180
+
181
+ ```yml
182
+ default: &default
183
+ adapter: :net_http_hmac
184
+ ```
185
+
172
186
  ## Rake tasks
173
187
 
174
188
  Artemis also adds a useful `rake graphql:schema:update` rake task that downloads the GraphQL schema using the
175
189
  `Introspection` query.
176
190
 
177
- | Task Name | Options | Description |
178
- | ---------------------------- | --------- | ------------|
179
- | `graphql:schema:update` | `SERVICE`: Service name the schema is downloaded from<br>`AUTHORIZATION`: HTTTP `Authroization` header value used to download the schema| Downloads and saves the GraphQL schema
191
+ ### `graphql:schema:update`
192
+
193
+ Downloads and saves the GraphQL schema.
194
+
195
+ | Option Name | Description |
196
+ | ------------------ | ------------|
197
+ | `SERVICE` | Service name the schema is downloaded from.|
198
+ | `AUTHORIZATION` | HTTP `Authorization` header value used to download the schema with.|
199
+
200
+
201
+ #### Examples
202
+
203
+ ```
204
+ $ rake graphql:schema:update
205
+ # => downloads schema from the service. fails if there are multiple services in config/graphql.yml.
206
+
207
+ $ rake graphql:schema:update SERVICE=github AUTHORIZATION="token ..."
208
+ # => downloads schema from the `github` service using the HTTP header "AUTHORIZATION: token ..."
209
+ ```
180
210
 
181
211
  ## Testing
182
212
 
@@ -269,4 +299,4 @@ Everyone interacting in the Artemis project’s codebases, issue trackers, chat
269
299
  [curb]: https://rubygems.org/gems/curb
270
300
  [curl]: https://curl.haxx.se/docs/http2.html
271
301
  [nghttp]: https://nghttp2.org/
272
- [nhp]: https://rubygems.org/gems/net-http-persistent
302
+ [nhp]: https://rubygems.org/gems/net-http-persistent
@@ -15,15 +15,15 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test)/}) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.add_dependency "activesupport", ">= 4.2.0"
18
+ spec.add_dependency "activesupport", ">= 4.0.0"
19
+ spec.add_dependency "railties", ">= 4.0.0"
19
20
  spec.add_dependency "graphql", ">= 1.8"
20
21
  spec.add_dependency "graphql-client", ">= 0.13.0"
21
- spec.add_dependency "railties", ">= 4.2.0"
22
22
 
23
- spec.add_development_dependency "appraisal", "~> 2.2"
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
- spec.add_development_dependency "curb", "~> 0.9.6"
26
- spec.add_development_dependency "net-http-persistent", "~> 3.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "rspec", "~> 3.8"
23
+ spec.add_development_dependency "appraisal", ">= 2.2"
24
+ spec.add_development_dependency "bundler", ">= 1.16"
25
+ spec.add_development_dependency "curb", ">= 0.9.6"
26
+ spec.add_development_dependency "net-http-persistent", ">= 3.0"
27
+ spec.add_development_dependency "rake", ">= 10.0"
28
+ spec.add_development_dependency "rspec", ">= 3.8"
29
29
  end
Binary file
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.0.0"
6
+ gem "pry"
7
+ gem "pry-byebug", platforms: :mri
8
+ gem "railties", "~> 4.0.0"
9
+ gem "activesupport", "~> 4.0.0"
10
+
11
+ gemspec path: "../"
@@ -0,0 +1,12 @@
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: "../"
@@ -2,11 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "rails", "~> 4.2.0"
5
6
  gem "pry"
6
7
  gem "pry-byebug", platforms: :mri
7
- gem "rails", "~> 4.2"
8
- gem "railties", "~> 4.2"
9
- gem "activesupport", "~> 4.2"
8
+ gem "railties", "~> 4.2.0"
9
+ gem "activesupport", "~> 4.2.0"
10
10
  gem "minitest", "5.10.3"
11
11
 
12
12
  gemspec path: "../"
@@ -2,10 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "rails", "~> 5.0.0"
5
6
  gem "pry"
6
7
  gem "pry-byebug", platforms: :mri
7
- gem "rails", "~> 5.0"
8
- gem "railties", "~> 5.0"
9
- gem "activesupport", "~> 5.0"
8
+ gem "railties", "~> 5.0.0"
9
+ gem "activesupport", "~> 5.0.0"
10
+ gem "minitest", "5.10.3"
10
11
 
11
12
  gemspec path: "../"
@@ -2,10 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "rails", "~> 5.1.0"
5
6
  gem "pry"
6
7
  gem "pry-byebug", platforms: :mri
7
- gem "rails", "~> 5.1"
8
- gem "railties", "~> 5.1"
9
- gem "activesupport", "~> 5.1"
8
+ gem "railties", "~> 5.1.0"
9
+ gem "activesupport", "~> 5.1.0"
10
10
 
11
11
  gemspec path: "../"
@@ -2,10 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "rails", "~> 5.2.0"
5
6
  gem "pry"
6
7
  gem "pry-byebug", platforms: :mri
7
- gem "rails", "~> 5.2"
8
- gem "railties", "~> 5.2"
9
- gem "activesupport", "~> 5.2"
8
+ gem "railties", "~> 5.2.0"
9
+ gem "activesupport", "~> 5.2.0"
10
10
 
11
11
  gemspec path: "../"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0.rc1"
6
+ gem "pry"
7
+ gem "pry-byebug", platforms: :mri
8
+ gem "railties", "~> 6.0.0.rc1"
9
+ gem "activesupport", "~> 6.0.0.rc1"
10
+
11
+ gemspec path: "../"
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- git "git://github.com/rails/rails.git" do
5
+ git "https://github.com/rails/rails.git" do
6
6
  gem "rails"
7
7
  gem "railties"
8
8
  gem "activesupport"
@@ -1,3 +1,34 @@
1
1
  require "artemis/version"
2
2
  require "artemis/client"
3
- require "artemis/railtie" if defined?(Rails)
3
+ require "artemis/railtie" if defined?(Rails)
4
+
5
+ module Artemis
6
+ def self.config_for_graphql(app)
7
+ if app.respond_to?(:config_for)
8
+ app.config_for(:graphql)
9
+ else
10
+ config_for(:graphql, app: app)
11
+ end
12
+ end
13
+
14
+ # backported from https://github.com/rails/rails/blob/b9ca94ca/railties/lib/rails/application.rb#L226
15
+ # TODO: Remove once dropping Rails <= 4.1 support
16
+ def self.config_for(name, app:, env: Rails.env)
17
+ if name.is_a?(Pathname)
18
+ yaml = name
19
+ else
20
+ yaml = Pathname.new("#{app.paths["config"].existent.first}/#{name}.yml")
21
+ end
22
+
23
+ if yaml.exist?
24
+ require "erb"
25
+ (YAML.load(ERB.new(yaml.read).result) || {})[env] || {}
26
+ else
27
+ raise "Could not load configuration. No such file - #{yaml}"
28
+ end
29
+ rescue Psych::SyntaxError => e
30
+ raise "YAML syntax error occurred while parsing #{yaml}. " \
31
+ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
32
+ "Error: #{e.message}"
33
+ end
34
+ end
@@ -10,6 +10,11 @@ module Artemis
10
10
 
11
11
  EMPTY_HEADERS = {}.freeze
12
12
 
13
+ DEFAULT_HEADERS = {
14
+ "Accept" => "application/json",
15
+ "Content-Type" => "application/json"
16
+ }.freeze
17
+
13
18
  def initialize(uri, service_name: , timeout: , pool_size: )
14
19
  raise ArgumentError, "url is required (given `#{uri.inspect}')" if uri.blank?
15
20
 
@@ -30,7 +30,7 @@ module Artemis
30
30
 
31
31
  easy.timeout = timeout
32
32
  easy.multi = multi
33
- easy.headers = headers(context) || {}
33
+ easy.headers = DEFAULT_HEADERS.merge(headers(context))
34
34
  easy.post_body = JSON.generate(body)
35
35
 
36
36
  if defined?(Curl::CURLPIPE_MULTIPLEX)
@@ -15,9 +15,7 @@ module Artemis
15
15
 
16
16
  request.basic_auth(uri.user, uri.password) if uri.user || uri.password
17
17
 
18
- request["Accept"] = "application/json"
19
- request["Content-Type"] = "application/json"
20
- headers(context).each { |name, value| request[name] = value }
18
+ DEFAULT_HEADERS.merge(headers(context)).each { |name, value| request[name] = value }
21
19
 
22
20
  body = {}
23
21
  body["query"] = document.to_query_string
@@ -4,6 +4,7 @@ require 'delegate'
4
4
 
5
5
  require 'active_support/configurable'
6
6
  require 'active_support/core_ext/hash/deep_merge'
7
+ require 'active_support/core_ext/module/delegation'
7
8
  require 'active_support/core_ext/string/inflections'
8
9
 
9
10
  require 'artemis/graphql_endpoint'
@@ -205,6 +206,10 @@ module Artemis
205
206
  Executor.new(endpoint.connection, callbacks, default_context.deep_merge(context))
206
207
  end
207
208
 
209
+ def execute(query, context: {}, **arguments)
210
+ new(default_context).execute(query, context: context, **arguments)
211
+ end
212
+
208
213
  private
209
214
 
210
215
  # Looks up the GraphQL file that matches the given +const_name+ and sets it to a constant. If the files it not
@@ -255,6 +260,28 @@ module Artemis
255
260
  end
256
261
  end
257
262
 
263
+ # Executes a given query, raises if we didn't define the operation
264
+ #
265
+ # @param [String] operation
266
+ # @param [Hash] context
267
+ # @param [Hash] arguments
268
+ #
269
+ # @return [GraphQL::Client::Response]
270
+ def execute(query, context: {}, **arguments)
271
+ if self.class.resolve_graphql_file_path(query)
272
+ const_name = query.to_s.camelize
273
+
274
+ # This check will be unnecessary once we drop support for Ruby 2.4 and earlier
275
+ if !self.class.const_get(const_name).is_a?(GraphQL::Client::OperationDefinition)
276
+ self.class.load_constant(const_name)
277
+ end
278
+
279
+ client.query(self.class.const_get(const_name), variables: arguments, context: context)
280
+ else
281
+ raise GraphQLFileNotFound.new("Query #{query}.graphql not found in: #{config.query_paths.join(", ")}")
282
+ end
283
+ end
284
+
258
285
  private
259
286
 
260
287
  # Delegates a method call to a GraphQL call.
@@ -268,18 +295,9 @@ module Artemis
268
295
  #
269
296
  # @api private
270
297
  def method_missing(method_name, context: {}, **arguments)
271
- if self.class.resolve_graphql_file_path(method_name)
272
- const_name = method_name.to_s.camelize
273
-
274
- # This check will be unnecessary once we drop support for Ruby 2.4 and earlier
275
- if !self.class.const_get(const_name).is_a?(GraphQL::Client::OperationDefinition)
276
- self.class.load_constant(const_name)
277
- end
278
-
279
- client.query(self.class.const_get(const_name), variables: arguments, context: context)
280
- else
281
- super
282
- end
298
+ execute(method_name, context: context, **arguments)
299
+ rescue GraphQLFileNotFound
300
+ super
283
301
  end
284
302
 
285
303
  def respond_to_missing?(method_name, *_, &block) #:nodoc:
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_support/core_ext/hash/deep_merge'
4
4
  require 'active_support/core_ext/hash/keys'
5
+ require 'active_support/core_ext/class/attribute_accessors'
5
6
  require 'active_support/core_ext/object/blank'
6
7
  require 'active_support/core_ext/string/inflections'
7
8
  require 'graphql/client'
@@ -11,6 +12,13 @@ require 'artemis/exceptions'
11
12
 
12
13
  module Artemis
13
14
  class GraphQLEndpoint
15
+
16
+ # Whether or not to suppress warnings on schema load. Use it with caution.
17
+ #
18
+ # @private
19
+ cattr_accessor :suppress_warnings_on_schema_load
20
+ self.suppress_warnings_on_schema_load = false
21
+
14
22
  # Hash object that holds references to adapter instances.
15
23
  ENDPOINT_INSTANCES = {}
16
24
 
@@ -46,9 +54,13 @@ module Artemis
46
54
  end
47
55
 
48
56
  def schema
57
+ org, $stderr = $stderr, File.new("/dev/null", "w") if self.class.suppress_warnings_on_schema_load
58
+
49
59
  @schema || @mutex_for_schema.synchronize do
50
60
  @schema ||= ::GraphQL::Client.load_schema(schema_path.presence || connection)
51
61
  end
62
+ ensure
63
+ $stderr = org if self.class.suppress_warnings_on_schema_load
52
64
  end
53
65
  alias load_schema! schema
54
66
 
@@ -58,4 +70,4 @@ module Artemis
58
70
  end
59
71
  end
60
72
  end
61
- end
73
+ end
@@ -31,13 +31,15 @@ module Artemis
31
31
  end
32
32
 
33
33
  initializer 'graphql.client.set_reloader', after: 'graphql.client.set_query_paths' do |app|
34
- files_to_watch = Artemis::Client.query_paths.map {|path| [path, config.artemis.graphql_extentions] }.to_h
34
+ if !config.respond_to?(:autoloader) || config.autoloader != :zeitwerk
35
+ files_to_watch = Artemis::Client.query_paths.map {|path| [path, config.artemis.graphql_extentions] }.to_h
35
36
 
36
- app.reloaders << ActiveSupport::FileUpdateChecker.new([], files_to_watch) do
37
- endpoint_names = app.config_for(:graphql).keys
38
- endpoint_names.each do |endpoint_name|
39
- Artemis::Client.query_paths.each do |path|
40
- FileUtils.touch("#{path}/#{endpoint_name}.rb")
37
+ app.reloaders << ActiveSupport::FileUpdateChecker.new([], files_to_watch) do
38
+ endpoint_names = Artemis.config_for_graphql(app).keys
39
+ endpoint_names.each do |endpoint_name|
40
+ Artemis::Client.query_paths.each do |path|
41
+ FileUtils.touch("#{path}/#{endpoint_name}.rb")
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -45,17 +47,17 @@ module Artemis
45
47
 
46
48
  initializer 'graphql.client.load_config' do |app|
47
49
  if Pathname.new("#{app.paths["config"].existent.first}/graphql.yml").exist?
48
- app.config_for(:graphql).each do |endpoint_name, options|
50
+ Artemis.config_for_graphql(app).each do |endpoint_name, options|
49
51
  Artemis::GraphQLEndpoint.register!(endpoint_name, {
50
- 'schema_path' => app.root.join(config.artemis.schema_path, "#{endpoint_name}.json").to_s
51
- }.merge(options))
52
+ schema_path: app.root.join(config.artemis.schema_path, "#{endpoint_name}.json").to_s
53
+ }.merge(options.symbolize_keys))
52
54
  end
53
55
  end
54
56
  end
55
57
 
56
58
  initializer 'graphql.client.preload', after: 'graphql.client.load_config' do |app|
57
- if app.config.eager_load
58
- app.config_for(:graphql).keys.each do |endpoint_name|
59
+ if app.config.eager_load && app.config.cache_classes
60
+ Artemis.config_for_graphql(app).keys.each do |endpoint_name|
59
61
  endpoint_name.to_s.camelize.constantize.preload!
60
62
  end
61
63
  end
@@ -65,4 +67,4 @@ module Artemis
65
67
  load "tasks/artemis.rake"
66
68
  end
67
69
  end
68
- end
70
+ end
@@ -9,7 +9,7 @@ require 'artemis/exceptions'
9
9
  module Artemis
10
10
  # TODO: Write documentation for +TestHelper+
11
11
  module TestHelper
12
- cattr_accessor :__graphql_fixture_path__
12
+ mattr_accessor :__graphql_fixture_path__
13
13
 
14
14
  # Creates an object that stubs a GraphQL request for the given +service+. No mock response is registered until the
15
15
  # +to_return+ method.
@@ -1,3 +1,3 @@
1
1
  module Artemis
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -56,7 +56,7 @@ YAML
56
56
  end
57
57
 
58
58
  def client_file_name
59
- if mountable_engine?
59
+ if respond_to?(:mountable_engine?) && mountable_engine?
60
60
  "app/operations/#{namespaced_path}/#{file_name}.rb"
61
61
  else
62
62
  "app/operations/#{file_name}.rb"
@@ -64,7 +64,7 @@ YAML
64
64
  end
65
65
 
66
66
  def query_dir_gitkeep
67
- if mountable_engine?
67
+ if respond_to?(:mountable_engine?) && mountable_engine?
68
68
  "app/operations/#{namespaced_path}/#{file_name}/.gitkeep"
69
69
  else
70
70
  "app/operations/#{file_name}/.gitkeep"
@@ -12,7 +12,7 @@ namespace :graphql do
12
12
  service = if ENV['SERVICE']
13
13
  ENV['SERVICE']
14
14
  else
15
- services = Rails.application.config_for(:graphql).keys
15
+ services = Artemis.config_for_graphql(Rails.application).keys
16
16
 
17
17
  if services.size == 1
18
18
  services.first
@@ -22,7 +22,7 @@ namespace :graphql do
22
22
  end
23
23
 
24
24
  headers = ENV['AUTHORIZATION'] ? { Authorization: ENV['AUTHORIZATION'] } : {}
25
- service_class = service.camelize.constantize
25
+ service_class = service.to_s.camelize.constantize
26
26
  schema_path = service_class.endpoint.schema_path
27
27
  schema = service_class.connection
28
28
  .execute(
@@ -44,4 +44,4 @@ namespace :graphql do
44
44
  end
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -5,7 +5,7 @@ describe 'Adapters' do
5
5
  FakeServer = ->(env) {
6
6
  case env['PATH_INFO']
7
7
  when '/slow_server'
8
- sleep 2.1
8
+ sleep 1.1
9
9
 
10
10
  [200, {}, ['{}']]
11
11
  when '/500'
@@ -14,7 +14,7 @@ describe 'Adapters' do
14
14
  body = {
15
15
  data: {
16
16
  body: JSON.parse(env['rack.input'].read),
17
- headers: env.select {|key, val| key.start_with?('HTTP_') }
17
+ headers: env.select {|key, val| key.match("^HTTP.*|^CONTENT.*|^AUTHORIZATION.*") }
18
18
  .collect {|key, val| [key.gsub(/^HTTP_/, ''), val.downcase] }
19
19
  .to_h,
20
20
  },
@@ -69,6 +69,8 @@ describe 'Adapters' do
69
69
  expect(response['data']['body']['query']).to eq(GraphQL::Client::IntrospectionDocument.to_query_string)
70
70
  expect(response['data']['body']['variables']).to eq('id' => 'yayoi-kusama')
71
71
  expect(response['data']['body']['operationName']).to eq('IntrospectionQuery')
72
+ expect(response['data']['headers']['CONTENT_TYPE']).to eq('application/json')
73
+ expect(response['data']['headers']['ACCEPT']).to eq('application/json')
72
74
  expect(response['errors']).to eq([])
73
75
  expect(response['extensions']).to eq({})
74
76
  end
@@ -92,14 +94,14 @@ describe 'Adapters' do
92
94
  end
93
95
 
94
96
  describe Artemis::Adapters::NetHttpAdapter do
95
- let(:adapter) { Artemis::Adapters::NetHttpAdapter.new('http://localhost:8000', service_name: nil, timeout: 2, pool_size: 5) }
97
+ let(:adapter) { Artemis::Adapters::NetHttpAdapter.new('http://localhost:8000', service_name: nil, timeout: 0.5, pool_size: 5) }
96
98
  let(:timeout_error) { Net::ReadTimeout }
97
99
 
98
100
  it_behaves_like 'an adapter'
99
101
  end
100
102
 
101
103
  describe Artemis::Adapters::NetHttpPersistentAdapter do
102
- let(:adapter) { Artemis::Adapters::NetHttpPersistentAdapter.new('http://localhost:8000', service_name: nil, timeout: 2, pool_size: 5) }
104
+ let(:adapter) { Artemis::Adapters::NetHttpPersistentAdapter.new('http://localhost:8000', service_name: nil, timeout: 0.5, pool_size: 5) }
103
105
  let(:timeout_error) { Net::HTTP::Persistent::Error }
104
106
 
105
107
  it_behaves_like 'an adapter'
@@ -111,4 +113,4 @@ describe 'Adapters' do
111
113
 
112
114
  it_behaves_like 'an adapter'
113
115
  end
114
- end
116
+ end
@@ -97,6 +97,31 @@ describe GraphQL::Client do
97
97
  GRAPHQL
98
98
  end
99
99
 
100
+ it "can make a GraphQL request with #execute" do
101
+ Metaphysics.execute(:artist, id: "yayoi-kusama")
102
+
103
+ request = requests[0]
104
+
105
+ expect(request.operation_name).to eq('Metaphysics__Artist')
106
+ expect(request.variables).to eq('id' => 'yayoi-kusama')
107
+ expect(request.context).to eq({})
108
+ expect(request.document.to_query_string).to eq(<<~GRAPHQL.strip)
109
+ query Metaphysics__Artist($id: String!) {
110
+ artist(id: $id) {
111
+ name
112
+ bio
113
+ birthday
114
+ }
115
+ }
116
+ GRAPHQL
117
+ end
118
+
119
+ it "can make a GraphQL request with #execute" do
120
+ expect { Metaphysics.execute(:does_not_exist) }
121
+ .to raise_error(Artemis::GraphQLFileNotFound)
122
+ .with_message(/Query does_not_exist\.graphql not found/)
123
+ end
124
+
100
125
  it "assigns context to the request when provided as an argument" do
101
126
  context = { headers: { Authorization: 'bearer ...' } }
102
127
 
@@ -158,4 +183,4 @@ describe GraphQL::Client do
158
183
  ensure
159
184
  files.each {|file| File.delete(file) }
160
185
  end
161
- end
186
+ end
@@ -12,6 +12,7 @@ require 'pry-byebug' if RUBY_ENGINE == 'ruby'
12
12
  # The only method that doesn't need test coverage is +Artemis::Client.query_paths+. The rest of the methods should be
13
13
  # tested, but we don't have any test setup for that yet.
14
14
  Artemis::Client.query_paths = [File.join(__dir__, 'fixtures')]
15
+ Artemis::GraphQLEndpoint.suppress_warnings_on_schema_load = true
15
16
  Artemis::GraphQLEndpoint.register!(:metaphysics, adapter: :test, url: '', schema_path: 'spec/fixtures/metaphysics/schema.json')
16
17
  Artemis::GraphQLEndpoint.lookup(:metaphysics).load_schema!
17
18
 
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.0
4
+ version: 0.5.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: 2019-01-30 00:00:00.000000000 Z
12
+ date: 2019-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,138 +17,138 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.0
20
+ version: 4.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 4.2.0
27
+ version: 4.0.0
28
28
  - !ruby/object:Gem::Dependency
29
- name: graphql
29
+ name: railties
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '1.8'
34
+ version: 4.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '1.8'
41
+ version: 4.0.0
42
42
  - !ruby/object:Gem::Dependency
43
- name: graphql-client
43
+ name: graphql
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: 0.13.0
48
+ version: '1.8'
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: 0.13.0
55
+ version: '1.8'
56
56
  - !ruby/object:Gem::Dependency
57
- name: railties
57
+ name: graphql-client
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 4.2.0
62
+ version: 0.13.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 4.2.0
69
+ version: 0.13.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: appraisal
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: '2.2'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.2'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: bundler
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '1.16'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '1.16'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: curb
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - "~>"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: 0.9.6
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - "~>"
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: 0.9.6
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: net-http-persistent
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: '3.0'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '3.0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "~>"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: '10.0'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "~>"
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '10.0'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rspec
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - "~>"
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '3.8'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - "~>"
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: '3.8'
154
154
  description: GraphQL client on Rails + Convention over Configuration = ❤️
@@ -170,15 +170,19 @@ files:
170
170
  - README.md
171
171
  - Rakefile
172
172
  - artemis.gemspec
173
+ - banner.png
173
174
  - bin/console
174
175
  - bin/setup
175
176
  - doc/CHANGELOG.md.erb
176
177
  - doc/changelog_generator.rb
177
178
  - gemfiles/.bundle/config
179
+ - gemfiles/rails_40.gemfile
180
+ - gemfiles/rails_41.gemfile
178
181
  - gemfiles/rails_42.gemfile
179
182
  - gemfiles/rails_50.gemfile
180
183
  - gemfiles/rails_51.gemfile
181
184
  - gemfiles/rails_52.gemfile
185
+ - gemfiles/rails_60.gemfile
182
186
  - gemfiles/rails_edge.gemfile
183
187
  - lib/artemis.rb
184
188
  - lib/artemis/adapters.rb
@@ -240,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
244
  - !ruby/object:Gem::Version
241
245
  version: '0'
242
246
  requirements: []
243
- rubyforge_project:
244
- rubygems_version: 2.7.6
247
+ rubygems_version: 3.0.3
245
248
  signing_key:
246
249
  specification_version: 4
247
250
  summary: GraphQL on Rails