yabeda-graphql 0.2.2 → 0.3.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.
@@ -1,100 +0,0 @@
1
- require "graphql/tracing/platform_tracing"
2
-
3
- module Yabeda
4
- module GraphQL
5
- class Tracing < ::GraphQL::Tracing::PlatformTracing
6
-
7
- self.platform_keys = {
8
- 'lex' => "graphql.lex",
9
- 'parse' => "graphql.parse",
10
- 'validate' => "graphql.validate",
11
- 'analyze_query' => "graphql.analyze",
12
- 'analyze_multiplex' => "graphql.analyze",
13
- 'execute_multiplex' => "graphql.execute",
14
- 'execute_query' => "graphql.execute",
15
- 'execute_query_lazy' => "graphql.execute",
16
- 'execute_field' => "graphql.execute",
17
- 'execute_field_lazy' => "graphql.execute"
18
- }
19
-
20
- def platform_trace(platform_key, key, data, &block)
21
- start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC
22
- result = block.call
23
- duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
24
-
25
- case key
26
- when "execute_field", "execute_field_lazy"
27
- field, path, query = extract_field_trace_data(data)
28
-
29
- tags = extract_field_tags(field)
30
- if path.length == 1
31
- return result if key == "execute_field" && query.schema.lazy?(result)
32
-
33
- if query.query?
34
- instrument_query_execution(tags)
35
- elsif query.mutation?
36
- instrument_mutation_execution(tags)
37
- elsif query.subscription?
38
- # Not implemented yet
39
- end
40
- else
41
- instrument_field_execution(query, path, tags, duration)
42
- end
43
- end
44
-
45
- result
46
- end
47
-
48
- # See https://graphql-ruby.org/api-doc/1.10.5/GraphQL/Tracing
49
- def extract_field_trace_data(data)
50
- if data[:context] # Legacy non-interpreter mode
51
- [data[:context].field, data[:context].path, data[:context].query]
52
- else # Interpreter mode
53
- data.values_at(:field, :path, :query)
54
- end
55
- end
56
-
57
- def extract_field_tags(field)
58
- owner = field.respond_to?(:owner) ? field.owner : field.metadata[:type_class].owner
59
- {
60
- type: owner.graphql_name,
61
- field: field.graphql_name,
62
- deprecated: !field.deprecation_reason.nil?,
63
- }
64
- end
65
-
66
- def instrument_field_execution(query, path, tags, duration)
67
- cache(query)[path][:tags] = tags
68
- cache(query)[path][:duration] += duration
69
- end
70
-
71
- def instrument_mutation_execution(tags)
72
- tags = { name: tags[:field], deprecated: tags[:deprecated] }
73
- Yabeda.graphql.mutation_fields_count.increment(tags)
74
- end
75
-
76
- def instrument_query_execution(tags)
77
- tags = { name: tags[:field], deprecated: tags[:deprecated] }
78
- Yabeda.graphql.query_fields_count.increment(tags)
79
- end
80
-
81
- def cache(query)
82
- query.context.namespace(Yabeda::GraphQL)[:field_call_cache]
83
- end
84
-
85
- def platform_field_key(type, field)
86
- "#{type.graphql_name}.#{field.graphql_name}"
87
- end
88
-
89
- # We don't use these yet, but graphql-ruby require us to declare them
90
-
91
- def platform_authorized_key(type)
92
- "#{type.graphql_name}.authorized"
93
- end
94
-
95
- def platform_resolve_type_key(type)
96
- "#{type.graphql_name}.resolve_type"
97
- end
98
- end
99
- end
100
- end