Skip to content

Commit 08d831a

Browse files
committed
Polishing
See gh-771
1 parent a38fac0 commit 08d831a

13 files changed

+86
-73
lines changed

spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public B interceptors(Consumer<List<GraphQlClientInterceptor>> interceptorsConsu
9999
}
100100

101101
@Override
102-
public B documentSource(DocumentSource contentLoader) {
103-
this.documentSource = contentLoader;
102+
public B documentSource(DocumentSource documentSource) {
103+
this.documentSource = documentSource;
104104
return self();
105105
}
106106

@@ -195,8 +195,7 @@ protected Consumer<AbstractGraphQlClientBuilder<?>> getBuilderInitializer() {
195195

196196
private Chain createExecuteChain(GraphQlTransport transport) {
197197

198-
Chain chain = request -> transport
199-
.execute(request)
198+
Chain chain = request -> transport.execute(request)
200199
.map(response -> new DefaultClientGraphQlResponse(request, response, getEncoder(), getDecoder()));
201200

202201
return this.interceptors.stream()

spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientSyncBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public B interceptors(Consumer<List<SyncGraphQlClientInterceptor>> interceptorsC
100100
}
101101

102102
@Override
103-
public B documentSource(DocumentSource contentLoader) {
104-
this.documentSource = contentLoader;
103+
public B documentSource(DocumentSource documentSource) {
104+
this.documentSource = documentSource;
105105
return self();
106106
}
107107

spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class DefaultGraphQlClient implements GraphQlClient {
4646

4747
private final GraphQlClientInterceptor.Chain nonBlockingChain;
4848

49-
private final GraphQlClientInterceptor.SubscriptionChain executeSubscriptionChain;
49+
private final GraphQlClientInterceptor.SubscriptionChain subscriptionChain;
5050

5151
@Nullable
5252
private final Duration blockingTimeout;
@@ -63,7 +63,7 @@ final class DefaultGraphQlClient implements GraphQlClient {
6363
this.documentSource = documentSource;
6464
this.blockingChain = blockingChain;
6565
this.nonBlockingChain = adaptToNonBlockingChain(blockingChain, scheduler);
66-
this.executeSubscriptionChain = request -> Flux.error(new IllegalStateException("Subscriptions on supported"));
66+
this.subscriptionChain = request -> Flux.error(new IllegalStateException("Subscriptions on supported"));
6767
this.blockingTimeout = blockingTimeout;
6868
}
6969

@@ -80,7 +80,7 @@ final class DefaultGraphQlClient implements GraphQlClient {
8080
this.documentSource = documentSource;
8181
this.blockingChain = adaptToBlockingChain(nonBlockingChain, blockingTimeout);
8282
this.nonBlockingChain = nonBlockingChain;
83-
this.executeSubscriptionChain = subscriptionChain;
83+
this.subscriptionChain = subscriptionChain;
8484
this.blockingTimeout = blockingTimeout;
8585
}
8686

@@ -217,7 +217,7 @@ public Mono<ClientGraphQlResponse> execute() {
217217

218218
@Override
219219
public Flux<ClientGraphQlResponse> executeSubscription() {
220-
return initRequest().flatMapMany(request -> executeSubscriptionChain.next(request)
220+
return initRequest().flatMapMany(request -> subscriptionChain.next(request)
221221
.onErrorResume(
222222
ex -> !(ex instanceof GraphQlClientException),
223223
ex -> Mono.error(new GraphQlTransportException(ex, request))));

spring-graphql/src/main/java/org/springframework/graphql/client/DefaultSyncHttpGraphQlClientBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ public HttpSyncGraphQlClient build() {
111111
});
112112

113113
RestClient restClient = this.restClientBuilder.build();
114-
HttpSyncGraphQlTransport syncTransport = new HttpSyncGraphQlTransport(restClient);
114+
HttpSyncGraphQlTransport transport = new HttpSyncGraphQlTransport(restClient);
115115

116-
GraphQlClient graphQlClient = super.buildGraphQlClient(syncTransport);
116+
GraphQlClient graphQlClient = super.buildGraphQlClient(transport);
117117
return new DefaultHttpSyncGraphQlClient(graphQlClient, restClient, getBuilderInitializer());
118118
}
119119

120120

121121
/**
122-
* Default {@link HttpGraphQlClient} implementation.
122+
* Default {@link HttpSyncGraphQlClient} implementation.
123123
*/
124124
private static class DefaultHttpSyncGraphQlClient
125125
extends AbstractDelegatingGraphQlClient implements HttpSyncGraphQlClient {

spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ static Builder<?> builder(GraphQlTransport transport) {
8989

9090

9191
/**
92-
* Base builder to create a {@link GraphQlClient}.
92+
* Base builder for creating and initializing a {@link GraphQlClient}.
9393
* @since 1.3
9494
*/
9595
interface BaseBuilder<B extends BaseBuilder<B>> {
9696

9797
/**
98-
* Configure a {@link DocumentSource} for use with
99-
* {@link #documentName(String)} for resolving a document by name.
98+
* Configure a {@link DocumentSource} strategy to resolve a document by
99+
* name. For use within {@link #documentName(String)}.
100100
* <p>By default, this is set to {@link ResourceDocumentSource} with
101101
* classpath location {@code "graphql-documents/"} and
102102
* {@link ResourceDocumentSource#FILE_EXTENSIONS} as extensions.
@@ -107,8 +107,9 @@ interface BaseBuilder<B extends BaseBuilder<B>> {
107107
* Configure a timeout to use for blocking execution.
108108
* <p>By default this is not set, in which case the behavior depends on
109109
* connection and request timeout settings of the underlying transport.
110-
* We recommend configuring timeout values directly on the underlying
111-
* transport, which provides more control over such settings.
110+
* We recommend configuring timeout values directly if possible on the
111+
* underlying transport library such an HTTP client library as that can
112+
* provide more control over such settings.
112113
* @param blockingTimeout the timeout to use
113114
*/
114115
B blockingTimeout(@Nullable Duration blockingTimeout);
@@ -123,7 +124,7 @@ interface BaseBuilder<B extends BaseBuilder<B>> {
123124

124125
/**
125126
* Builder to create a {@link GraphQlClient} instance with a
126-
* synchronous transport and interceptors.
127+
* synchronous execution chain and transport.
127128
* @since 1.3
128129
* @see SyncGraphQlTransport
129130
*/
@@ -156,8 +157,8 @@ interface SyncBuilder<B extends SyncBuilder<B>> extends BaseBuilder<B> {
156157

157158

158159
/**
159-
* Builder to create {@link GraphQlClient} instances with a non-blocking
160-
* {@link GraphQlTransport} and interceptors.
160+
* Builder to create a {@link GraphQlClient} with a non-blocking execution
161+
* chain and transport.
161162
*/
162163
interface Builder<B extends Builder<B>> extends BaseBuilder<B> {
163164

@@ -242,10 +243,10 @@ interface RequestSpec {
242243
RequestSpec attributes(Consumer<Map<String, Object>> attributesConsumer);
243244

244245
/**
245-
* Shortcut for {@link #execute()} with a field path to decode from.
246-
* <p>If you want to decode the full data instead, use {@link #execute()}:
246+
* Shortcut for {@link #executeSync()} with a field path to decode from.
247+
* <p>If you want to decode the full data instead, use:
247248
* <pre>
248-
* client.document("..").execute().map(response -> response.toEntity(..))
249+
* client.document("..").executeSync()
249250
* </pre>
250251
* @return a spec with decoding options
251252
* @throws FieldAccessException if the field has any field errors,
@@ -256,9 +257,9 @@ interface RequestSpec {
256257

257258
/**
258259
* Shortcut for {@link #execute()} with a field path to decode from.
259-
* <p>If you want to decode the full data instead, use {@link #execute()}:
260+
* <p>If you want to decode the full data instead, use:
260261
* <pre>
261-
* client.document("..").execute().map(response -> response.toEntity(..))
262+
* client.document("..").execute().map(response -> ...)
262263
* </pre>
263264
* @return a spec with decoding options
264265
* @throws FieldAccessException if the field has any field errors,
@@ -269,9 +270,9 @@ interface RequestSpec {
269270
/**
270271
* Shortcut for {@link #executeSubscription()} with a field path to
271272
* decode from for each result.
272-
* <p>If you want to decode the full data, use {@link #executeSubscription()}:
273+
* <p>If you want to decode the full data, use:
273274
* <pre>
274-
* client.document("..").executeSubscription().map(response -> response.toEntity(..))
275+
* client.document("..").executeSubscription().map(response -> ...)
275276
* </pre>
276277
* @return a spec with decoding options
277278
*/
@@ -291,8 +292,8 @@ interface RequestSpec {
291292
* Execute request with a single response, e.g. "query" or "mutation", and
292293
* return a response for further options.
293294
* @return a {@code Mono} with a {@code ClientGraphQlResponse} for further
294-
* decoding of the response. The {@code Mono} may end with a
295-
* .
295+
* decoding of the response. The {@code Mono} may end with an error due
296+
* to transport level issues.
296297
*/
297298
Mono<ClientGraphQlResponse> execute();
298299

@@ -316,17 +317,17 @@ interface RequestSpec {
316317

317318

318319
/**
319-
* Declares options to decode a field for a single response operation.
320+
* Declares options to decode a field in a single response.
321+
* @since 1.3
320322
*/
321323
interface RetrieveSyncSpec {
322324

323325
/**
324326
* Decode the field to an entity of the given type.
325327
* @param entityType the type to convert to
326-
* @return {@code Mono} with the decoded entity; completes with
327-
* {@link FieldAccessException} in case of {@link ResponseField field
328+
* @return the entity or null if the field is {@code null} and has no errors.
329+
* @throws FieldAccessException in case of {@link ResponseField field
328330
* errors} or an {@link GraphQlResponse#isValid() invalid} response;
329-
* completes empty if the field is {@code null} but has no errors.
330331
* @see ResponseField#getErrors()
331332
*/
332333
@Nullable
@@ -345,16 +346,15 @@ interface RetrieveSyncSpec {
345346
<D> List<D> toEntityList(Class<D> elementType);
346347

347348
/**
348-
* Variant of {@link #toEntity(Class)} to decode to a List of entities.
349-
* @param elementType the type of elements in the list
349+
* Variant of {@link #toEntityList(Class)} with a {@link ParameterizedTypeReference}.
350350
*/
351351
<D> List<D> toEntityList(ParameterizedTypeReference<D> elementType);
352352

353353
}
354354

355355

356356
/**
357-
* Declares options to decode a field for a single response operation.
357+
* Declares options to decode a field in a single response.
358358
*/
359359
interface RetrieveSpec {
360360

@@ -381,8 +381,7 @@ interface RetrieveSpec {
381381
<D> Mono<List<D>> toEntityList(Class<D> elementType);
382382

383383
/**
384-
* Variant of {@link #toEntity(Class)} to decode to a List of entities.
385-
* @param elementType the type of elements in the list
384+
* Variant of {@link #toEntityList(Class)} with a {@link ParameterizedTypeReference}.
386385
*/
387386
<D> Mono<List<D>> toEntityList(ParameterizedTypeReference<D> elementType);
388387

spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121

2222

2323
/**
24-
* Interceptor for {@link GraphQlClient} requests.
24+
* Interceptor for {@link GraphQlClient} requests for use in a non-blocking
25+
* execution chain with a non-blocking {@link GraphQlTransport}..
2526
*
2627
* @author Rossen Stoyanchev
2728
* @since 1.0.0
29+
* @see GraphQlClient.Builder
2830
*/
2931
public interface GraphQlClientInterceptor {
3032

@@ -54,8 +56,8 @@ default Flux<ClientGraphQlResponse> interceptSubscription(ClientGraphQlRequest r
5456
}
5557

5658
/**
57-
* Return a new {@link GraphQlClientInterceptor} that invokes the current
58-
* interceptor first and then the one that is passed in.
59+
* Return a new interceptor that invokes the current interceptor first and
60+
* then the one that is passed in.
5961
* @param interceptor the interceptor to delegate to after "this"
6062
* @return the new {@code GraphQlClientInterceptor}
6163
*/
@@ -78,7 +80,7 @@ public Flux<ClientGraphQlResponse> interceptSubscription(ClientGraphQlRequest re
7880

7981

8082
/**
81-
* Contract for delegation of single response requests to the rest of the chain.
83+
* Contract to delegate to the rest of a non-blocking execution chain.
8284
*/
8385
interface Chain {
8486

spring-graphql/src/main/java/org/springframework/graphql/client/HttpMessageConverterDelegate.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ static HttpMessageConverter<Object> findJsonConverter(List<HttpMessageConverter<
6666
.orElseThrow(() -> new IllegalArgumentException("No JSON HttpMessageConverter"));
6767
}
6868

69-
@Nullable
70-
private static MediaType toMediaType(@Nullable MimeType mimeType) {
71-
if (mimeType instanceof MediaType mediaType) {
72-
return mediaType;
73-
}
74-
return (mimeType != null ? new MediaType(mimeType) : null);
75-
}
76-
7769
static HttpMessageConverterEncoder asEncoder(HttpMessageConverter<Object> converter) {
7870
return new HttpMessageConverterEncoder(converter);
7971
}
@@ -82,7 +74,18 @@ static HttpMessageConverterDecoder asDecoder(HttpMessageConverter<Object> conver
8274
return new HttpMessageConverterDecoder(converter);
8375
}
8476

77+
@Nullable
78+
private static MediaType toMediaType(@Nullable MimeType mimeType) {
79+
if (mimeType instanceof MediaType mediaType) {
80+
return mediaType;
81+
}
82+
return (mimeType != null ? new MediaType(mimeType) : null);
83+
}
84+
8585

86+
/**
87+
* Partial Encoder implementation to encode a single value through an HttpMessageConverter.
88+
*/
8689
private static class HttpMessageConverterEncoder implements Encoder<Object> {
8790

8891
private final HttpMessageConverter<Object> converter;
@@ -134,6 +137,9 @@ public Flux<DataBuffer> encode(
134137
}
135138

136139

140+
/**
141+
* Partial Decoder implementation to decode a single buffer through an HttpMessageConverter.
142+
*/
137143
private static class HttpMessageConverterDecoder implements Decoder<Object> {
138144

139145
private final HttpMessageConverter<Object> converter;

spring-graphql/src/main/java/org/springframework/graphql/client/HttpSyncGraphQlClient.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626

2727

2828
/**
29-
* GraphQL over HTTP client that uses {@link RestClient}.
29+
* GraphQL over HTTP client with that uses {@link RestClient} in a blocking
30+
* execution chain.
3031
*
3132
* @author Rossen Stoyanchev
3233
* @since 1.3
34+
* @see SyncGraphQlTransport
3335
*/
3436
public interface HttpSyncGraphQlClient extends GraphQlClient {
3537

@@ -70,24 +72,24 @@ static Builder<?> builder(RestClient.Builder builder) {
7072

7173

7274
/**
73-
* Builder for the GraphQL over HTTP client.
75+
* Builder for the GraphQL over HTTP client with a blocking execution chain.
7476
*/
7577
interface Builder<B extends Builder<B>> extends GraphQlClient.SyncBuilder<B> {
7678

7779
/**
7880
* Set the GraphQL endpoint URL as a String.
79-
* @param url the url to send HTTP requests to or connect over WebSocket
81+
* @param url the url to send HTTP requests to
8082
*/
8183
B url(String url);
8284

8385
/**
8486
* Set the GraphQL endpoint URL.
85-
* @param url the url to send HTTP requests to or connect over WebSocket
87+
* @param url the url to send HTTP requests to
8688
*/
8789
B url(URI url);
8890

8991
/**
90-
* Add the given header to HTTP requests or to the WebSocket handshake request.
92+
* Add the given header to HTTP requests.
9193
* @param name the header name
9294
* @param values the header values
9395
*/
@@ -101,14 +103,16 @@ interface Builder<B extends Builder<B>> extends GraphQlClient.SyncBuilder<B> {
101103
B headers(Consumer<HttpHeaders> headersConsumer);
102104

103105
/**
104-
* Configure message converters for all JSON encoding and decoding needs.
106+
* Configure message converters for JSON for use in the
107+
* {@link org.springframework.graphql.GraphQlResponse} to convert response
108+
* data to higher level objects.
105109
* @param configurer the configurer to apply
106110
* @return this builder
107111
*/
108112
B messageConverters(Consumer<List<HttpMessageConverter<?>>> configurer);
109113

110114
/**
111-
* Customize the {@code RestClient} to use.
115+
* Customize the underlying {@code RestClient}.
112116
* <p>Note that some properties of {@code RestClient.Builder} like the base URL,
113117
* headers, and message converters can be customized through this builder.
114118
* @see #url(String)
@@ -118,7 +122,7 @@ interface Builder<B extends Builder<B>> extends GraphQlClient.SyncBuilder<B> {
118122
B restClient(Consumer<RestClient.Builder> builderConsumer);
119123

120124
/**
121-
* Build the {@code RestClientGraphQlClient} instance.
125+
* Build the {@code HttpSyncGraphQlClient} instance.
122126
*/
123127
@Override
124128
HttpSyncGraphQlClient build();

0 commit comments

Comments
 (0)