Class: GraphQL::Hive
- Inherits:
-
Tracing::PlatformTracing
- Object
- Tracing::PlatformTracing
- GraphQL::Hive
- Defined in:
- lib/graphql-hive.rb,
lib/graphql-hive/client.rb,
lib/graphql-hive/printer.rb,
lib/graphql-hive/analyzer.rb,
lib/graphql-hive/usage_reporter.rb
Overview
GraphQL Hive usage collector and schema reporter
Defined Under Namespace
Classes: Analyzer, Client, Printer, UsageReporter
Constant Summary collapse
- REPORT_SCHEMA_MUTATION =
<<~MUTATION mutation schemaPublish($input: SchemaPublishInput!) { schemaPublish(input: $input) { __typename } } MUTATION
- DEFAULT_OPTIONS =
{ enabled: true, debug: false, port: '443', collect_usage: true, read_operations: true, report_schema: true, buffer_size: 50, logger: nil, collect_usage_sampling: 1.0 }.freeze
- @@schema =
nil- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Hive
constructor
A new instance of Hive.
- #on_exit ⇒ Object
- #on_start ⇒ Object
-
#platform_authorized_key(type) ⇒ Object
compat.
-
#platform_field_key(type, field) ⇒ Object
compat.
-
#platform_resolve_type_key(type) ⇒ Object
compat.
-
#platform_trace(platform_key, _key, data) ⇒ Object
called on trace events.
Constructor Details
#initialize(options = {}) ⇒ Hive
Returns a new instance of Hive.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/graphql-hive.rb', line 76 def initialize( = {}) opts = DEFAULT_OPTIONS.merge() (opts) super(opts) @@instance = self @client = GraphQL::Hive::Client.new(opts) @usage_reporter = GraphQL::Hive::UsageReporter.new(opts, @client) # buffer @report = { size: 0, map: {}, operations: [] } send_report_schema(@@schema) if @@schema && opts[:report_schema] && @options[:enabled] end |
Class Method Details
.instance ⇒ Object
96 97 98 |
# File 'lib/graphql-hive.rb', line 96 def self.instance @@instance end |
.use(schema, **kwargs) ⇒ Object
100 101 102 103 |
# File 'lib/graphql-hive.rb', line 100 def self.use(schema, **kwargs) @@schema = schema super end |
Instance Method Details
#on_exit ⇒ Object
147 148 149 |
# File 'lib/graphql-hive.rb', line 147 def on_exit @usage_reporter.on_exit end |
#on_start ⇒ Object
151 152 153 |
# File 'lib/graphql-hive.rb', line 151 def on_start @usage_reporter.on_start end |
#platform_authorized_key(type) ⇒ Object
compat
133 134 135 |
# File 'lib/graphql-hive.rb', line 133 def (type) "#{type.graphql_name}.authorized.graphql" end |
#platform_field_key(type, field) ⇒ Object
compat
143 144 145 |
# File 'lib/graphql-hive.rb', line 143 def platform_field_key(type, field) "graphql.#{type.name}.#{field.name}" end |
#platform_resolve_type_key(type) ⇒ Object
compat
138 139 140 |
# File 'lib/graphql-hive.rb', line 138 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type.graphql" end |
#platform_trace(platform_key, _key, data) ⇒ Object
called on trace events
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/graphql-hive.rb', line 106 def platform_trace(platform_key, _key, data) return yield unless @options[:enabled] && @options[:collect_usage] if platform_key == 'execute_multiplex' if data[:multiplex] queries = data[:multiplex].queries = (Time.now.utc.to_f * 1000).to_i starting = Process.clock_gettime(Process::CLOCK_MONOTONIC) results = yield ending = Process.clock_gettime(Process::CLOCK_MONOTONIC) elapsed = ending - starting duration = (elapsed.to_f * (10**9)).to_i # rubocop:disable Layout/LineLength report_usage(, queries, results, duration) if !queries.empty? && SecureRandom.random_number <= @options[:collect_usage_sampling] # rubocop:enable Layout/LineLength results else yield end else yield end end |