optics-agent 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjIwMWU1NjYxNGYzNzhhMzk1Y2IwODMxZTE1NjZkYjUwNTY1NTQ5YQ==
4
+ OTY4ZDA5OTJkNWJjMmE3NWIwOTAyNTJlNGJjNWQzM2RlNWViNDA3MA==
5
5
  data.tar.gz: !binary |-
6
- MTNkMjcxMjAyNWJlY2E1OTc4NTVkY2NmMTZjMGZiODdkNDg4ZTFkMA==
6
+ OGI1YmVmMzE3ZDY1MDUzMjNmOWZmZTg2YTA5MzlmOWMzNDZkMzFiNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTRkYTZlZDlhMDNmMjQ5OGU5MTliNDVkNWRhYzUzMjIzMDMwNTNjYjQ4NTg2
10
- OTNkOWRmOWM1YmE2YWViNzE2MGExZDliNzQwZjcxZjFkYmNmNjA2MGM5OWMz
11
- ZjhmOGFmODM2MWFjMDM5Njc3OTU2YzFmMDgyN2FiYmUwMmVmYWI=
9
+ YjA0ODUzYjA2ZjJkZWI5ZDc4MDJlMDk5NDA3ZmU5NWRjMDQ5YTA4ZjAzY2Y4
10
+ NzgwNTU4M2YzMjk2MzM5YTk1M2M4NzM2YjIyZjI2NzE5ZDBkM2YyYTc5OWY3
11
+ YjIyNWFhOWRhNzI5ZGJjMjdkN2I3Yjc2NDVlZThlZDBiZGQ4YTY=
12
12
  data.tar.gz: !binary |-
13
- NWM4ZDQwOGU5MTZjYTVhY2MwZjg4NWQ4MjA5Zjc2OGZjZWUyZTlkMTc2YTI1
14
- MTk4YzQzZWEyNGY1YmUwMDUzZTg2Mjg3NTk4MTIyNGNiMjA4ZGNhNjQwYWE1
15
- ZGE0ZjEyMTdiNmJlZTM3NDFlN2E3YTEyOTNhZmUyZTJkYzQ4NTM=
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
- document = JSON.parse request.body.read
52
- result = Schema.execute(document["query"],
53
- variables: document["variables"],
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
- result = YourSchema.execute(query_string,
95
+
96
+ result = YourSchema.execute(
97
+ query_string,
91
98
  variables: query_variables,
92
99
  context: {
93
- optics_agent: env[:optics_agent].with_document(params)
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
- begin
12
- start_time = Time.now
11
+ start_time = Time.now
13
12
 
14
- # XXX: figure out a way to pass this in here
15
- agent = OpticsAgent::Agent.instance
16
- query = OpticsAgent::Reporting::Query.new
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
- # Attach so resolver middleware can access
19
- env[:optics_agent] = {
20
- agent: agent,
21
- query: query
22
- }
23
- env[:optics_agent].define_singleton_method(:with_document) do |document|
24
- self[:query].document = document
25
- self
26
- end
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
- # XXX: this approach means if the user forgets to call with_document
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
- result
37
- rescue Exception => e
38
- puts "Rack Middleware Error: #{e}"
39
- puts e.backtrace
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
@@ -28,7 +28,7 @@ module OpticsAgent::Reporting
28
28
  throw "You must call .with_document on the optics context"
29
29
  end
30
30
 
31
- @signature ||= normalize(document["query"].to_s)
31
+ @signature ||= normalize(document.to_s)
32
32
  end
33
33
 
34
34
  # we do nothing when reporting to minimize impact
@@ -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 = DocumentMock.new('{field}')
15
+ query.document = '{field}'
27
16
 
28
17
  trace = QueryTrace.new(query, {}, 1, 1.25)
29
18
 
@@ -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 = DocumentMock.new('{field}')
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 = DocumentMock.new('{field}')
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 = DocumentMock.new('{field}')
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 = DocumentMock.new('{fieldOne}')
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 = DocumentMock.new('{fieldTwo}')
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 = DocumentMock.new('{field}')
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 = DocumentMock.new('{field}')
153
+ query.document = '{field}'
165
154
 
166
155
  report = Report.new
167
156
  report.add_query query, {}, 1, 1.25
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optics-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ! 'Tom Coleman '