optics-agent 0.1.3 → 0.2.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.
- checksums.yaml +8 -8
- data/README.md +13 -5
- data/lib/optics-agent/rack-middleware.rb +20 -25
- data/lib/optics-agent/reporting/query.rb +1 -1
- data/spec/query_trace_spec.rb +1 -12
- data/spec/report_spec.rb +7 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTY4ZDA5OTJkNWJjMmE3NWIwOTAyNTJlNGJjNWQzM2RlNWViNDA3MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGI1YmVmMzE3ZDY1MDUzMjNmOWZmZTg2YTA5MzlmOWMzNDZkMzFiNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjA0ODUzYjA2ZjJkZWI5ZDc4MDJlMDk5NDA3ZmU5NWRjMDQ5YTA4ZjAzY2Y4
|
10
|
+
NzgwNTU4M2YzMjk2MzM5YTk1M2M4NzM2YjIyZjI2NzE5ZDBkM2YyYTc5OWY3
|
11
|
+
YjIyNWFhOWRhNzI5ZGJjMjdkN2I3Yjc2NDVlZThlZDBiZGQ4YTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWQxMDVjZWZkMjM2YjIyNGI0MzhhNGI0NWE4NmFlYzc0ZmRhMzNhZDVjYWZk
|
14
|
+
Y2U2ODA1NjlkMmIxNDU4MmE5NzM0ZGE0NTNhZWIyNDc4NzQ3MTFlNDhiOGZj
|
15
|
+
M2I0NzhiZmZjNmE0NjQ5OWRjYjEyNmQyYzFlOGUyZGM3ZjQ1Mjg=
|
data/README.md
CHANGED
@@ -48,11 +48,16 @@ Add something like this to your route:
|
|
48
48
|
```ruby
|
49
49
|
post '/graphql' do
|
50
50
|
request.body.rewind
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
params = JSON.parse request.body.read
|
52
|
+
document = params['query']
|
53
|
+
variables = params['variables']
|
54
|
+
|
55
|
+
result = Schema.execute(
|
56
|
+
document,
|
57
|
+
variables: variables,
|
54
58
|
context: { optics_agent: env[:optics_agent].with_document(document) }
|
55
59
|
)
|
60
|
+
|
56
61
|
JSON.generate(result)
|
57
62
|
end
|
58
63
|
```
|
@@ -87,12 +92,15 @@ Register Optics Agent on the GraphQL context within your `graphql` action as bel
|
|
87
92
|
def create
|
88
93
|
query_string = params[:query]
|
89
94
|
query_variables = ensure_hash(params[:variables])
|
90
|
-
|
95
|
+
|
96
|
+
result = YourSchema.execute(
|
97
|
+
query_string,
|
91
98
|
variables: query_variables,
|
92
99
|
context: {
|
93
|
-
optics_agent: env[:optics_agent].with_document(
|
100
|
+
optics_agent: env[:optics_agent].with_document(query_string)
|
94
101
|
}
|
95
102
|
)
|
103
|
+
|
96
104
|
render json: result
|
97
105
|
end
|
98
106
|
```
|
@@ -8,36 +8,31 @@ module OpticsAgent
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
|
12
|
-
start_time = Time.now
|
11
|
+
start_time = Time.now
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
# XXX: figure out a way to pass this in here
|
14
|
+
agent = OpticsAgent::Agent.instance
|
15
|
+
query = OpticsAgent::Reporting::Query.new
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
result = @app.call(env)
|
17
|
+
# Attach so resolver middleware can access
|
18
|
+
env[:optics_agent] = {
|
19
|
+
agent: agent,
|
20
|
+
query: query
|
21
|
+
}
|
22
|
+
env[:optics_agent].define_singleton_method(:with_document) do |document|
|
23
|
+
self[:query].document = document
|
24
|
+
self
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
# we just never log queries. Can we detect if the request is a graphql one?
|
32
|
-
if (query.document)
|
33
|
-
agent.add_query(query, env, start_time, Time.now)
|
34
|
-
end
|
27
|
+
result = @app.call(env)
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
# XXX: this approach means if the user forgets to call with_document
|
30
|
+
# we just never log queries. Can we detect if the request is a graphql one?
|
31
|
+
if (query.document)
|
32
|
+
agent.add_query(query, env, start_time, Time.now)
|
40
33
|
end
|
34
|
+
|
35
|
+
result
|
41
36
|
end
|
42
37
|
end
|
43
38
|
end
|
data/spec/query_trace_spec.rb
CHANGED
@@ -6,24 +6,13 @@ require 'graphql'
|
|
6
6
|
include Apollo::Optics::Proto
|
7
7
|
include OpticsAgent::Reporting
|
8
8
|
|
9
|
-
class DocumentMock
|
10
|
-
def initialize(key)
|
11
|
-
@key = key
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](name) # used for [:query]
|
15
|
-
@key
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
9
|
describe QueryTrace do
|
21
10
|
it "can represent a simple query" do
|
22
11
|
query = Query.new
|
23
12
|
query.report_field 'Person', 'firstName', 1, 1.1
|
24
13
|
query.report_field 'Person', 'lastName', 1, 1.1
|
25
14
|
query.report_field 'Query', 'person', 1, 1.22
|
26
|
-
query.document =
|
15
|
+
query.document = '{field}'
|
27
16
|
|
28
17
|
trace = QueryTrace.new(query, {}, 1, 1.25)
|
29
18
|
|
data/spec/report_spec.rb
CHANGED
@@ -6,24 +6,13 @@ require 'graphql'
|
|
6
6
|
include OpticsAgent::Reporting
|
7
7
|
include Apollo::Optics::Proto
|
8
8
|
|
9
|
-
class DocumentMock
|
10
|
-
def initialize(key)
|
11
|
-
@key = key
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](name) # used for [:query]
|
15
|
-
@key
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
9
|
describe Report do
|
21
10
|
it "can represent a simple query" do
|
22
11
|
query = Query.new
|
23
12
|
query.report_field 'Person', 'firstName', 1, 1.1
|
24
13
|
query.report_field 'Person', 'lastName', 1, 1.1
|
25
14
|
query.report_field 'Query', 'person', 1, 1.22
|
26
|
-
query.document =
|
15
|
+
query.document = '{field}'
|
27
16
|
|
28
17
|
report = Report.new
|
29
18
|
report.add_query query, {}, 1, 1.25
|
@@ -52,13 +41,13 @@ describe Report do
|
|
52
41
|
queryOne.report_field 'Person', 'firstName', 1, 1.1
|
53
42
|
queryOne.report_field 'Person', 'lastName', 1, 1.1
|
54
43
|
queryOne.report_field 'Query', 'person', 1, 1.22
|
55
|
-
queryOne.document =
|
44
|
+
queryOne.document = '{field}'
|
56
45
|
|
57
46
|
queryTwo = Query.new
|
58
47
|
queryTwo.report_field 'Person', 'firstName', 1, 1.05
|
59
48
|
queryTwo.report_field 'Person', 'lastName', 1, 1.05
|
60
49
|
queryTwo.report_field 'Query', 'person', 1, 1.2
|
61
|
-
queryTwo.document =
|
50
|
+
queryTwo.document = '{field}'
|
62
51
|
|
63
52
|
report = Report.new
|
64
53
|
report.add_query queryOne, {}, 1, 1.1
|
@@ -88,13 +77,13 @@ describe Report do
|
|
88
77
|
queryOne.report_field 'Person', 'firstName', 1, 1.1
|
89
78
|
queryOne.report_field 'Person', 'lastName', 1, 1.1
|
90
79
|
queryOne.report_field 'Query', 'person', 1, 1.22
|
91
|
-
queryOne.document =
|
80
|
+
queryOne.document = '{fieldOne}'
|
92
81
|
|
93
82
|
queryTwo = Query.new
|
94
83
|
queryTwo.report_field 'Person', 'firstName', 1, 1.05
|
95
84
|
queryTwo.report_field 'Person', 'lastName', 1, 1.05
|
96
85
|
queryTwo.report_field 'Query', 'person', 1, 1.02
|
97
|
-
queryTwo.document =
|
86
|
+
queryTwo.document = '{fieldTwo}'
|
98
87
|
|
99
88
|
report = Report.new
|
100
89
|
report.add_query queryOne, {}, 1, 1.1
|
@@ -123,7 +112,7 @@ describe Report do
|
|
123
112
|
query = Query.new
|
124
113
|
query.report_field 'Person', 'firstName', 1, 1.1
|
125
114
|
query.report_field 'Person', 'age', 1, 1.1
|
126
|
-
query.document =
|
115
|
+
query.document = '{field}'
|
127
116
|
|
128
117
|
report = Report.new
|
129
118
|
report.add_query query, {}, 1, 1.25
|
@@ -161,7 +150,7 @@ describe Report do
|
|
161
150
|
query.report_field 'Query', '__schema', 1, 1.1
|
162
151
|
query.report_field 'Query', '__typename', 1, 1.1
|
163
152
|
query.report_field 'Query', '__type', 1, 1.1
|
164
|
-
query.document =
|
153
|
+
query.document = '{field}'
|
165
154
|
|
166
155
|
report = Report.new
|
167
156
|
report.add_query query, {}, 1, 1.25
|