Skip to content

Commit 973fc56

Browse files
committed
Upgrade to Micrometer context-propagation snapshots
Closes gh-477
1 parent 2b829db commit 973fc56

16 files changed

+20
-20
lines changed

platform/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323

2424
constraints {
2525
api("com.graphql-java:graphql-java:${graphQlJavaVersion}")
26-
api("io.micrometer:context-propagation:1.0.0-M4")
26+
api("io.micrometer:context-propagation:1.0.0-SNAPSHOT")
2727

2828
api("jakarta.annotation:jakarta.annotation-api:2.0.0")
2929
api("jakarta.servlet:jakarta.servlet-api:5.0.0")

spring-graphql/src/main/java/org/springframework/graphql/data/method/InvocableHandlerMethodSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private Object handleReturnValue(GraphQLContext graphQLContext, @Nullable Object
114114
return CompletableFuture.supplyAsync(
115115
() -> {
116116
try {
117-
return ContextSnapshot.capture(graphQLContext).wrap((Callable<?>) result).call();
117+
return ContextSnapshot.captureFrom(graphQLContext).wrap((Callable<?>) result).call();
118118
}
119119
catch (Exception ex) {
120120
throw new IllegalStateException(

spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private ContextDataFetcherDecorator(
7070
@Override
7171
public Object get(DataFetchingEnvironment environment) throws Exception {
7272

73-
ContextSnapshot snapshot = ContextSnapshot.capture(environment.getGraphQlContext());
73+
ContextSnapshot snapshot = ContextSnapshot.captureFrom(environment.getGraphQlContext());
7474
Object value = snapshot.wrap(() -> this.delegate.get(environment)).call();
7575

7676
if (this.subscription) {

spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private List<GraphQLError> resolveInternal(Throwable exception, DataFetchingEnvi
9898
return resolveToMultipleErrors(exception, env);
9999
}
100100
try {
101-
return ContextSnapshot.capture(env.getGraphQlContext())
101+
return ContextSnapshot.captureFrom(env.getGraphQlContext())
102102
.wrap(() -> resolveToMultipleErrors(exception, env))
103103
.call();
104104
}

spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public DataLoaderOptions getOptionsOrDefault(
190190
@Override
191191
public CompletionStage<List<V>> load(List<K> keys, BatchLoaderEnvironment environment) {
192192
GraphQLContext graphQLContext = environment.getContext();
193-
ContextSnapshot snapshot = ContextSnapshot.capture(graphQLContext);
193+
ContextSnapshot snapshot = ContextSnapshot.captureFrom(graphQLContext);
194194
try {
195195
return snapshot.wrap(() ->
196196
this.loader.apply(keys, environment)
@@ -245,7 +245,7 @@ public DataLoaderOptions getOptionsOrDefault(
245245
@Override
246246
public CompletionStage<Map<K, V>> load(Set<K> keys, BatchLoaderEnvironment environment) {
247247
GraphQLContext graphQLContext = environment.getContext();
248-
ContextSnapshot snapshot = ContextSnapshot.capture(graphQLContext);
248+
ContextSnapshot snapshot = ContextSnapshot.captureFrom(graphQLContext);
249249
try {
250250
return snapshot.wrap(() ->
251251
this.loader.apply(keys, environment)

spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultExecutionGraphQlService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public final Mono<ExecutionGraphQlResponse> execute(ExecutionGraphQlRequest requ
7777
request.configureExecutionInput(RESET_EXECUTION_ID_CONFIGURER);
7878
}
7979
ExecutionInput executionInput = request.toExecutionInput();
80-
ContextSnapshot.capture(contextView).updateContext(executionInput.getGraphQLContext());
80+
ContextSnapshot.captureFrom(contextView).updateContext(executionInput.getGraphQLContext());
8181
ExecutionInput updatedExecutionInput = registerDataLoaders(executionInput);
8282
return Mono.fromFuture(this.graphQlSource.graphQl().executeAsync(updatedExecutionInput))
8383
.map(result -> new DefaultExecutionGraphQlResponse(updatedExecutionInput, result));

spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public DataFetcherExceptionHandlerResult onException(DataFetcherExceptionHandler
7070
public CompletableFuture<DataFetcherExceptionHandlerResult> handleException(DataFetcherExceptionHandlerParameters params) {
7171
Throwable exception = unwrapException(params);
7272
DataFetchingEnvironment env = params.getDataFetchingEnvironment();
73-
ContextSnapshot snapshot = ContextSnapshot.capture(env.getGraphQlContext());
73+
ContextSnapshot snapshot = ContextSnapshot.captureFrom(env.getGraphQlContext());
7474
try {
7575
return Flux.fromIterable(this.resolvers)
7676
.flatMap(resolver -> resolver.resolveException(exception, env))

spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolverAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public boolean isThreadLocalContextAware() {
8383
public final Mono<List<GraphQLError>> resolveException(Throwable exception) {
8484
if (this.threadLocalContextAware) {
8585
return Mono.deferContextual(contextView -> {
86-
ContextSnapshot snapshot = ContextSnapshot.capture(contextView);
86+
ContextSnapshot snapshot = ContextSnapshot.captureFrom(contextView);
8787
try {
8888
List<GraphQLError> errors = snapshot.wrap(() -> resolveToMultipleErrors(exception)).call();
8989
return Mono.justOrEmpty(errors);

spring-graphql/src/main/java/org/springframework/graphql/server/DefaultWebGraphQlHandlerBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public WebSocketGraphQlInterceptor getWebSocketInterceptor() {
8787

8888
@Override
8989
public Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request) {
90-
ContextSnapshot snapshot = ContextSnapshot.capture();
90+
ContextSnapshot snapshot = ContextSnapshot.captureAll();
9191
return executionChain.next(request).contextWrite(snapshot::updateContext);
9292
}
9393
};

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public boolean beforeHandshake(
360360
ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
361361
Map<String, Object> attributes) {
362362

363-
attributes.put(KEY, ContextSnapshot.capture());
363+
attributes.put(KEY, ContextSnapshot.captureAll());
364364
return true;
365365
}
366366

@@ -373,7 +373,7 @@ public void afterHandshake(
373373
public static AutoCloseable setThreadLocals(WebSocketSession session) {
374374
ContextSnapshot snapshot = (ContextSnapshot) session.getAttributes().get(KEY);
375375
Assert.notNull(snapshot, "Expected ContextSnapshot in WebSocketSession attributes");
376-
return snapshot.setThreadLocalValues();
376+
return snapshot.setThreadLocals();
377377
}
378378
}
379379

0 commit comments

Comments
 (0)