You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/schema/instrumentation.md
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ Field instrumentation can be attached during schema definition:
10
10
11
11
```ruby
12
12
MySchema=GraphQL::Schema.define do
13
-
instrument(:field, MyFieldInstrumentation.new)
13
+
instrument(:field, FieldTimerInstrumentation.new)
14
14
end
15
15
```
16
16
@@ -19,7 +19,7 @@ The instrumenter is an object which responds to `#instrument(type, field)`. `#in
19
19
Here's an example field instrumenter:
20
20
21
21
```ruby
22
-
classMyFieldInstrumentation
22
+
classFieldTimerInstrumentation
23
23
# If a field was flagged to be timed,
24
24
# wrap its resolve proc with a timer.
25
25
definstrument(type, field)
@@ -40,7 +40,7 @@ class MyFieldInstrumentation
40
40
end
41
41
```
42
42
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.
44
44
45
45
## Query Instrumentation
46
46
@@ -49,14 +49,16 @@ Query instrumentation can be attached during schema definition:
49
49
50
50
```ruby
51
51
MySchema=GraphQL::Schema.define do
52
-
instrument(:query, MyQueryInstrumentation.new)
52
+
instrument(:query, QueryTimerInstrumentation)
53
53
end
54
54
```
55
55
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.
0 commit comments