Skip to content

Commit a068c4a

Browse files
committed
Update multiplex docs
1 parent c6359e0 commit a068c4a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

guides/queries/multiplex.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Some clients may send _several_ queries to the server at once (for example, [Apo
1212

1313
Multiplex runs have their own context, analyzers and instrumentation.
1414

15-
__NOTE:__ As an implementation detail, _all_ queries are run inside multiplexes. That is, a stand-alone query is executed as a "multiplex of one", so instrumentation and multiplex analyzers and instrumentation _will_ apply to standalone queries run with `MySchema.execute(...)`.
15+
__NOTE:__ As an implementation detail, _all_ queries run inside multiplexes. That is, a stand-alone query is executed as a "multiplex of one", so instrumentation and multiplex analyzers and tracers _will_ apply to standalone queries run with `MySchema.execute(...)`.
1616

1717
## Concurrent Execution
1818

@@ -84,7 +84,7 @@ end
8484

8585
## Validation and Error Handling
8686

87-
Each query is validated and {% internal_link "analyzed","/queries/ast_analysis" %} independently. The `results` array may include a mix of successful results and failed results
87+
Each query is validated and {% internal_link "analyzed","/queries/ast_analysis" %} independently. The `results` array may include a mix of successful results and failed results.
8888

8989
## Multiplex-Level Context
9090

@@ -111,31 +111,29 @@ The API is the same as {% internal_link "query analyzers","/queries/ast_analysis
111111

112112
Multiplex analyzers may return {{ "AnalysisError" | api_doc }} to halt execution of the whole multiplex.
113113

114-
## Multiplex Instrumentation
114+
## Multiplex Tracing
115115

116-
You can add hooks for each multiplex run with multiplex instrumentation.
116+
You can add hooks for each multiplex run with {% internal_link "trace modules", "/queries/tracing" %}.
117117

118-
An instrumenter must implement `.before_multiplex(multiplex)` and `.after_multiplex(multiplex)`. Then, it can be mounted with `instrument(:multiplex, MyMultiplexAnalyzer)`. See {{ "Execution::Multiplex" | api_doc }} for available methods.
118+
The trace module may implement `def execute_multiplex(multiplex:)` which `yield`s to allow the multiplex to execute. See {{ "Execution::Multiplex" | api_doc }} for available methods.
119119

120120
For example:
121121

122122
```ruby
123123
# Count how many queries are in the multiplex run:
124124
module MultiplexCounter
125-
def self.before_multiplex(multiplex)
125+
def execute_multiplex(multiplex:)
126126
Rails.logger.info("Multiplex size: #{multiplex.queries.length}")
127-
end
128-
129-
def self.after_multiplex(multiplex)
127+
yield
130128
end
131129
end
132130

133131
# ...
134132

135133
class MySchema < GraphQL::Schema
136134
# ...
137-
instrument(:multiplex, MultiplexCounter)
135+
trace_with(MultiplexCounter )
138136
end
139137
```
140138

141-
Now, `MultiplexCounter.before_multiplex` will be called before each multiplex and `.after_multiplex` will run after each multiplex.
139+
Now, `MultiplexCounter#execute_multiplex` will be called for each execution, logging the size of each multiplex.

0 commit comments

Comments
 (0)