Skip to content

Commit bd8a633

Browse files
committed
AbstractGraphQlTesterBuilder copies extensions/attributes
Closes gh-1135
1 parent 5682740 commit bd8a633

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/AbstractGraphQlTesterBuilder.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.time.Duration;
2020
import java.util.Collections;
21+
import java.util.Map;
2122
import java.util.function.Consumer;
2223
import java.util.function.Function;
2324
import java.util.function.Predicate;
@@ -34,6 +35,7 @@
3435
import org.springframework.graphql.GraphQlResponse;
3536
import org.springframework.graphql.ResponseError;
3637
import org.springframework.graphql.client.AbstractGraphQlClientBuilder;
38+
import org.springframework.graphql.client.ClientGraphQlRequest;
3739
import org.springframework.graphql.client.GraphQlClient;
3840
import org.springframework.graphql.client.GraphQlTransport;
3941
import org.springframework.graphql.support.DocumentSource;
@@ -167,6 +169,8 @@ public Mono<GraphQlResponse> execute(GraphQlRequest request) {
167169
.document(request.getDocument())
168170
.operationName(request.getOperationName())
169171
.variables(request.getVariables())
172+
.extensions(request.getExtensions())
173+
.attributes((map) -> copyAttributes(map, request))
170174
.execute()
171175
.cast(GraphQlResponse.class);
172176
}
@@ -177,9 +181,17 @@ public Flux<GraphQlResponse> executeSubscription(GraphQlRequest request) {
177181
.document(request.getDocument())
178182
.operationName(request.getOperationName())
179183
.variables(request.getVariables())
184+
.extensions(request.getExtensions())
185+
.attributes((map) -> copyAttributes(map, request))
180186
.executeSubscription()
181187
.cast(GraphQlResponse.class);
182188
}
189+
190+
private static void copyAttributes(Map<String, Object> map, GraphQlRequest request) {
191+
if (request instanceof ClientGraphQlRequest clientGraphQlRequest) {
192+
map.putAll(clientGraphQlRequest.getAttributes());
193+
}
194+
}
183195
};
184196
}
185197

0 commit comments

Comments
 (0)