Skip to content

Commit fe7eb1d

Browse files
committed
Update docs for context propagation
Closes gh-459
1 parent f5e7103 commit fe7eb1d

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

spring-graphql-docs/src/docs/asciidoc/index.adoc

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -486,39 +486,40 @@ different thread.
486486

487487
Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container
488488
thread to the thread a `DataFetcher` and other components invoked by GraphQL Java to
489-
execute on. To do this, an application needs to create a `ThreadLocalAccessor` to extract
490-
`ThreadLocal` values of interest:
489+
execute on. To do this, an application needs to implement
490+
`io.micrometer.context.ThreadLocalAccessor` for a `ThreadLocal` values of interest:
491491

492492
[source,java,indent=0,subs="verbatim,quotes"]
493493
----
494-
public class RequestAttributesAccessor implements ThreadLocalAccessor {
494+
public class RequestAttributesAccessor implements ThreadLocalAccessor<RequestAttributes> {
495495
496-
private static final String KEY = RequestAttributesAccessor.class.getName();
496+
@Override
497+
public Object key() {
498+
return RequestAttributesAccessor.class.getName();
499+
}
497500
498-
@Override
499-
public void extractValues(Map<String, Object> container) {
500-
container.put(KEY, RequestContextHolder.getRequestAttributes());
501-
}
501+
@Override
502+
public RequestAttributes getValue() {
503+
return RequestContextHolder.getRequestAttributes();
504+
}
502505
503-
@Override
504-
public void restoreValues(Map<String, Object> values) {
505-
if (values.containsKey(KEY)) {
506-
RequestContextHolder.setRequestAttributes((RequestAttributes) values.get(KEY));
507-
}
508-
}
506+
@Override
507+
public void setValue(RequestAttributes attributes) {
508+
RequestContextHolder.setRequestAttributes(attributes);
509+
}
509510
510-
@Override
511-
public void resetValues(Map<String, Object> values) {
512-
RequestContextHolder.resetRequestAttributes();
513-
}
511+
@Override
512+
public void reset() {
513+
RequestContextHolder.resetRequestAttributes();
514+
}
514515
515516
}
516517
----
517518

518-
A `ThreadLocalAccessor` can be registered in the <<server-interception,WebGraphHandler>>
519-
builder. The Boot starter detects beans of this type and automatically registers them for
520-
Spring MVC application, see the
521-
{spring-boot-ref-docs}/web.html#web.graphql.transports.http-websocket[Web Endpoints] section.
519+
You can register a `ThreadLocalAccessor` manually on startup with the global
520+
`ContextRegistry` instance, which is accessible via
521+
`io.micrometer.context.ContextRegistry#getInstance()`. You can also register it
522+
automatically through the `java.util.ServiceLoader` mechanism.
522523

523524

524525
[[execution-context-webflux]]

0 commit comments

Comments
 (0)