Skip to content

Commit 522e430

Browse files
committed
doc(Instrumentation) update docs
1 parent 60fd6eb commit 522e430

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

guides/schema/instrumentation.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Field instrumentation can be attached during schema definition:
1010

1111
```ruby
1212
MySchema = GraphQL::Schema.define do
13-
instrument(:field, MyFieldInstrumentation.new)
13+
instrument(:field, FieldTimerInstrumentation.new)
1414
end
1515
```
1616

@@ -19,7 +19,7 @@ The instrumenter is an object which responds to `#instrument(type, field)`. `#in
1919
Here's an example field instrumenter:
2020

2121
```ruby
22-
class MyFieldInstrumentation
22+
class FieldTimerInstrumentation
2323
# If a field was flagged to be timed,
2424
# wrap its resolve proc with a timer.
2525
def instrument(type, field)
@@ -40,7 +40,7 @@ class MyFieldInstrumentation
4040
end
4141
```
4242

43-
It can be attached as shown above. This implementation will _modify_ the underlying `GraphQL::Field` instance... be warned!
43+
It can be attached as shown above. You can use `redefine { ... }` to make a shallow copy of the {{ "GraphQL::Field" | api_doc }} and extend its definition.
4444

4545
## Query Instrumentation
4646

@@ -49,14 +49,16 @@ Query instrumentation can be attached during schema definition:
4949

5050
```ruby
5151
MySchema = GraphQL::Schema.define do
52-
instrument(:query, MyQueryInstrumentation.new)
52+
instrument(:query, QueryTimerInstrumentation)
5353
end
5454
```
5555

56-
The instrumenter must implement `#before_query(query)` and `#after_query(query)`. The return value of these methods are not used. They receive the `GraphQL::Query` instance.
56+
The instrumenter must implement `#before_query(query)` and `#after_query(query)`. The return values of these methods are not used. They receive the {{ "GraphQL::Query" | api_doc }} instance.
5757

5858
```ruby
59-
class MyQueryInstrumentation
59+
module MyQueryInstrumentation
60+
module_function
61+
6062
# Log the time of the query
6163
def before_query(query)
6264
Rails.logger.info("Query begin: #{Time.now.to_i}")

0 commit comments

Comments
 (0)