artemis 0.8.0 → 0.9.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 +6 -1
- data/Appraisals +9 -0
- data/CHANGELOG.md +16 -2
- data/artemis.gemspec +1 -1
- data/gemfiles/rails_71.gemfile +14 -0
- data/gemfiles/rails_edge.gemfile +1 -0
- data/lib/artemis/adapters/net_http_persistent_adapter.rb +6 -0
- data/lib/artemis/railtie.rb +1 -1
- data/lib/artemis/version.rb +1 -1
- data/spec/adapters_spec.rb +9 -2
- data/spec/autoloading_spec.rb +55 -49
- data/spec/callbacks_spec.rb +6 -6
- data/spec/client_spec.rb +84 -78
- data/spec/endpoint_spec.rb +11 -7
- data/spec/fixtures/github/_repository_fields.graphql +12 -0
- data/spec/fixtures/github/repository.graphql +6 -0
- data/spec/fixtures/github/schema.json +165225 -0
- data/spec/fixtures/github/user.graphql +6 -0
- data/spec/fixtures/github/user_repositories.graphql +13 -0
- data/spec/fixtures/github.rb +2 -0
- data/spec/fixtures/responses/github/repository.yml +17 -0
- data/spec/fixtures/responses/github/user.json +10 -0
- data/spec/spec_helper.rb +3 -3
- data/spec/test_helper_spec.rb +32 -32
- metadata +16 -15
- data/spec/fixtures/metaphysics/_artist_fields.graphql +0 -4
- data/spec/fixtures/metaphysics/artist.graphql +0 -7
- data/spec/fixtures/metaphysics/artists.graphql +0 -8
- data/spec/fixtures/metaphysics/artwork.graphql +0 -8
- data/spec/fixtures/metaphysics/schema.json +0 -49811
- data/spec/fixtures/metaphysics.rb +0 -2
- data/spec/fixtures/responses/metaphysics/artist.yml +0 -24
- data/spec/fixtures/responses/metaphysics/artwork.json +0 -12
data/spec/client_spec.rb
CHANGED
@@ -5,119 +5,128 @@ describe GraphQL::Client do
|
|
5
5
|
|
6
6
|
describe ".lookup_graphql_file" do
|
7
7
|
it "returns the path to the matching graph file" do
|
8
|
-
expect(
|
8
|
+
expect(Github.resolve_graphql_file_path("user")).to eq("#{PROJECT_DIR}/spec/fixtures/github/user.graphql")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns nil if the file is missing" do
|
12
|
-
expect(
|
12
|
+
expect(Github.resolve_graphql_file_path("does_not_exist")).to be_nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe ".graphql_file_paths" do
|
17
17
|
it "returns a list of GraphQL files (*.graphql) in the query_paths" do
|
18
|
-
|
19
|
-
original =
|
18
|
+
Github.instance_variable_set :@graphql_file_paths, nil
|
19
|
+
original = Github.query_paths
|
20
20
|
|
21
|
-
|
21
|
+
Github.query_paths = [File.join(PROJECT_DIR, 'tmp')]
|
22
22
|
|
23
23
|
begin
|
24
|
-
FileUtils.mkdir "./tmp/
|
24
|
+
FileUtils.mkdir "./tmp/github" if !Dir.exist?("./tmp/github")
|
25
25
|
|
26
|
-
with_files "./tmp/
|
27
|
-
expect(
|
26
|
+
with_files "./tmp/github/text.txt", "./tmp/github/sale.graphql" do
|
27
|
+
expect(Github.graphql_file_paths).to eq(["#{PROJECT_DIR}/tmp/github/sale.graphql"])
|
28
28
|
end
|
29
29
|
ensure
|
30
|
-
|
31
|
-
|
30
|
+
Github.instance_variable_set :@graphql_file_paths, nil
|
31
|
+
Github.query_paths = original
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can make a GraphQL request without variables" do
|
37
|
-
|
37
|
+
Github.user
|
38
38
|
|
39
39
|
request = requests[0]
|
40
40
|
|
41
|
-
expect(request.operation_name).to eq('
|
41
|
+
expect(request.operation_name).to eq('Github__User')
|
42
42
|
expect(request.variables).to be_empty
|
43
43
|
expect(request.context).to eq({})
|
44
44
|
expect(request.document.to_query_string).to eq(<<~GRAPHQL.strip)
|
45
|
-
query
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
name
|
50
|
-
}
|
45
|
+
query Github__User {
|
46
|
+
user(login: "yuki24") {
|
47
|
+
id
|
48
|
+
name
|
51
49
|
}
|
52
50
|
}
|
53
51
|
GRAPHQL
|
54
52
|
end
|
55
53
|
|
56
54
|
it "can make a GraphQL request with variables" do
|
57
|
-
|
55
|
+
Github.repository(owner: "yuki24", name: "artemis")
|
58
56
|
|
59
57
|
request = requests[0]
|
60
58
|
|
61
|
-
expect(request.operation_name).to eq('
|
62
|
-
expect(request.variables).to eq(
|
59
|
+
expect(request.operation_name).to eq('Github__Repository')
|
60
|
+
expect(request.variables).to eq("owner" => "yuki24", "name" => "artemis")
|
63
61
|
expect(request.context).to eq({})
|
64
62
|
expect(request.document.to_query_string).to eq(<<~GRAPHQL.strip)
|
65
|
-
query
|
66
|
-
|
63
|
+
query Github__Repository($owner: String!, $name: String!) {
|
64
|
+
repository(owner: $owner, name: $name) {
|
67
65
|
name
|
68
|
-
|
69
|
-
birthday
|
66
|
+
nameWithOwner
|
70
67
|
}
|
71
68
|
}
|
72
69
|
GRAPHQL
|
73
70
|
end
|
74
71
|
|
75
72
|
it "can make a GraphQL request with a query that contains fragments" do
|
76
|
-
|
73
|
+
Github.user_repositories(login: "yuki24", size: 10)
|
77
74
|
|
78
75
|
request = requests[0]
|
79
76
|
|
80
|
-
expect(request.operation_name).to eq('
|
81
|
-
expect(request.variables).to eq('size' => 10)
|
77
|
+
expect(request.operation_name).to eq('Github__UserRepositories')
|
78
|
+
expect(request.variables).to eq('login' => 'yuki24', 'size' => 10)
|
82
79
|
expect(request.context).to eq({})
|
83
80
|
expect(request.document.to_query_string).to eq(<<~GRAPHQL.strip)
|
84
|
-
query
|
85
|
-
|
81
|
+
query Github__UserRepositories($login: String!, $size: Int!) {
|
82
|
+
user(login: $login) {
|
83
|
+
id
|
86
84
|
name
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
repositories(first: $size) {
|
86
|
+
nodes {
|
87
|
+
name
|
88
|
+
description
|
89
|
+
...Github__RepositoryFields
|
90
|
+
}
|
91
|
+
}
|
90
92
|
}
|
91
93
|
}
|
92
94
|
|
93
|
-
fragment
|
94
|
-
|
95
|
-
|
95
|
+
fragment Github__RepositoryFields on Repository {
|
96
|
+
name
|
97
|
+
nameWithOwner
|
98
|
+
url
|
99
|
+
updatedAt
|
100
|
+
languages(first: 1) {
|
101
|
+
nodes {
|
102
|
+
name
|
103
|
+
color
|
104
|
+
}
|
105
|
+
}
|
96
106
|
}
|
97
107
|
GRAPHQL
|
98
108
|
end
|
99
109
|
|
100
110
|
it "can make a GraphQL request with #execute" do
|
101
|
-
|
111
|
+
Github.execute(:repository, owner: "yuki24", name: "artemis")
|
102
112
|
|
103
113
|
request = requests[0]
|
104
114
|
|
105
|
-
expect(request.operation_name).to eq('
|
106
|
-
expect(request.variables).to eq(
|
115
|
+
expect(request.operation_name).to eq('Github__Repository')
|
116
|
+
expect(request.variables).to eq("owner" => "yuki24", "name" => "artemis")
|
107
117
|
expect(request.context).to eq({})
|
108
118
|
expect(request.document.to_query_string).to eq(<<~GRAPHQL.strip)
|
109
|
-
query
|
110
|
-
|
119
|
+
query Github__Repository($owner: String!, $name: String!) {
|
120
|
+
repository(owner: $owner, name: $name) {
|
111
121
|
name
|
112
|
-
|
113
|
-
birthday
|
122
|
+
nameWithOwner
|
114
123
|
}
|
115
124
|
}
|
116
125
|
GRAPHQL
|
117
126
|
end
|
118
127
|
|
119
|
-
it "
|
120
|
-
expect {
|
128
|
+
it "raises an error when the specified graphql file does not exist" do
|
129
|
+
expect { Github.execute(:does_not_exist) }
|
121
130
|
.to raise_error(Artemis::GraphQLFileNotFound)
|
122
131
|
.with_message(/Query does_not_exist\.graphql not found/)
|
123
132
|
end
|
@@ -125,17 +134,17 @@ describe GraphQL::Client do
|
|
125
134
|
it "assigns context to the request when provided as an argument" do
|
126
135
|
context = { headers: { Authorization: 'bearer ...' } }
|
127
136
|
|
128
|
-
|
137
|
+
Github.repository(owner: "yuki24", name: "artemis", context: context)
|
129
138
|
|
130
139
|
expect(requests[0].context).to eq(context)
|
131
140
|
end
|
132
141
|
|
133
142
|
it "can create a client that always assigns the provided context to the request" do
|
134
143
|
context = { headers: { Authorization: 'bearer ...' } }
|
135
|
-
client =
|
144
|
+
client = Github.with_context(context)
|
136
145
|
|
137
|
-
client.
|
138
|
-
client.
|
146
|
+
client.repository(owner: "yuki24", name: "artemis")
|
147
|
+
client.repository(owner: "yuki24", name: "artemis")
|
139
148
|
|
140
149
|
expect(requests[0].context).to eq(context)
|
141
150
|
expect(requests[1].context).to eq(context)
|
@@ -143,21 +152,21 @@ describe GraphQL::Client do
|
|
143
152
|
|
144
153
|
it "assigns the default context to a GraphQL request if present" do
|
145
154
|
begin
|
146
|
-
|
147
|
-
|
155
|
+
Github.default_context = { headers: { Authorization: 'bearer ...' } }
|
156
|
+
Github.repository(owner: "yuki24", name: "artemis")
|
148
157
|
|
149
158
|
expect(requests[0].context).to eq(headers: { Authorization: 'bearer ...' })
|
150
159
|
ensure
|
151
|
-
|
160
|
+
Github.default_context = { }
|
152
161
|
end
|
153
162
|
end
|
154
163
|
|
155
164
|
it "can make a GraphQL request with all of .default_context, with_context(...) and the :context argument" do
|
156
165
|
begin
|
157
|
-
|
158
|
-
|
166
|
+
Github.default_context = { headers: { 'User-Agent': 'Artemis', 'X-key': 'value', Authorization: 'token ...' } }
|
167
|
+
Github
|
159
168
|
.with_context({ headers: { 'X-key': 'overridden' } })
|
160
|
-
.
|
169
|
+
.repository(owner: "yuki24", name: "artemis", context: { headers: { Authorization: 'bearer ...' } })
|
161
170
|
|
162
171
|
expect(requests[0].context).to eq(
|
163
172
|
headers: {
|
@@ -167,41 +176,38 @@ describe GraphQL::Client do
|
|
167
176
|
}
|
168
177
|
)
|
169
178
|
ensure
|
170
|
-
|
179
|
+
Github.default_context = { }
|
171
180
|
end
|
172
181
|
end
|
173
182
|
|
174
183
|
it "can batch multiple requests using Multiplex" do
|
175
|
-
|
176
|
-
queue.
|
177
|
-
queue.
|
184
|
+
Github.multiplex do |queue|
|
185
|
+
queue.repository(owner: "yuki24", name: "artemis", context: { headers: { Authorization: 'bearer ...' } })
|
186
|
+
queue.user
|
178
187
|
end
|
179
188
|
|
180
|
-
|
189
|
+
repository_query, user_query = requests[0].queries
|
181
190
|
|
182
|
-
expect(
|
183
|
-
expect(
|
184
|
-
expect(
|
185
|
-
expect(
|
186
|
-
query
|
187
|
-
|
191
|
+
expect(repository_query[:operationName]).to eq('Github__Repository')
|
192
|
+
expect(repository_query[:variables]).to eq("owner" => "yuki24", "name" => "artemis")
|
193
|
+
expect(repository_query[:context]).to eq({ headers: { Authorization: 'bearer ...' } })
|
194
|
+
expect(repository_query[:query]).to eq(<<~GRAPHQL.strip)
|
195
|
+
query Github__Repository($owner: String!, $name: String!) {
|
196
|
+
repository(owner: $owner, name: $name) {
|
188
197
|
name
|
189
|
-
|
190
|
-
birthday
|
198
|
+
nameWithOwner
|
191
199
|
}
|
192
200
|
}
|
193
201
|
GRAPHQL
|
194
202
|
|
195
|
-
expect(
|
196
|
-
expect(
|
197
|
-
expect(
|
198
|
-
expect(
|
199
|
-
query
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
name
|
204
|
-
}
|
203
|
+
expect(user_query[:operationName]).to eq('Github__User')
|
204
|
+
expect(user_query[:variables]).to be_empty
|
205
|
+
expect(user_query[:context]).to eq({})
|
206
|
+
expect(user_query[:query]).to eq(<<~GRAPHQL.strip)
|
207
|
+
query Github__User {
|
208
|
+
user(login: "yuki24") {
|
209
|
+
id
|
210
|
+
name
|
205
211
|
}
|
206
212
|
}
|
207
213
|
GRAPHQL
|
data/spec/endpoint_spec.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
describe Artemis::GraphQLEndpoint do
|
2
|
+
after do
|
3
|
+
Artemis::GraphQLEndpoint.const_get(:ENDPOINT_INSTANCES).delete("gitlab")
|
4
|
+
end
|
5
|
+
|
2
6
|
describe ".lookup" do
|
3
7
|
it "raises an exception when the service is missing" do
|
4
8
|
expect { Artemis::GraphQLEndpoint.lookup(:does_not_exit) }.to raise_error(Artemis::EndpointNotFound)
|
@@ -6,18 +10,18 @@ describe Artemis::GraphQLEndpoint do
|
|
6
10
|
end
|
7
11
|
|
8
12
|
it "can register an endpoint" do
|
9
|
-
endpoint = Artemis::GraphQLEndpoint.register!(:
|
13
|
+
endpoint = Artemis::GraphQLEndpoint.register!(:gitlab, url: "https://api.gitlab.com/graphql")
|
10
14
|
|
11
|
-
expect(endpoint.url).to eq("https://api.
|
15
|
+
expect(endpoint.url).to eq("https://api.gitlab.com/graphql")
|
12
16
|
expect(endpoint.connection).to be_instance_of(Artemis::Adapters::NetHttpAdapter)
|
13
17
|
end
|
14
18
|
|
15
19
|
it "can look up a registered endpoint" do
|
16
|
-
Artemis::GraphQLEndpoint.register!(:
|
20
|
+
Artemis::GraphQLEndpoint.register!(:gitlab, url: "https://api.gitlab.com/graphql")
|
17
21
|
|
18
|
-
endpoint = Artemis::GraphQLEndpoint.lookup(:
|
22
|
+
endpoint = Artemis::GraphQLEndpoint.lookup(:gitlab)
|
19
23
|
|
20
|
-
expect(endpoint.url).to eq("https://api.
|
24
|
+
expect(endpoint.url).to eq("https://api.gitlab.com/graphql")
|
21
25
|
expect(endpoint.connection).to be_instance_of(Artemis::Adapters::NetHttpAdapter) # Not a fan of this test but for now
|
22
26
|
|
23
27
|
# FIXME: This #schema method makes a network call.
|
@@ -32,9 +36,9 @@ describe Artemis::GraphQLEndpoint do
|
|
32
36
|
pool_size: 25,
|
33
37
|
}
|
34
38
|
|
35
|
-
endpoint = Artemis::GraphQLEndpoint.register!(:
|
39
|
+
endpoint = Artemis::GraphQLEndpoint.register!(:gitlab, url: "https://api.gitlab.com/graphql", **options)
|
36
40
|
|
37
|
-
expect(endpoint.url).to eq("https://api.
|
41
|
+
expect(endpoint.url).to eq("https://api.gitlab.com/graphql")
|
38
42
|
expect(endpoint.timeout).to eq(10)
|
39
43
|
expect(endpoint.pool_size).to eq(25)
|
40
44
|
expect(endpoint.connection).to be_instance_of(Artemis::Adapters::TestAdapter) # Not a fan of this test but for now
|