graphql-hive 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +12 -19
- data/.gitignore +6 -0
- data/.rubocop.yml +10 -41
- data/.ruby-version +1 -0
- data/Gemfile +13 -1
- data/Gemfile.lock +75 -12
- data/README.md +47 -35
- data/Rakefile +3 -3
- data/graphql-hive.gemspec +15 -20
- data/lib/graphql-hive/analyzer.rb +1 -1
- data/lib/graphql-hive/client.rb +13 -13
- data/lib/graphql-hive/printer.rb +17 -17
- data/lib/graphql-hive/sampler.rb +15 -15
- data/lib/graphql-hive/sampling/basic_sampler.rb +1 -1
- data/lib/graphql-hive/sampling/dynamic_sampler.rb +1 -1
- data/lib/graphql-hive/sampling/sampling_context.rb +1 -1
- data/lib/graphql-hive/usage_reporter.rb +29 -25
- data/lib/graphql-hive/version.rb +1 -1
- data/lib/graphql-hive.rb +31 -28
- metadata +3 -73
- data/.github/workflows/benchmark.yml +0 -67
- data/examples/simple-api/Gemfile +0 -8
- data/examples/simple-api/Gemfile.lock +0 -48
- data/examples/simple-api/app.rb +0 -31
- data/examples/simple-api/config.ru +0 -2
- data/examples/simple-api/schema.rb +0 -52
- data/k6/graphql-api/Gemfile +0 -9
- data/k6/graphql-api/Gemfile.lock +0 -52
- data/k6/graphql-api/app.rb +0 -26
- data/k6/graphql-api/config.ru +0 -2
- data/k6/graphql-api/schema.rb +0 -41
- data/k6/k6.js +0 -99
- data/k6/package.json +0 -11
- data/k6/usage-api.js +0 -26
- data/k6/yarn.lock +0 -405
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4176f281928e52d551ae77d96f837f449e32ecc4636d9f3c160c6c36121cef43
|
4
|
+
data.tar.gz: 71b3d0d1740cd707321c4970ad608fd73cae893561a6aa51b6ef288c2a955fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dd8fe627ef820bb26b8c20a3eb5fb9946bd87b4d3c36cff52c508f02aca17645ebc105314ada908b2dd926b176134e8e83d6c86b891849b5cf3c98d86db1ad0
|
7
|
+
data.tar.gz: b66d19f472e1e0034ae4eb42ab7f1ec14814216a6e7e71660aaaec4948c9b85287f947595043a41d9b31f7308cf9039af2978ef4af59f5edc2ed822410d890f8
|
data/.github/workflows/ci.yml
CHANGED
@@ -8,33 +8,26 @@ on:
|
|
8
8
|
- master
|
9
9
|
|
10
10
|
jobs:
|
11
|
-
|
11
|
+
standard:
|
12
12
|
runs-on: ubuntu-latest
|
13
13
|
steps:
|
14
|
-
|
15
|
-
|
16
|
-
- uses: ruby/setup-ruby@2a9a743e19810b9f3c38060637daf594dbd7b37f
|
17
|
-
with:
|
18
|
-
ruby-version: '3.3'
|
19
|
-
bundler-cache: true
|
20
|
-
|
21
|
-
- run: bundle exec rake rubocop
|
22
|
-
|
14
|
+
- name: Standard Ruby
|
15
|
+
uses: standardrb/standard-ruby-action@v1
|
23
16
|
test:
|
24
17
|
strategy:
|
25
18
|
fail-fast: false
|
26
19
|
matrix:
|
27
20
|
ruby-version:
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
21
|
+
- "3.1"
|
22
|
+
- "3.2"
|
23
|
+
- "3.3"
|
31
24
|
runs-on: ubuntu-latest
|
32
25
|
steps:
|
33
|
-
|
26
|
+
- uses: actions/checkout@v4
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
- uses: ruby/setup-ruby@2a9a743e19810b9f3c38060637daf594dbd7b37f
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby-version }}
|
31
|
+
bundler-cache: true
|
39
32
|
|
40
|
-
|
33
|
+
- run: bundle exec rake spec
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,41 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Metrics/BlockLength:
|
12
|
-
Exclude:
|
13
|
-
- 'spec/**/*'
|
14
|
-
|
15
|
-
Layout/LineLength:
|
16
|
-
Exclude:
|
17
|
-
- 'spec/**/*'
|
18
|
-
|
19
|
-
Naming/FileName:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Style/ClassVars:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Metrics/AbcSize:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Metrics/PerceivedComplexity:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Metrics/CyclomaticComplexity:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Metrics/MethodLength:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Metrics/ClassLength:
|
38
|
-
Enabled: false
|
39
|
-
|
40
|
-
Gemspec/DevelopmentDependencies:
|
41
|
-
EnforcedStyle: 'gemspec'
|
1
|
+
require:
|
2
|
+
- standard
|
3
|
+
- standard-custom
|
4
|
+
- standard-performance
|
5
|
+
- rubocop-performance
|
6
|
+
|
7
|
+
inherit_gem:
|
8
|
+
standard: config/base.yml
|
9
|
+
standard-custom: config/base.yml
|
10
|
+
standard-performance: config/base.yml
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.5
|
data/Gemfile
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
7
|
# Specify your gem's dependencies in graphql-hive.gemspec
|
8
8
|
gemspec
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "bundler", "~> 2"
|
12
|
+
gem "debug", ">= 1.0.0"
|
13
|
+
gem "rack-test", "~> 2"
|
14
|
+
gem "rake", "~> 13"
|
15
|
+
gem "rspec", "~> 3"
|
16
|
+
gem "sinatra", "~> 2"
|
17
|
+
gem "standardrb", "~> 1"
|
18
|
+
gem "vcr", "~> 6"
|
19
|
+
gem "webmock", "~> 3"
|
20
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql-hive (0.
|
4
|
+
graphql-hive (0.5.1)
|
5
5
|
graphql (>= 2.3, < 3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
addressable (2.8.7)
|
11
|
+
public_suffix (>= 2.0.2, < 7.0)
|
10
12
|
ast (2.4.2)
|
11
13
|
base64 (0.2.0)
|
14
|
+
bigdecimal (3.1.8)
|
15
|
+
crack (1.0.0)
|
16
|
+
bigdecimal
|
17
|
+
rexml
|
18
|
+
debug (1.9.2)
|
19
|
+
irb (~> 1.10)
|
20
|
+
reline (>= 0.3.8)
|
12
21
|
diff-lcs (1.5.1)
|
13
22
|
graphql (2.3.7)
|
14
23
|
base64
|
24
|
+
hashdiff (1.1.1)
|
25
|
+
io-console (0.7.2)
|
26
|
+
irb (1.14.1)
|
27
|
+
rdoc (>= 4.0.0)
|
28
|
+
reline (>= 0.4.2)
|
15
29
|
json (2.7.2)
|
16
30
|
language_server-protocol (3.17.0.3)
|
17
|
-
|
18
|
-
|
31
|
+
lint_roller (1.1.0)
|
32
|
+
mustermann (2.0.2)
|
33
|
+
ruby2_keywords (~> 0.0.1)
|
34
|
+
parallel (1.26.3)
|
35
|
+
parser (3.3.5.0)
|
19
36
|
ast (~> 2.4.1)
|
20
37
|
racc
|
21
|
-
|
38
|
+
psych (5.1.2)
|
39
|
+
stringio
|
40
|
+
public_suffix (6.0.1)
|
41
|
+
racc (1.8.1)
|
42
|
+
rack (2.2.10)
|
43
|
+
rack-protection (2.2.4)
|
44
|
+
rack
|
45
|
+
rack-test (2.1.0)
|
46
|
+
rack (>= 1.3)
|
22
47
|
rainbow (3.1.1)
|
23
48
|
rake (13.2.1)
|
49
|
+
rdoc (6.7.0)
|
50
|
+
psych (>= 4.0.0)
|
24
51
|
regexp_parser (2.9.2)
|
25
|
-
|
26
|
-
|
52
|
+
reline (0.5.10)
|
53
|
+
io-console (~> 0.5)
|
54
|
+
rexml (3.3.8)
|
27
55
|
rspec (3.13.0)
|
28
56
|
rspec-core (~> 3.13.0)
|
29
57
|
rspec-expectations (~> 3.13.0)
|
@@ -37,22 +65,52 @@ GEM
|
|
37
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
66
|
rspec-support (~> 3.13.0)
|
39
67
|
rspec-support (3.13.1)
|
40
|
-
rubocop (1.
|
68
|
+
rubocop (1.65.1)
|
41
69
|
json (~> 2.3)
|
42
70
|
language_server-protocol (>= 3.17.0)
|
43
71
|
parallel (~> 1.10)
|
44
72
|
parser (>= 3.3.0.2)
|
45
73
|
rainbow (>= 2.2.2, < 4.0)
|
46
|
-
regexp_parser (>=
|
74
|
+
regexp_parser (>= 2.4, < 3.0)
|
47
75
|
rexml (>= 3.2.5, < 4.0)
|
48
76
|
rubocop-ast (>= 1.31.1, < 2.0)
|
49
77
|
ruby-progressbar (~> 1.7)
|
50
78
|
unicode-display_width (>= 2.4.0, < 3.0)
|
51
|
-
rubocop-ast (1.
|
79
|
+
rubocop-ast (1.32.3)
|
52
80
|
parser (>= 3.3.1.0)
|
81
|
+
rubocop-performance (1.21.1)
|
82
|
+
rubocop (>= 1.48.1, < 2.0)
|
83
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
53
84
|
ruby-progressbar (1.13.0)
|
54
|
-
|
55
|
-
|
85
|
+
ruby2_keywords (0.0.5)
|
86
|
+
sinatra (2.2.4)
|
87
|
+
mustermann (~> 2.0)
|
88
|
+
rack (~> 2.2)
|
89
|
+
rack-protection (= 2.2.4)
|
90
|
+
tilt (~> 2.0)
|
91
|
+
standard (1.40.1)
|
92
|
+
language_server-protocol (~> 3.17.0.2)
|
93
|
+
lint_roller (~> 1.0)
|
94
|
+
rubocop (~> 1.65.0)
|
95
|
+
standard-custom (~> 1.0.0)
|
96
|
+
standard-performance (~> 1.4)
|
97
|
+
standard-custom (1.0.2)
|
98
|
+
lint_roller (~> 1.0)
|
99
|
+
rubocop (~> 1.50)
|
100
|
+
standard-performance (1.4.0)
|
101
|
+
lint_roller (~> 1.1)
|
102
|
+
rubocop-performance (~> 1.21.0)
|
103
|
+
standardrb (1.0.1)
|
104
|
+
standard
|
105
|
+
stringio (3.1.1)
|
106
|
+
tilt (2.4.0)
|
107
|
+
unicode-display_width (2.6.0)
|
108
|
+
vcr (6.3.1)
|
109
|
+
base64
|
110
|
+
webmock (3.24.0)
|
111
|
+
addressable (>= 2.8.0)
|
112
|
+
crack (>= 0.3.2)
|
113
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
56
114
|
|
57
115
|
PLATFORMS
|
58
116
|
arm64-darwin-23
|
@@ -60,10 +118,15 @@ PLATFORMS
|
|
60
118
|
|
61
119
|
DEPENDENCIES
|
62
120
|
bundler (~> 2)
|
121
|
+
debug (>= 1.0.0)
|
63
122
|
graphql-hive!
|
123
|
+
rack-test (~> 2)
|
64
124
|
rake (~> 13)
|
65
125
|
rspec (~> 3)
|
66
|
-
|
126
|
+
sinatra (~> 2)
|
127
|
+
standardrb (~> 1)
|
128
|
+
vcr (~> 6)
|
129
|
+
webmock (~> 3)
|
67
130
|
|
68
131
|
BUNDLED WITH
|
69
132
|
2.5.15
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# GraphQL Hive: `graphql-ruby` integration
|
1
|
+
# GraphQL Hive: `graphql-ruby` integration
|
2
2
|
[![CI Suite](https://github.com/charlypoly/graphql-ruby-hive/actions/workflows/ci.yml/badge.svg)](https://github.com/charlypoly/graphql-ruby-hive/actions)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/graphql-hive.svg)](https://rubygems.org/gems/graphql-hive)
|
4
4
|
|
@@ -146,39 +146,53 @@ class MySchema < GraphQL::Schema
|
|
146
146
|
use(
|
147
147
|
GraphQL::Hive,
|
148
148
|
{
|
149
|
-
#
|
150
|
-
token: 'YOUR-TOKEN',
|
151
|
-
|
152
|
-
# optional
|
153
|
-
|
154
|
-
|
149
|
+
# Token is the only required configuration value.
|
150
|
+
token: 'YOUR-REGISTRY-TOKEN',
|
151
|
+
#
|
152
|
+
# The following are optional configuration values.
|
153
|
+
#
|
154
|
+
# Enable/disable Hive Client.
|
155
|
+
enabled: true,
|
156
|
+
# Verbose logs.
|
157
|
+
debug: false,
|
158
|
+
# A custom logger.
|
155
159
|
logger: MyLogger.new,
|
160
|
+
# Endpoint and port of the Hive API. Change this if you are using a self-hosted Hive instance.
|
156
161
|
endpoint: 'app.graphql-hive.com',
|
157
|
-
port: 80,
|
158
|
-
|
159
|
-
|
160
|
-
|
162
|
+
port: 80,
|
163
|
+
# Number of operations sent to Hive in a batch (AFTER sampling).
|
164
|
+
buffer_size: 50,
|
165
|
+
# Size of the queue used to send operations to the buffer before sampling.
|
166
|
+
queue_size: 1000,
|
167
|
+
# Report usage to Hive.
|
168
|
+
collect_usage: true,
|
169
|
+
# Usage sampling configurations.
|
161
170
|
collect_usage_sampling: {
|
162
|
-
#
|
163
|
-
sample_rate: 0.5,
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
171
|
+
# % of operations recorded.
|
172
|
+
sample_rate: 0.5,
|
173
|
+
# Custom sampler to assign custom sampling rates.
|
174
|
+
sampler: proc { |context| context.operation_name.includes?('someQuery') 1 : 0.5 },
|
175
|
+
# Sample every distinct operation at least once.
|
176
|
+
at_least_once: true,
|
177
|
+
# Assign custom keys to distinguish between distinct operations.
|
178
|
+
key_generator: proc { |context| context.operation_name }
|
179
|
+
},
|
180
|
+
# Publish schema to Hive.
|
181
|
+
report_schema: true,
|
182
|
+
# Mandatory if `report_schema: true`.
|
183
|
+
reporting: {
|
184
|
+
# Mandatory members of `reporting`.
|
173
185
|
author: 'Author of the latest change',
|
174
186
|
commit: 'git sha or any identifier',
|
175
|
-
#
|
187
|
+
# Optional members of `reporting`.
|
176
188
|
service_name: '',
|
177
189
|
service_url: '',
|
178
190
|
},
|
179
191
|
|
180
|
-
|
181
|
-
client_info: proc { |context|
|
192
|
+
# Pass an optional proc to client_info to help identify the client (ex: Apollo web app) that performed the query.
|
193
|
+
client_info: proc { |context|
|
194
|
+
{ name: context.client_name, version: context.client_version }
|
195
|
+
}
|
182
196
|
}
|
183
197
|
)
|
184
198
|
|
@@ -187,16 +201,14 @@ class MySchema < GraphQL::Schema
|
|
187
201
|
end
|
188
202
|
```
|
189
203
|
|
190
|
-
See default options for the optional parameters [here](https://github.com/
|
204
|
+
See default options for the optional parameters [here](https://github.com/rperryng/graphql-ruby-hive/blob/master/lib/graphql-hive.rb#L31-L41).
|
191
205
|
|
192
206
|
<br/>
|
193
207
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
However, please note that a higher `buffer_size` value will introduce some peak of increase in memory consumption.
|
208
|
+
> [!Important]
|
209
|
+
> `buffer_size` and `queue_size` will affect memory consumption.
|
210
|
+
>
|
211
|
+
> `buffer_size` is the number of operations sent to Hive in a batch after operations have been sampled.
|
212
|
+
> `queue_size` is the size of the queue used to send operations to the buffer before sampling.
|
213
|
+
> Adjust these values according to your application's memory constraints and throughput.
|
214
|
+
> High throughput applications will need a larger `queue_size`.
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require "rubocop/rake_task"
|
9
9
|
RuboCop::RakeTask.new
|
10
10
|
|
11
11
|
task(default: %i[spec rubocop])
|
data/graphql-hive.gemspec
CHANGED
@@ -1,33 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
5
|
+
require "graphql-hive/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
8
|
+
spec.name = "graphql-hive"
|
9
|
+
spec.version = Graphql::Hive::VERSION
|
10
|
+
spec.authors = ["Charly POLY"]
|
11
|
+
spec.email = ["cpoly55@gmail.com"]
|
12
12
|
|
13
|
-
spec.summary
|
14
|
-
spec.description
|
15
|
-
spec.homepage
|
16
|
-
spec.license
|
13
|
+
spec.summary = '"GraphQL Hive integration for `graphql-ruby`"'
|
14
|
+
spec.description = '"Monitor operations, inspect your queries and publish your GraphQL schema with GraphQL Hive"'
|
15
|
+
spec.homepage = "https://docs.graphql-hive.com/specs/integrations"
|
16
|
+
spec.license = "MIT"
|
17
17
|
|
18
|
-
spec.metadata
|
18
|
+
spec.metadata = {"rubygems_mfa_required" => "true"}
|
19
19
|
|
20
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
21
21
|
|
22
|
-
spec.require_paths = [
|
23
|
-
spec.files
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
25
|
end
|
26
26
|
|
27
|
-
spec.add_dependency
|
28
|
-
|
29
|
-
spec.add_development_dependency 'bundler', '~> 2'
|
30
|
-
spec.add_development_dependency 'rake', '~> 13'
|
31
|
-
spec.add_development_dependency 'rspec', '~> 3'
|
32
|
-
spec.add_development_dependency 'rubocop', '~> 1'
|
27
|
+
spec.add_dependency "graphql", ">= 2.3", "< 3"
|
33
28
|
end
|
data/lib/graphql-hive/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
5
|
|
6
6
|
module GraphQL
|
7
7
|
class Hive < GraphQL::Tracing::PlatformTracing
|
@@ -14,9 +14,9 @@ module GraphQL
|
|
14
14
|
def send(path, body, _log_type)
|
15
15
|
uri =
|
16
16
|
URI::HTTP.build(
|
17
|
-
scheme: @options[:port].to_s ==
|
18
|
-
host: @options[:endpoint] ||
|
19
|
-
port: @options[:port] ||
|
17
|
+
scheme: (@options[:port].to_s == "443") ? "https" : "http",
|
18
|
+
host: @options[:endpoint] || "app.graphql-hive.com",
|
19
|
+
port: @options[:port] || "443",
|
20
20
|
path: path
|
21
21
|
)
|
22
22
|
|
@@ -26,25 +26,25 @@ module GraphQL
|
|
26
26
|
|
27
27
|
@options[:logger].debug(response.inspect)
|
28
28
|
@options[:logger].debug(response.body.inspect)
|
29
|
-
rescue
|
29
|
+
rescue => e
|
30
30
|
@options[:logger].fatal("Failed to send data: #{e}")
|
31
31
|
end
|
32
32
|
|
33
33
|
def setup_http(uri)
|
34
34
|
http = ::Net::HTTP.new(uri.host, uri.port)
|
35
|
-
http.use_ssl = @options[:port].to_s ==
|
35
|
+
http.use_ssl = @options[:port].to_s == "443"
|
36
36
|
http.read_timeout = 2
|
37
37
|
http
|
38
38
|
end
|
39
39
|
|
40
40
|
def build_request(uri, body)
|
41
41
|
request = Net::HTTP::Post.new(uri.request_uri)
|
42
|
-
request[
|
43
|
-
request[
|
44
|
-
request[
|
45
|
-
request[
|
46
|
-
request[
|
47
|
-
request[
|
42
|
+
request["Authorization"] = @options[:token]
|
43
|
+
request["X-Usage-API-Version"] = "2"
|
44
|
+
request["content-type"] = "application/json"
|
45
|
+
request["User-Agent"] = "Hive@#{Graphql::Hive::VERSION}"
|
46
|
+
request["graphql-client-name"] = "Hive Ruby Client"
|
47
|
+
request["graphql-client-version"] = Graphql::Hive::VERSION
|
48
48
|
request.body = JSON.generate(body)
|
49
49
|
request
|
50
50
|
end
|
data/lib/graphql-hive/printer.rb
CHANGED
@@ -10,12 +10,12 @@ module GraphQL
|
|
10
10
|
@out.append(str)
|
11
11
|
end
|
12
12
|
|
13
|
-
def print_node(node, indent:
|
13
|
+
def print_node(node, indent: "")
|
14
14
|
case node
|
15
15
|
when Float, Integer
|
16
|
-
print_string
|
16
|
+
print_string "0"
|
17
17
|
when String
|
18
|
-
print_string
|
18
|
+
print_string ""
|
19
19
|
else
|
20
20
|
super
|
21
21
|
end
|
@@ -23,16 +23,16 @@ module GraphQL
|
|
23
23
|
|
24
24
|
# from GraphQL::Language::Printer with sort_by name
|
25
25
|
# ignores aliases
|
26
|
-
def print_field(field, indent:
|
26
|
+
def print_field(field, indent: "")
|
27
27
|
print_string(indent)
|
28
28
|
print_string(field.name)
|
29
29
|
if field.arguments.any?
|
30
|
-
print_string(
|
30
|
+
print_string("(")
|
31
31
|
field.arguments.sort_by(&:name).each_with_index do |a, i|
|
32
32
|
print_argument(a)
|
33
|
-
print_string(
|
33
|
+
print_string(", ") if i < field.arguments.size - 1
|
34
34
|
end
|
35
|
-
print_string(
|
35
|
+
print_string(")")
|
36
36
|
end
|
37
37
|
print_directives(field.directives)
|
38
38
|
print_selections(field.selections, indent: indent)
|
@@ -43,7 +43,7 @@ module GraphQL
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# from GraphQL::Language::Printer with sort_by name
|
46
|
-
def print_selections(selections, indent:
|
46
|
+
def print_selections(selections, indent: "")
|
47
47
|
sorted_nodes = selections.sort_by do |s|
|
48
48
|
next s.name if s.respond_to?(:name)
|
49
49
|
next s.type.name if s.respond_to?(:type)
|
@@ -55,35 +55,35 @@ module GraphQL
|
|
55
55
|
|
56
56
|
# from GraphQL::Language::Printer with sort_by name
|
57
57
|
def print_directive(directive)
|
58
|
-
print_string(
|
58
|
+
print_string("@")
|
59
59
|
print_string(directive.name)
|
60
60
|
|
61
61
|
return if directive.arguments.blank?
|
62
62
|
|
63
|
-
print_string(
|
63
|
+
print_string("(")
|
64
64
|
directive.arguments.sort_by(&:name).each_with_index do |a, i|
|
65
65
|
print_argument(a)
|
66
|
-
print_string(
|
66
|
+
print_string(", ") if i < directive.arguments.size - 1
|
67
67
|
end
|
68
|
-
print_string(
|
68
|
+
print_string(")")
|
69
69
|
end
|
70
70
|
|
71
71
|
# from GraphQL::Language::Printer with sort_by name
|
72
|
-
def print_operation_definition(operation_definition, indent:
|
72
|
+
def print_operation_definition(operation_definition, indent: "")
|
73
73
|
print_string(indent)
|
74
74
|
print_string(operation_definition.operation_type)
|
75
75
|
if operation_definition.name
|
76
|
-
print_string(
|
76
|
+
print_string(" ")
|
77
77
|
print_string(operation_definition.name)
|
78
78
|
end
|
79
79
|
|
80
80
|
if operation_definition.variables.any?
|
81
|
-
print_string(
|
81
|
+
print_string("(")
|
82
82
|
operation_definition.variables.sort_by(&:name).each_with_index do |v, i|
|
83
83
|
print_variable_definition(v)
|
84
|
-
print_string(
|
84
|
+
print_string(", ") if i < operation_definition.variables.size - 1
|
85
85
|
end
|
86
|
-
print_string(
|
86
|
+
print_string(")")
|
87
87
|
end
|
88
88
|
|
89
89
|
print_directives(operation_definition.directives)
|
data/lib/graphql-hive/sampler.rb
CHANGED
@@ -8,28 +8,28 @@ module GraphQL
|
|
8
8
|
# backwards compatibility with old `collect_usage_sampling` field
|
9
9
|
if sampling_options.is_a?(Numeric)
|
10
10
|
logger&.warn(
|
11
|
-
|
12
|
-
|
11
|
+
"`collect_usage_sampling` is deprecated for fixed sampling rates, " \
|
12
|
+
"use `collect_usage_sampling: { sample_rate: XX }` instead"
|
13
13
|
)
|
14
14
|
passed_sampling_rate = sampling_options
|
15
|
-
sampling_options = {
|
15
|
+
sampling_options = {sample_rate: passed_sampling_rate}
|
16
16
|
end
|
17
17
|
|
18
18
|
sampling_options ||= {}
|
19
19
|
|
20
20
|
@sampler = if sampling_options[:sampler]
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
21
|
+
Sampling::DynamicSampler.new(
|
22
|
+
sampling_options[:sampler],
|
23
|
+
sampling_options[:at_least_once],
|
24
|
+
sampling_options[:key_generator]
|
25
|
+
)
|
26
|
+
else
|
27
|
+
Sampling::BasicSampler.new(
|
28
|
+
sampling_options[:sample_rate],
|
29
|
+
sampling_options[:at_least_once],
|
30
|
+
sampling_options[:key_generator]
|
31
|
+
)
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
def sample?(operation)
|