graphql-hive 0.5.5 → 0.6.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +13 -0
- data/lib/graphql-hive/client.rb +37 -10
- data/lib/graphql-hive/version.rb +1 -1
- data/lib/graphql-hive.rb +24 -10
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49d7ea84eecb7ee527720752d5fed3179acfdc56a97abf71e7e009e79c860a00
|
|
4
|
+
data.tar.gz: 5f69430570fe93bf637be7726fecf57fb396243a177c1705130b0f8b5c4cef6e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d215ba7482205e18466b32d53f46fd9b2fcc18b3b0e144f5e824f844e856c904ab47d22153250f9529c44a3c3fea1ce4bdbccb548135018f61735e555c3d9825
|
|
7
|
+
data.tar.gz: b46ea3f3660e53d5c62e0c50b14f101740887d0b8256e4bada10f41cac540de632866bb039a6e9d66a9a3e444ee7684d9a960ea70cfb66a7b92872e29aee8e2a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
|
|
29
29
|
If you are using Hive as a service, please refer to our documentation: https://docs.graphql-hive.com/features/tokens.
|
|
30
30
|
|
|
31
|
+
### Organization-level tokens
|
|
32
|
+
|
|
33
|
+
If you are using an organization-level access token (tokens starting with `hvo1/`), you must also provide a `target` parameter to specify which target the usage data should be reported to. See the [organization access tokens documentation](https://the-guild.dev/graphql/hive/docs/migration-guides/organization-access-tokens#usage-data-reporting) for more details.
|
|
34
|
+
|
|
31
35
|
## 1. Install the `graphql-hive` gem
|
|
32
36
|
|
|
33
37
|
```
|
|
@@ -48,6 +52,8 @@ class Schema < GraphQL::Schema
|
|
|
48
52
|
GraphQL::Hive,
|
|
49
53
|
{
|
|
50
54
|
token: '<YOUR_TOKEN>',
|
|
55
|
+
# target is only needed if you're using an organization level token
|
|
56
|
+
target: 'your-org/your-project/production', # or target UUID
|
|
51
57
|
reporting: {
|
|
52
58
|
author: ENV['GITHUB_USER'],
|
|
53
59
|
commit: ENV['GITHUB_COMMIT']
|
|
@@ -148,6 +154,9 @@ class MySchema < GraphQL::Schema
|
|
|
148
154
|
{
|
|
149
155
|
# Token is the only required configuration value.
|
|
150
156
|
token: 'YOUR-REGISTRY-TOKEN',
|
|
157
|
+
# Target is required when using organization-level tokens (tokens starting with 'hvo1/').
|
|
158
|
+
# Can be a target slug (e.g., 'org/project/target') or target UUID.
|
|
159
|
+
target: 'your-org/your-project/production',
|
|
151
160
|
#
|
|
152
161
|
# The following are optional configuration values.
|
|
153
162
|
#
|
|
@@ -157,6 +166,10 @@ class MySchema < GraphQL::Schema
|
|
|
157
166
|
debug: false,
|
|
158
167
|
# A custom logger.
|
|
159
168
|
logger: MyLogger.new,
|
|
169
|
+
# Log request details at info level (default: false, logs at debug level). Details include request type, request path, and a unique request ID.
|
|
170
|
+
log_request_details: false,
|
|
171
|
+
# Log Hive errors (unsuccessful responses and exceptions) as warnings instead of errors (default: false, logs as errors).
|
|
172
|
+
warn_on_hive_errors: false,
|
|
160
173
|
# Endpoint and port of the Hive API. Change this if you are using a self-hosted Hive instance.
|
|
161
174
|
endpoint: 'app.graphql-hive.com',
|
|
162
175
|
port: 80,
|
data/lib/graphql-hive/client.rb
CHANGED
|
@@ -12,28 +12,36 @@ module GraphQL
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def send(path, body, _log_type)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
port: @options[:port] || "443",
|
|
20
|
-
path: path
|
|
21
|
-
)
|
|
15
|
+
path = path.to_s
|
|
16
|
+
if path == "/usage" && @options[:target] && @options[:target] != ""
|
|
17
|
+
path = "/usage/#{@options[:target]}"
|
|
18
|
+
end
|
|
22
19
|
|
|
20
|
+
scheme = (@options[:port].to_s == "443") ? "https" : "http"
|
|
21
|
+
endpoint = @options[:endpoint] || "app.graphql-hive.com"
|
|
22
|
+
uri = URI::HTTP.build(
|
|
23
|
+
scheme: scheme,
|
|
24
|
+
host: endpoint,
|
|
25
|
+
port: @options[:port] || "443",
|
|
26
|
+
path: path
|
|
27
|
+
)
|
|
23
28
|
http = setup_http(uri)
|
|
24
29
|
request = build_request(uri, body)
|
|
30
|
+
|
|
31
|
+
log_request(request, scheme, endpoint, path)
|
|
32
|
+
|
|
25
33
|
response = http.request(request)
|
|
26
34
|
|
|
27
35
|
code = response.code.to_i
|
|
28
36
|
if code >= 400 && code < 500
|
|
29
37
|
error_message = "Unsuccessful response: #{response.code} - #{response.message}"
|
|
30
|
-
|
|
38
|
+
log_error("#{error_message} #{extract_error_details(response)}")
|
|
31
39
|
end
|
|
32
40
|
|
|
33
41
|
@options[:logger].debug(response.inspect)
|
|
34
42
|
@options[:logger].debug(response.body.inspect)
|
|
35
43
|
rescue => e
|
|
36
|
-
|
|
44
|
+
log_error("Failed to send data: #{e}")
|
|
37
45
|
end
|
|
38
46
|
|
|
39
47
|
def setup_http(uri)
|
|
@@ -45,16 +53,27 @@ module GraphQL
|
|
|
45
53
|
|
|
46
54
|
def build_request(uri, body)
|
|
47
55
|
request = Net::HTTP::Post.new(uri.request_uri)
|
|
48
|
-
request["Authorization"] = @options[:token]
|
|
56
|
+
request["Authorization"] = "Bearer #{@options[:token]}"
|
|
49
57
|
request["X-Usage-API-Version"] = "2"
|
|
50
58
|
request["content-type"] = "application/json"
|
|
51
59
|
request["User-Agent"] = "Hive@#{Graphql::Hive::VERSION}"
|
|
52
60
|
request["graphql-client-name"] = "Hive Ruby Client"
|
|
53
61
|
request["graphql-client-version"] = Graphql::Hive::VERSION
|
|
62
|
+
request["X-Request-Id"] = SecureRandom.uuid
|
|
54
63
|
request.body = JSON.generate(body)
|
|
55
64
|
request
|
|
56
65
|
end
|
|
57
66
|
|
|
67
|
+
def log_request(request, scheme, endpoint, path)
|
|
68
|
+
log_message = "#{request.method} #{scheme}://#{endpoint}#{path} request id: #{request["X-Request-Id"]}"
|
|
69
|
+
|
|
70
|
+
if @options[:log_request_details]
|
|
71
|
+
@options[:logger].info(log_message)
|
|
72
|
+
else
|
|
73
|
+
@options[:logger].debug(log_message)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
58
77
|
def extract_error_details(response)
|
|
59
78
|
parsed_body = JSON.parse(response.body)
|
|
60
79
|
return unless parsed_body.is_a?(Hash) && parsed_body["errors"].is_a?(Array)
|
|
@@ -62,6 +81,14 @@ module GraphQL
|
|
|
62
81
|
rescue JSON::ParserError
|
|
63
82
|
"Could not parse response from Hive"
|
|
64
83
|
end
|
|
84
|
+
|
|
85
|
+
def log_error(message)
|
|
86
|
+
if @options[:warn_on_hive_errors]
|
|
87
|
+
@options[:logger].warn(message)
|
|
88
|
+
else
|
|
89
|
+
@options[:logger].error(message)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
65
92
|
end
|
|
66
93
|
end
|
|
67
94
|
end
|
data/lib/graphql-hive/version.rb
CHANGED
data/lib/graphql-hive.rb
CHANGED
|
@@ -39,7 +39,10 @@ module GraphQL
|
|
|
39
39
|
buffer_size: 50,
|
|
40
40
|
queue_size: 1000,
|
|
41
41
|
logger: nil,
|
|
42
|
-
collect_usage_sampling: 1.0
|
|
42
|
+
collect_usage_sampling: 1.0,
|
|
43
|
+
target: nil,
|
|
44
|
+
log_request_details: false,
|
|
45
|
+
warn_on_hive_errors: false
|
|
43
46
|
}.freeze
|
|
44
47
|
|
|
45
48
|
self.platform_keys = {
|
|
@@ -141,10 +144,14 @@ module GraphQL
|
|
|
141
144
|
}
|
|
142
145
|
options[:logger].level = options[:debug] ? Logger::DEBUG : Logger::INFO
|
|
143
146
|
end
|
|
144
|
-
if !options.include?(:token) && (!options.include?(:enabled) || options
|
|
147
|
+
if !options.include?(:token) && (!options.include?(:enabled) || options[:enabled])
|
|
145
148
|
options[:logger].warn("`token` options is missing")
|
|
146
149
|
options[:enabled] = false
|
|
147
150
|
false
|
|
151
|
+
elsif options[:token]&.start_with?("hvo1/") && (options[:target].nil? || options[:target] == "")
|
|
152
|
+
options[:logger].warn("Organization-level token detected but `target` option is missing. Target must be specified for organization-level tokens.")
|
|
153
|
+
options[:enabled] = false
|
|
154
|
+
false
|
|
148
155
|
elsif options[:report_schema] &&
|
|
149
156
|
(
|
|
150
157
|
!options.include?(:reporting) ||
|
|
@@ -168,18 +175,25 @@ module GraphQL
|
|
|
168
175
|
def send_report_schema(schema)
|
|
169
176
|
sdl = GraphQL::Schema::Printer.new(schema).print_schema
|
|
170
177
|
|
|
178
|
+
input = {
|
|
179
|
+
sdl: sdl,
|
|
180
|
+
author: @options[:reporting][:author],
|
|
181
|
+
commit: @options[:reporting][:commit],
|
|
182
|
+
service: @options[:reporting][:service_name],
|
|
183
|
+
url: @options[:reporting][:service_url],
|
|
184
|
+
force: true
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
# Add target for organization-level tokens
|
|
188
|
+
if @options[:target]
|
|
189
|
+
input[:target] = @options[:target]
|
|
190
|
+
end
|
|
191
|
+
|
|
171
192
|
body = {
|
|
172
193
|
query: REPORT_SCHEMA_MUTATION,
|
|
173
194
|
operationName: "schemaPublish",
|
|
174
195
|
variables: {
|
|
175
|
-
input:
|
|
176
|
-
sdl: sdl,
|
|
177
|
-
author: @options[:reporting][:author],
|
|
178
|
-
commit: @options[:reporting][:commit],
|
|
179
|
-
service: @options[:reporting][:service_name],
|
|
180
|
-
url: @options[:reporting][:service_url],
|
|
181
|
-
force: true
|
|
182
|
-
}
|
|
196
|
+
input: input
|
|
183
197
|
}
|
|
184
198
|
}
|
|
185
199
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphql-hive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Charly POLY
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-10-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: graphql
|
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
82
82
|
- !ruby/object:Gem::Version
|
|
83
83
|
version: '0'
|
|
84
84
|
requirements: []
|
|
85
|
-
rubygems_version: 3.5.
|
|
85
|
+
rubygems_version: 3.5.22
|
|
86
86
|
signing_key:
|
|
87
87
|
specification_version: 4
|
|
88
88
|
summary: '"GraphQL Hive integration for `graphql-ruby`"'
|