diff --git a/spring-graphql/src/main/java/org/springframework/graphql/GraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/GraphQlRequest.java index 84062e67..0e979209 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/GraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/GraphQlRequest.java @@ -61,7 +61,7 @@ public interface GraphQlRequest { /** * Convert the request to a {@link Map} as defined in * GraphQL over HTTP and - * GraphQL over WebSocket: + * GraphQL over WebSocket. * * * diff --git a/spring-graphql/src/main/java/org/springframework/graphql/ResponseError.java b/spring-graphql/src/main/java/org/springframework/graphql/ResponseError.java index b30898ff..10297819 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/ResponseError.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/ResponseError.java @@ -1,3 +1,19 @@ +/* + * Copyright 2020-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.graphql; import java.util.List; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java b/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java index 5f0b3e6f..cd681ffe 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/ResponseField.java @@ -43,7 +43,7 @@ public interface ResponseField { * * @deprecated as of 1.0.3 in favor of checking via {@link #getValue()} */ - @Deprecated + @Deprecated(since = "1.0.3", forRemoval = true) boolean hasValue(); /** @@ -90,7 +90,7 @@ public interface ResponseField { * @deprecated since 1.0.3 in favor of {@link #getErrors()} */ @Nullable - @Deprecated + @Deprecated(since = "1.0.3", forRemoval = true) ResponseError getError(); /** diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientBuilder.java index 9ecb158a..f1367d4c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/AbstractGraphQlClientBuilder.java @@ -46,6 +46,7 @@ import org.springframework.util.ClassUtils; * agnostic {@code GraphQlClient}. A transport specific extension can then wrap * this default tester by extending {@link AbstractDelegatingGraphQlClient}. * + * @param the builder type * @author Rossen Stoyanchev * @since 1.0.0 * @see AbstractDelegatingGraphQlClient @@ -114,6 +115,8 @@ public abstract class AbstractGraphQlClientBuilder encoder, Decoder decoder) { this.jsonEncoder = encoder; @@ -122,6 +125,7 @@ public abstract class AbstractGraphQlClientBuilder encoder) { this.jsonEncoder = encoder; @@ -137,6 +141,7 @@ public abstract class AbstractGraphQlClientBuilder decoder) { this.jsonDecoder = decoder; @@ -161,12 +166,13 @@ public abstract class AbstractGraphQlClientBuilder> getBuilderInitializer() { - return builder -> { - builder.interceptors(interceptorList -> interceptorList.addAll(interceptors)); - builder.documentSource(documentSource); + return (builder) -> { + builder.interceptors((interceptorList) -> interceptorList.addAll(this.interceptors)); + builder.documentSource(this.documentSource); builder.setJsonCodecs(getEncoder(), getDecoder()); }; } private Chain createExecuteChain(GraphQlTransport transport) { - Chain chain = request -> transport.execute(request).map(response -> + Chain chain = (request) -> transport.execute(request).map((response) -> new DefaultClientGraphQlResponse(request, response, getEncoder(), getDecoder())); return this.interceptors.stream() .reduce(GraphQlClientInterceptor::andThen) - .map(interceptor -> (Chain) (request) -> interceptor.intercept(request, chain)) + .map((interceptor) -> (Chain) (request) -> interceptor.intercept(request, chain)) .orElse(chain); } private SubscriptionChain createExecuteSubscriptionChain(GraphQlTransport transport) { - SubscriptionChain chain = request -> transport.executeSubscription(request) - .map(response -> new DefaultClientGraphQlResponse(request, response, getEncoder(), getDecoder())); + SubscriptionChain chain = (request) -> transport.executeSubscription(request) + .map((response) -> new DefaultClientGraphQlResponse(request, response, getEncoder(), getDecoder())); return this.interceptors.stream() .reduce(GraphQlClientInterceptor::andThen) - .map(interceptor -> (SubscriptionChain) (request) -> interceptor.interceptSubscription(request, chain)) + .map((interceptor) -> (SubscriptionChain) (request) -> interceptor.interceptSubscription(request, chain)) .orElse(chain); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/ClientGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/client/ClientGraphQlResponse.java index a43c29c2..0824975b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/ClientGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/ClientGraphQlResponse.java @@ -32,10 +32,12 @@ public interface ClientGraphQlResponse extends GraphQlResponse { /** * {@inheritDoc} */ + @Override ClientResponseField field(String path); /** * Decode the full response map to the given target type. + * @param the target type * @param type the target class * @return the decoded value, or never {@code null} * @throws FieldAccessException if the response is not {@link #isValid() valid} @@ -44,7 +46,8 @@ public interface ClientGraphQlResponse extends GraphQlResponse { /** * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. - * @param type the target type + * @param the target type + * @param type the target parameterized type * @return the decoded value, or never {@code null} * @throws FieldAccessException if the response is not {@link #isValid() valid} */ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/ClientResponseField.java b/spring-graphql/src/main/java/org/springframework/graphql/client/ClientResponseField.java index 8d7ef9a9..66b5146d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/ClientResponseField.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/ClientResponseField.java @@ -34,6 +34,7 @@ public interface ClientResponseField extends ResponseField { /** * Decode the field to an entity of the given type. + * @param the entity type * @param entityType the type to convert to * @return the decoded entity, or {@code null} if the field is {@code null} * but otherwise there are no errors @@ -46,12 +47,15 @@ public interface ClientResponseField extends ResponseField { /** * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. + * @param the entity type + * @param entityType the type to convert to */ @Nullable D toEntity(ParameterizedTypeReference entityType); /** * Variant of {@link #toEntity(Class)} to decode to a list of entities. + * @param the entity type * @param elementType the type of elements in the list * @return the list of decoded entities, or an empty list if the field is * {@code null} but otherwise there are no errors @@ -61,15 +65,16 @@ public interface ClientResponseField extends ResponseField { */ List toEntityList(Class elementType); - /** - * Variant of {@link #toEntity(Class)} to decode to a list of entities. - * @param elementType the type of elements in the list - * @return the list of decoded entities, or an empty list if the field is - * {@code null} but otherwise there are no errors - * @throws FieldAccessException if the target field is {@code null} and the - * response is not {@link GraphQlResponse#isValid() valid} or the field has - * {@link ResponseField#getErrors() errors}. - */ + /** + * Variant of {@link #toEntity(Class)} to decode to a list of entities. + * @param the entity type + * @param elementType the type of elements in the list + * @return the list of decoded entities, or an empty list if the field is + * {@code null} but otherwise there are no errors + * @throws FieldAccessException if the target field is {@code null} and the + * response is not {@link GraphQlResponse#isValid() valid} or the field has + * {@link ResponseField#getErrors() errors}. + */ List toEntityList(ParameterizedTypeReference elementType); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/CodecDelegate.java b/spring-graphql/src/main/java/org/springframework/graphql/client/CodecDelegate.java index 6f433c78..841f1219 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/CodecDelegate.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/CodecDelegate.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.client; import java.util.List; @@ -37,7 +38,6 @@ import org.springframework.web.reactive.socket.WebSocketSession; * Helper class for encoding and decoding GraphQL messages. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class CodecDelegate { @@ -60,14 +60,14 @@ final class CodecDelegate { static Encoder findJsonEncoder(CodecConfigurer configurer) { return findJsonEncoder(configurer.getWriters().stream() - .filter(writer -> writer instanceof EncoderHttpMessageWriter) - .map(writer -> ((EncoderHttpMessageWriter) writer).getEncoder())); + .filter((writer) -> writer instanceof EncoderHttpMessageWriter) + .map((writer) -> ((EncoderHttpMessageWriter) writer).getEncoder())); } static Decoder findJsonDecoder(CodecConfigurer configurer) { return findJsonDecoder(configurer.getReaders().stream() - .filter(reader -> reader instanceof DecoderHttpMessageReader) - .map(reader -> ((DecoderHttpMessageReader) reader).getDecoder())); + .filter((reader) -> reader instanceof DecoderHttpMessageReader) + .map((reader) -> ((DecoderHttpMessageReader) reader).getDecoder())); } static Encoder findJsonEncoder(List> encoders) { @@ -80,26 +80,26 @@ final class CodecDelegate { private static Encoder findJsonEncoder(Stream> stream) { return stream - .filter(encoder -> encoder.canEncode(MESSAGE_TYPE, MediaType.APPLICATION_JSON)) + .filter((encoder) -> encoder.canEncode(MESSAGE_TYPE, MediaType.APPLICATION_JSON)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No JSON Encoder")); } private static Decoder findJsonDecoder(Stream> decoderStream) { return decoderStream - .filter(decoder -> decoder.canDecode(MESSAGE_TYPE, MediaType.APPLICATION_JSON)) + .filter((decoder) -> decoder.canDecode(MESSAGE_TYPE, MediaType.APPLICATION_JSON)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("No JSON Decoder")); } - public CodecConfigurer getCodecConfigurer() { + CodecConfigurer getCodecConfigurer() { return this.codecConfigurer; } @SuppressWarnings("unchecked") - public WebSocketMessage encode(WebSocketSession session, GraphQlWebSocketMessage message) { + WebSocketMessage encode(WebSocketSession session, GraphQlWebSocketMessage message) { DataBuffer buffer = ((Encoder) this.encoder).encodeValue( (T) message, session.bufferFactory(), MESSAGE_TYPE, MimeTypeUtils.APPLICATION_JSON, null); @@ -108,7 +108,7 @@ final class CodecDelegate { } @SuppressWarnings("ConstantConditions") - public GraphQlWebSocketMessage decode(WebSocketMessage webSocketMessage) { + GraphQlWebSocketMessage decode(WebSocketMessage webSocketMessage) { DataBuffer buffer = DataBufferUtils.retain(webSocketMessage.getPayload()); return (GraphQlWebSocketMessage) this.decoder.decode(buffer, MESSAGE_TYPE, null, null); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlRequest.java index ad576e45..8f0e6c83 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlRequest.java @@ -27,7 +27,6 @@ import org.springframework.lang.Nullable; * Default implementation of {@link ClientGraphQlRequest}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultClientGraphQlRequest extends DefaultGraphQlRequest implements ClientGraphQlRequest { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlResponse.java index 18a5ad4c..90bb57cb 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientGraphQlResponse.java @@ -26,7 +26,6 @@ import org.springframework.graphql.GraphQlResponse; * Default implementation of {@link ClientGraphQlResponse}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultClientGraphQlResponse extends ResponseMapGraphQlResponse implements ClientGraphQlResponse { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java index 44646250..c0aa2689 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultClientResponseField.java @@ -40,7 +40,6 @@ import org.springframework.util.MimeTypeUtils; * support for decoding. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultClientResponseField implements ClientResponseField { @@ -55,7 +54,7 @@ final class DefaultClientResponseField implements ClientResponseField { } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") @Override public boolean hasValue() { return (this.field.getValue() != null); @@ -76,7 +75,7 @@ final class DefaultClientResponseField implements ClientResponseField { return this.field.getValue(); } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") @Override public ResponseError getError() { return this.field.getError(); @@ -100,13 +99,13 @@ final class DefaultClientResponseField implements ClientResponseField { @Override public List toEntityList(Class elementType) { List list = toEntity(ResolvableType.forClassWithGenerics(List.class, elementType)); - return (list != null ? list : Collections.emptyList()); + return (list != null) ? list : Collections.emptyList(); } @Override public List toEntityList(ParameterizedTypeReference elementType) { List list = toEntity(ResolvableType.forClassWithGenerics(List.class, ResolvableType.forType(elementType))); - return (list != null ? list : Collections.emptyList()); + return (list != null) ? list : Collections.emptyList(); } @SuppressWarnings("unchecked") diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java index a43e4a44..79809afe 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java @@ -34,7 +34,6 @@ import org.springframework.util.Assert; * Default, final {@link GraphQlClient} implementation for use with any transport. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultGraphQlClient implements GraphQlClient { @@ -155,22 +154,22 @@ final class DefaultGraphQlClient implements GraphQlClient { @Override public Mono execute() { - return initRequest().flatMap(request -> executeChain.next(request) + return initRequest().flatMap((request) -> DefaultGraphQlClient.this.executeChain.next(request) .onErrorResume( - ex -> !(ex instanceof GraphQlClientException), - ex -> Mono.error(new GraphQlTransportException(ex, request)))); + (ex) -> !(ex instanceof GraphQlClientException), + (ex) -> Mono.error(new GraphQlTransportException(ex, request)))); } @Override public Flux executeSubscription() { - return initRequest().flatMapMany(request -> executeSubscriptionChain.next(request) + return initRequest().flatMapMany((request) -> DefaultGraphQlClient.this.executeSubscriptionChain.next(request) .onErrorResume( - ex -> !(ex instanceof GraphQlClientException), - ex -> Mono.error(new GraphQlTransportException(ex, request)))); + (ex) -> !(ex instanceof GraphQlClientException), + (ex) -> Mono.error(new GraphQlTransportException(ex, request)))); } private Mono initRequest() { - return this.documentMono.map(document -> + return this.documentMono.map((document) -> new DefaultClientGraphQlRequest(document, this.operationName, this.variables, this.extensions, this.attributes)); } @@ -198,7 +197,7 @@ final class DefaultGraphQlClient implements GraphQlClient { throw new FieldAccessException( ((DefaultClientGraphQlResponse) response).getRequest(), response, field); } - return (field.getValue() != null ? field : null); + return (field.getValue() != null) ? field : null; } } @@ -215,27 +214,27 @@ final class DefaultGraphQlClient implements GraphQlClient { @Override public Mono toEntity(Class entityType) { - return this.responseMono.mapNotNull(this::getValidField).mapNotNull(field -> field.toEntity(entityType)); + return this.responseMono.mapNotNull(this::getValidField).mapNotNull((field) -> field.toEntity(entityType)); } @Override public Mono toEntity(ParameterizedTypeReference entityType) { - return this.responseMono.mapNotNull(this::getValidField).mapNotNull(field -> field.toEntity(entityType)); + return this.responseMono.mapNotNull(this::getValidField).mapNotNull((field) -> field.toEntity(entityType)); } @Override public Mono> toEntityList(Class elementType) { - return this.responseMono.map(response -> { + return this.responseMono.map((response) -> { ClientResponseField field = getValidField(response); - return (field != null ? field.toEntityList(elementType) : Collections.emptyList()); + return (field != null) ? field.toEntityList(elementType) : Collections.emptyList(); }); } @Override public Mono> toEntityList(ParameterizedTypeReference elementType) { - return this.responseMono.map(response -> { + return this.responseMono.map((response) -> { ClientResponseField field = getValidField(response); - return (field != null ? field.toEntityList(elementType) : Collections.emptyList()); + return (field != null) ? field.toEntityList(elementType) : Collections.emptyList(); }); } @@ -253,27 +252,27 @@ final class DefaultGraphQlClient implements GraphQlClient { @Override public Flux toEntity(Class entityType) { - return this.responseFlux.mapNotNull(this::getValidField).mapNotNull(field -> field.toEntity(entityType)); + return this.responseFlux.mapNotNull(this::getValidField).mapNotNull((field) -> field.toEntity(entityType)); } @Override public Flux toEntity(ParameterizedTypeReference entityType) { - return this.responseFlux.mapNotNull(this::getValidField).mapNotNull(field -> field.toEntity(entityType)); + return this.responseFlux.mapNotNull(this::getValidField).mapNotNull((field) -> field.toEntity(entityType)); } @Override public Flux> toEntityList(Class elementType) { - return this.responseFlux.map(response -> { + return this.responseFlux.map((response) -> { ClientResponseField field = getValidField(response); - return (field != null ? field.toEntityList(elementType) : Collections.emptyList()); + return (field != null) ? field.toEntityList(elementType) : Collections.emptyList(); }); } @Override public Flux> toEntityList(ParameterizedTypeReference elementType) { - return this.responseFlux.map(response -> { + return this.responseFlux.map((response) -> { ClientResponseField field = getValidField(response); - return (field != null ? field.toEntityList(elementType) : Collections.emptyList()); + return (field != null) ? field.toEntityList(elementType) : Collections.emptyList(); }); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultHttpGraphQlClientBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultHttpGraphQlClientBuilder.java index f2e4f38d..7041fea4 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultHttpGraphQlClientBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultHttpGraphQlClientBuilder.java @@ -33,7 +33,6 @@ import org.springframework.web.util.UriComponentsBuilder; * around a {@link WebClient.Builder}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultHttpGraphQlClientBuilder extends AbstractGraphQlClientBuilder @@ -105,7 +104,7 @@ final class DefaultHttpGraphQlClientBuilder public HttpGraphQlClient build() { // Pass the codecs to the parent for response decoding - this.webClientBuilder.codecs(configurer -> + this.webClientBuilder.codecs((configurer) -> setJsonCodecs( CodecDelegate.findJsonEncoder(configurer), CodecDelegate.findJsonDecoder(configurer))); @@ -139,6 +138,7 @@ final class DefaultHttpGraphQlClientBuilder this.builderInitializer = builderInitializer; } + @Override public DefaultHttpGraphQlClientBuilder mutate() { DefaultHttpGraphQlClientBuilder builder = new DefaultHttpGraphQlClientBuilder(this.webClient); this.builderInitializer.accept(builder); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultRSocketGraphQlClientBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultRSocketGraphQlClientBuilder.java index 0dc645d4..68e6fe0a 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultRSocketGraphQlClientBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultRSocketGraphQlClientBuilder.java @@ -41,7 +41,6 @@ import org.springframework.util.MimeTypeUtils; * a {@link RSocketRequester.Builder}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultRSocketGraphQlClientBuilder extends AbstractGraphQlClientBuilder @@ -134,9 +133,9 @@ final class DefaultRSocketGraphQlClientBuilder public RSocketGraphQlClient build() { // Pass the codecs to the parent for response decoding - this.requesterBuilder.rsocketStrategies(builder -> { - builder.decoders(decoders -> setJsonDecoder(CodecDelegate.findJsonDecoder(decoders))); - builder.encoders(encoders -> setJsonEncoder(CodecDelegate.findJsonEncoder(encoders))); + this.requesterBuilder.rsocketStrategies((builder) -> { + builder.decoders((decoders) -> setJsonDecoder(CodecDelegate.findJsonDecoder(decoders))); + builder.encoders((encoders) -> setJsonEncoder(CodecDelegate.findJsonEncoder(encoders))); }); RSocketRequester requester; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultTransportGraphQlClientBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultTransportGraphQlClientBuilder.java index 86d49925..29dc8113 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultTransportGraphQlClientBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultTransportGraphQlClientBuilder.java @@ -26,7 +26,6 @@ import org.springframework.util.Assert; * Default {@link GraphQlClient.Builder} with a given, externally, prepared transport. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultTransportGraphQlClientBuilder extends AbstractGraphQlClientBuilder { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultWebSocketGraphQlClientBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultWebSocketGraphQlClientBuilder.java index 90204385..7d303850 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultWebSocketGraphQlClientBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/DefaultWebSocketGraphQlClientBuilder.java @@ -20,7 +20,6 @@ import java.net.URI; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; -import java.util.stream.Collectors; import reactor.core.publisher.Mono; @@ -37,7 +36,6 @@ import org.springframework.web.util.DefaultUriBuilderFactory; * {@code WebSocketGraphQlTransport}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class DefaultWebSocketGraphQlClientBuilder extends AbstractGraphQlClientBuilder @@ -130,14 +128,14 @@ final class DefaultWebSocketGraphQlClientBuilder private WebSocketGraphQlClientInterceptor getInterceptor() { List interceptors = getInterceptors().stream() - .filter(interceptor -> interceptor instanceof WebSocketGraphQlClientInterceptor) - .map(interceptor -> (WebSocketGraphQlClientInterceptor) interceptor) + .filter((interceptor) -> interceptor instanceof WebSocketGraphQlClientInterceptor) + .map((interceptor) -> (WebSocketGraphQlClientInterceptor) interceptor) .toList(); Assert.state(interceptors.size() <= 1, "Only a single interceptor of type WebSocketGraphQlClientInterceptor may be configured"); - return (!interceptors.isEmpty() ? interceptors.get(0) : new WebSocketGraphQlClientInterceptor() {}); + return (!interceptors.isEmpty() ? interceptors.get(0) : new WebSocketGraphQlClientInterceptor() { }); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/FieldAccessException.java b/spring-graphql/src/main/java/org/springframework/graphql/client/FieldAccessException.java index 6bddc787..4c6cb60e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/FieldAccessException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/FieldAccessException.java @@ -38,6 +38,9 @@ public class FieldAccessException extends GraphQlClientException { /** * Constructor with the request and response, and the accessed field. + * @param request the client request + * @param response the client response + * @param field the accessed field that caused the error */ public FieldAccessException( ClientGraphQlRequest request, ClientGraphQlResponse response, ClientResponseField field) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java index 985f834d..6a2c6f7c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.client; import java.util.List; @@ -61,6 +62,7 @@ public interface GraphQlClient { * Variant of {@link #document(String)} that uses the given key to resolve * the GraphQL document from a file with the help of the configured * {@link Builder#documentSource(DocumentSource) DocumentSource}. + * @param name the document name * @throws IllegalArgumentException if the content could not be loaded */ RequestSpec documentName(String name); @@ -87,6 +89,7 @@ public interface GraphQlClient { /** * Defines a builder for creating {@link GraphQlClient} instances. + * @param the client builder type */ interface Builder> { @@ -112,6 +115,7 @@ public interface GraphQlClient { *

By default, this is set to {@link ResourceDocumentSource} with * classpath location {@code "graphql-documents/"} and * {@link ResourceDocumentSource#FILE_EXTENSIONS} as extensions. + * @param contentLoader the document source */ B documentSource(DocumentSource contentLoader); @@ -190,6 +194,7 @@ public interface GraphQlClient { *

 		 * client.document("..").execute().map(response -> response.toEntity(..))
 		 * 
+ * @param path the field path * @return a spec with decoding options * @throws FieldAccessException if the field has any field errors, * including errors at, above or below the field path. @@ -203,6 +208,7 @@ public interface GraphQlClient { *
 		 * client.document("..").executeSubscription().map(response -> response.toEntity(..))
 		 * 
+ * @param path the field path * @return a spec with decoding options */ RetrieveSubscriptionSpec retrieveSubscription(String path); @@ -242,6 +248,7 @@ public interface GraphQlClient { /** * Decode the field to an entity of the given type. + * @param the entity type * @param entityType the type to convert to * @return {@code Mono} with the decoded entity; completes with * {@link FieldAccessException} in case of {@link ResponseField field @@ -253,17 +260,21 @@ public interface GraphQlClient { /** * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. + * @param the entity type + * @param entityType the type to convert to */ Mono toEntity(ParameterizedTypeReference entityType); /** * Variant of {@link #toEntity(Class)} to decode to a List of entities. + * @param the entity type * @param elementType the type of elements in the list */ Mono> toEntityList(Class elementType); /** * Variant of {@link #toEntity(Class)} to decode to a List of entities. + * @param the entity type * @param elementType the type of elements in the list */ Mono> toEntityList(ParameterizedTypeReference elementType); @@ -278,6 +289,7 @@ public interface GraphQlClient { /** * Decode the field to an entity of the given type. + * @param the entity type * @param entityType the type to convert to * @return {@code Mono} with the decoded entity; completes with * {@link FieldAccessException} in case of {@link ResponseField field @@ -289,20 +301,25 @@ public interface GraphQlClient { /** * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. + * @param the entity type + * @param entityType the type to convert to */ Flux toEntity(ParameterizedTypeReference entityType); /** * Variant of {@link #toEntity(Class)} to decode each response to a List of entities. + * @param the entity type * @param elementType the type of elements in the list */ Flux> toEntityList(Class elementType); /** * Variant of {@link #toEntity(Class)} to decode each response to a List of entities. + * @param the entity type + * @param elementType the type of elements in the list */ Flux> toEntityList(ParameterizedTypeReference elementType); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientException.java b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientException.java index 543ad296..9cce8bce 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientException.java @@ -36,6 +36,9 @@ public class GraphQlClientException extends NestedRuntimeException { /** * Constructor with a message, optional cause, and the request details. + * @param message the exception message to use + * @param cause the original cause for the client exception + * @param request the request that failed */ public GraphQlClientException(String message, @Nullable Throwable cause, GraphQlRequest request) { super(message, cause); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java index a1b9597a..fda6bb57 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java @@ -65,13 +65,13 @@ public interface GraphQlClientInterceptor { @Override public Mono intercept(ClientGraphQlRequest request, Chain chain) { return GraphQlClientInterceptor.this.intercept( - request, nextRequest -> interceptor.intercept(nextRequest, chain)); + request, (nextRequest) -> interceptor.intercept(nextRequest, chain)); } @Override public Flux interceptSubscription(ClientGraphQlRequest request, SubscriptionChain chain) { return GraphQlClientInterceptor.this.interceptSubscription( - request, nextRequest -> interceptor.interceptSubscription(nextRequest, chain)); + request, (nextRequest) -> interceptor.interceptSubscription(nextRequest, chain)); } }; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransport.java b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransport.java index 44b0a7a7..2afc67ed 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransport.java @@ -63,6 +63,7 @@ public interface GraphQlTransport { /** * Factory method to create {@link GraphQlResponse} from a GraphQL response * map for use in transport implementations. + * @param responseMap the GraphQL response map */ static GraphQlResponse createResponse(Map responseMap) { return new ResponseMapGraphQlResponse(responseMap); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransportException.java b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransportException.java index 8dca147e..e7f80067 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransportException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlTransportException.java @@ -32,6 +32,8 @@ public class GraphQlTransportException extends GraphQlClientException { /** * Constructor with a default message. + * @param cause the original cause of the transport error + * @param request the request that failed at the transport level */ public GraphQlTransportException(@Nullable Throwable cause, GraphQlRequest request) { super("GraphQlTransport error: " + cause.getMessage(), cause, request); @@ -39,6 +41,9 @@ public class GraphQlTransportException extends GraphQlClientException { /** * Constructor with a given message. + * @param message the exception message to use + * @param cause the original cause of the transport error + * @param request the request that failed at the transport level */ public GraphQlTransportException(String message, @Nullable Throwable cause, GraphQlRequest request) { super(message, cause, request); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlClient.java index 72c6505c..82734771 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlClient.java @@ -36,6 +36,7 @@ public interface HttpGraphQlClient extends WebGraphQlClient { /** * Create an {@link HttpGraphQlClient} that uses the given {@link WebClient}. + * @param webClient the {@code WebClient} to use for sending HTTP requests */ static HttpGraphQlClient create(WebClient webClient) { return builder(webClient.mutate()).build(); @@ -51,6 +52,7 @@ public interface HttpGraphQlClient extends WebGraphQlClient { /** * Variant of {@link #builder()} with a pre-configured {@code WebClient} * to mutate and customize further through the returned builder. + * @param webClient the {@code WebClient} to use for sending HTTP requests */ static Builder builder(WebClient webClient) { return builder(webClient.mutate()); @@ -59,6 +61,7 @@ public interface HttpGraphQlClient extends WebGraphQlClient { /** * Variant of {@link #builder()} with a pre-configured {@code WebClient} * to mutate and customize further through the returned builder. + * @param webClientBuilder the {@code WebClient.Builder} to use for building the HTTP client */ static Builder builder(WebClient.Builder webClientBuilder) { return new DefaultHttpGraphQlClientBuilder(webClientBuilder); @@ -67,6 +70,7 @@ public interface HttpGraphQlClient extends WebGraphQlClient { /** * Builder for the GraphQL over HTTP client. + * @param the builder type */ interface Builder> extends WebGraphQlClient.Builder { @@ -74,6 +78,7 @@ public interface HttpGraphQlClient extends WebGraphQlClient { * Customize the {@code WebClient} to use. *

Note that some properties of {@code WebClient.Builder} like the * base URL, headers, and codecs can be customized through this builder. + * @param webClient the function for customizing the {@code WebClient.Builder} that's used to build the HTTP client * @see #url(String) * @see #header(String, String...) * @see #codecConfigurer(Consumer) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlTransport.java b/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlTransport.java index 70af28a9..98a0d871 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlTransport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/HttpGraphQlTransport.java @@ -37,12 +37,11 @@ import org.springframework.web.reactive.function.client.WebClient; * see {@link WebSocketGraphQlTransport} and {@link RSocketGraphQlTransport}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class HttpGraphQlTransport implements GraphQlTransport { private static final ParameterizedTypeReference> MAP_TYPE = - new ParameterizedTypeReference>() {}; + new ParameterizedTypeReference>() { }; // To be removed in favor of Framework's MediaType.APPLICATION_GRAPHQL_RESPONSE private static final MediaType APPLICATION_GRAPHQL_RESPONSE = @@ -64,7 +63,7 @@ final class HttpGraphQlTransport implements GraphQlTransport { HttpHeaders headers = new HttpHeaders(); webClient.mutate().defaultHeaders(headers::putAll); MediaType contentType = headers.getContentType(); - return (contentType != null ? contentType : MediaType.APPLICATION_JSON); + return (contentType != null) ? contentType : MediaType.APPLICATION_JSON; } @@ -75,7 +74,7 @@ final class HttpGraphQlTransport implements GraphQlTransport { .contentType(this.contentType) .accept(MediaType.APPLICATION_JSON, APPLICATION_GRAPHQL_RESPONSE, MediaType.APPLICATION_GRAPHQL) .bodyValue(request.toMap()) - .attributes(attributes -> { + .attributes((attributes) -> { if (request instanceof ClientGraphQlRequest clientRequest) { attributes.putAll(clientRequest.getAttributes()); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlClient.java index 133975d8..72126cf2 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlClient.java @@ -70,6 +70,7 @@ public interface RSocketGraphQlClient extends GraphQlClient { /** * Start with a given {@link #builder()}. + * @param requesterBuilder the existing request builder */ static Builder builder(RSocketRequester.Builder requesterBuilder) { return new DefaultRSocketGraphQlClientBuilder(requesterBuilder); @@ -78,6 +79,7 @@ public interface RSocketGraphQlClient extends GraphQlClient { /** * Builder for the GraphQL over HTTP client. + * @param the builder type */ interface Builder> extends GraphQlClient.Builder { @@ -146,11 +148,12 @@ public interface RSocketGraphQlClient extends GraphQlClient { *

Note that some properties of {@code RSocketRequester.Builder} like the * data MimeType, and the underlying RSocket transport can be customized * through this builder. + * @param requester the requester to be customized + * @return the same builder instance * @see #dataMimeType(MimeType) * @see #tcp(String, int) * @see #webSocket(URI) * @see #clientTransport(ClientTransport) - * @return the same builder instance */ B rsocketRequester(Consumer requester); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlTransport.java b/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlTransport.java index 324c1fed..3d19b614 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlTransport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/RSocketGraphQlTransport.java @@ -45,12 +45,11 @@ import org.springframework.util.Assert; * metadata extension. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class RSocketGraphQlTransport implements GraphQlTransport { private static final ParameterizedTypeReference> MAP_TYPE = - new ParameterizedTypeReference>() {}; + new ParameterizedTypeReference>() { }; private static final ResolvableType LIST_TYPE = ResolvableType.forClass(List.class); @@ -83,7 +82,7 @@ final class RSocketGraphQlTransport implements GraphQlTransport { public Flux executeSubscription(GraphQlRequest request) { return this.rsocketRequester.route(this.route).data(request.toMap()) .retrieveFlux(MAP_TYPE) - .onErrorResume(RejectedException.class, ex -> Flux.error(decodeErrors(request, ex))) + .onErrorResume(RejectedException.class, (ex) -> Flux.error(decodeErrors(request, ex))) .map(ResponseMapGraphQlResponse::new); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java index 22f82976..f91ddf15 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/ResponseMapGraphQlResponse.java @@ -36,7 +36,6 @@ import org.springframework.util.ObjectUtils; * {@link GraphQlResponse} that wraps a deserialized the GraphQL response map. * * @author Rossen Stoyanchev - * @since 1.0.0 */ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { @@ -60,7 +59,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { @SuppressWarnings("unchecked") private static List wrapErrors(Map map) { List> errors = (List>) map.get("errors"); - errors = (errors != null ? errors : Collections.emptyList()); + errors = (errors != null) ? errors : Collections.emptyList(); return errors.stream().map(MapResponseError::new).collect(Collectors.toList()); } @@ -134,7 +133,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { return Collections.emptyList(); } return locations.stream() - .map(m -> new SourceLocation(getInt(m, "line"), getInt(m, "column"), (String) m.get("sourceName"))) + .map((m) -> new SourceLocation(getInt(m, "line"), getInt(m, "column"), (String) m.get("sourceName"))) .collect(Collectors.toList()); } @@ -155,7 +154,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { return ""; } return path.stream().reduce("", - (s, o) -> s + (o instanceof Integer ? "[" + o + "]" : (s.isEmpty() ? o : "." + o)), + (s, o) -> s + ((o instanceof Integer) ? "[" + o + "]" : (s.isEmpty() ? o : "." + o)), (s, s2) -> null); } @@ -163,7 +162,7 @@ class ResponseMapGraphQlResponse extends AbstractGraphQlResponse { @Override @Nullable public String getMessage() { - return (String) errorMap.get("message"); + return (String) this.errorMap.get("message"); } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/SubscriptionErrorException.java b/spring-graphql/src/main/java/org/springframework/graphql/client/SubscriptionErrorException.java index 775ad801..51a27baa 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/SubscriptionErrorException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/SubscriptionErrorException.java @@ -38,6 +38,8 @@ public class SubscriptionErrorException extends GraphQlTransportException { /** * Constructor with the request details and the errors listed in the payload * of the {@code "errors"} message. + * @param request the request details + * @param errors the errors listed in the payload */ public SubscriptionErrorException(GraphQlRequest request, List errors) { super("GraphQL subscription completed with an \"error\" message, " + diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/WebGraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/WebGraphQlClient.java index 534fdd6c..e323b54b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/WebGraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/WebGraphQlClient.java @@ -39,6 +39,7 @@ public interface WebGraphQlClient extends GraphQlClient { /** * Base builder for GraphQL clients over a Web transport. + * @param the builder type */ interface Builder> extends GraphQlClient.Builder { @@ -71,6 +72,7 @@ public interface WebGraphQlClient extends GraphQlClient { /** * Configure the underlying {@code CodecConfigurer} to use for all JSON * encoding and decoding needs. + * @param codecsConsumer a consumer that configures the {@code CodecConfigurer} */ B codecConfigurer(Consumer codecsConsumer); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketDisconnectedException.java b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketDisconnectedException.java index eb64ef8b..f04ac0b8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketDisconnectedException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketDisconnectedException.java @@ -35,6 +35,9 @@ public class WebSocketDisconnectedException extends GraphQlTransportException { /** * Constructor with an explanation about the closure, along with the request * details and the status used to close the WebSocket session. + * @param closeStatusMessage the message received when the connection was closed + * @param request the ongoing request when the connection was closed + * @param status the received close status */ public WebSocketDisconnectedException(String closeStatusMessage, GraphQlRequest request, CloseStatus status) { super(closeStatusMessage, null, request); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlClient.java b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlClient.java index 2350ec0a..86dbbdf8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlClient.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlClient.java @@ -85,6 +85,7 @@ public interface WebSocketGraphQlClient extends WebGraphQlClient { /** * Builder for a GraphQL over WebSocket client. + * @param the builder type */ interface Builder> extends WebGraphQlClient.Builder { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlTransport.java b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlTransport.java index 9c5a93c2..ba191672 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlTransport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlTransport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.client; import java.net.URI; @@ -50,7 +51,6 @@ import org.springframework.web.reactive.socket.client.WebSocketClient; * {@link GraphQlTransport} for GraphQL over WebSocket via {@link WebSocketClient}. * * @author Rossen Stoyanchev - * @since 1.0.0 * @see GraphQL over WebSocket protocol */ final class WebSocketGraphQlTransport implements GraphQlTransport { @@ -78,7 +78,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { Assert.notNull(interceptor, "WebSocketGraphQlClientInterceptor is required"); this.url = url; - this.headers.putAll(headers != null ? headers : HttpHeaders.EMPTY); + this.headers.putAll((headers != null) ? headers : HttpHeaders.EMPTY); this.webSocketClient = client; this.graphQlSessionHandler = new GraphQlSessionHandler(codecConfigurer, interceptor); @@ -100,7 +100,9 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { Mono sessionMono = handler.getGraphQlSession(); client.execute(uri, headers, handler) - .subscribe(aVoid -> {}, + .subscribe((aVoid) -> { + + }, handler::handleWebSocketSessionError, handler::handleWebSocketSessionClosed); @@ -109,19 +111,19 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { } - public URI getUrl() { + URI getUrl() { return this.url; } - public HttpHeaders getHeaders() { + HttpHeaders getHeaders() { return this.headers; } - public WebSocketClient getWebSocketClient() { + WebSocketClient getWebSocketClient() { return this.webSocketClient; } - public CodecConfigurer getCodecConfigurer() { + CodecConfigurer getCodecConfigurer() { return this.graphQlSessionHandler.getCodecConfigurer(); } @@ -132,7 +134,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * @return {@code Mono} that completes when the WebSocket is connected and * ready to begin sending GraphQL requests */ - public Mono start() { + Mono start() { this.graphQlSessionHandler.setStopped(false); return this.graphQlSessionMono.then(); } @@ -145,19 +147,19 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * call {@link #start()} to allow requests again. * @return {@code Mono} that completes when the underlying session is closed */ - public Mono stop() { + Mono stop() { this.graphQlSessionHandler.setStopped(true); - return this.graphQlSessionMono.flatMap(GraphQlSession::close).onErrorResume(ex -> Mono.empty()); + return this.graphQlSessionMono.flatMap(GraphQlSession::close).onErrorResume((ex) -> Mono.empty()); } @Override public Mono execute(GraphQlRequest request) { - return this.graphQlSessionMono.flatMap(session -> session.execute(request)); + return this.graphQlSessionMono.flatMap((session) -> session.execute(request)); } @Override public Flux executeSubscription(GraphQlRequest request) { - return this.graphQlSessionMono.flatMapMany(session -> session.executeSubscription(request)); + return this.graphQlSessionMono.flatMapMany((session) -> session.executeSubscription(request)); } @@ -189,7 +191,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { } - public CodecConfigurer getCodecConfigurer() { + CodecConfigurer getCodecConfigurer() { return this.codecDelegate.getCodecConfigurer(); } @@ -205,7 +207,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * the "connection_init" and "connection_ack" messages are exchanged or * returns an error if it fails for any reason. */ - public Mono getGraphQlSession() { + Mono getGraphQlSession() { return this.graphQlSessionSink.asMono(); } @@ -213,14 +215,14 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * When the handler is marked "stopped", i.e. set to {@code true}, new * requests are rejected. When set to {@code true} they are allowed. */ - public void setStopped(boolean stopped) { + void setStopped(boolean stopped) { this.stopped.set(stopped); } /** * Whether the handler is marked {@link #setStopped(boolean) "stopped"}. */ - public boolean isStopped() { + boolean isStopped() { return this.stopped.get(); } @@ -241,10 +243,10 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { Mono sendCompletion = session.send(connectionInitMono.concatWith(graphQlSession.getRequestFlux()) - .map(message -> this.codecDelegate.encode(session, message))); + .map((message) -> this.codecDelegate.encode(session, message))); Mono receiveCompletion = session.receive() - .flatMap(webSocketMessage -> { + .flatMap((webSocketMessage) -> { if (sessionNotInitialized()) { try { GraphQlWebSocketMessage message = this.codecDelegate.decode(webSocketMessage); @@ -301,14 +303,14 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { private void registerCloseStatusHandling(GraphQlSession graphQlSession, WebSocketSession session) { session.closeStatus() .defaultIfEmpty(CloseStatus.NO_STATUS_CODE) - .doOnNext(closeStatus -> { + .doOnNext((closeStatus) -> { String closeStatusMessage = initCloseStatusMessage(closeStatus, null, graphQlSession); if (logger.isDebugEnabled()) { logger.debug(closeStatusMessage); } graphQlSession.terminateRequests(closeStatusMessage, closeStatus); }) - .doOnError(cause -> { + .doOnError((cause) -> { CloseStatus closeStatus = CloseStatus.NO_STATUS_CODE; String closeStatusMessage = initCloseStatusMessage(closeStatus, cause, graphQlSession); if (logger.isErrorEnabled()) { @@ -347,7 +349,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * with an error. The error is routed to subscribers of * {@link #getGraphQlSession()} which is necessary for connection issues. */ - public void handleWebSocketSessionError(Throwable ex) { + void handleWebSocketSessionError(Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Session handling error: " + ex.getMessage(), ex); @@ -364,7 +366,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * This must be called from code that calls the {@code WebSocketClient} * when execution completes. */ - public void handleWebSocketSessionClosed() { + void handleWebSocketSessionClosed() { this.graphQlSessionSink = Sinks.unsafe().one(); } @@ -396,16 +398,16 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { /** * Return the {@code Flux} of GraphQL requests to send as WebSocket messages. */ - public Flux getRequestFlux() { + Flux getRequestFlux() { return this.requestSink.getRequestFlux(); } // Outbound messages - public Mono execute(GraphQlRequest request) { + Mono execute(GraphQlRequest request) { String id = String.valueOf(this.requestIndex.incrementAndGet()); - return Mono.create(sink -> { + return Mono.create((sink) -> { SingleResponseRequestState state = new SingleResponseRequestState(request, sink); this.requestStateMap.put(id, state); try { @@ -419,9 +421,9 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { }).doOnCancel(() -> this.requestStateMap.remove(id)); } - public Flux executeSubscription(GraphQlRequest request) { + Flux executeSubscription(GraphQlRequest request) { String id = String.valueOf(this.requestIndex.incrementAndGet()); - return Flux.create(sink -> { + return Flux.create((sink) -> { SubscriptionRequestState state = new SubscriptionRequestState(request, sink); this.requestStateMap.put(id, state); try { @@ -452,7 +454,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { } } - public void sendPong(@Nullable Map payload) { + void sendPong(@Nullable Map payload) { GraphQlWebSocketMessage message = GraphQlWebSocketMessage.pong(payload); this.requestSink.sendRequest(message); } @@ -463,7 +465,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { /** * Handle a "next" message and route to its recipient. */ - public void handleNext(GraphQlWebSocketMessage message) { + void handleNext(GraphQlWebSocketMessage message) { String id = message.getId(); RequestState requestState = this.requestStateMap.get(id); if (requestState == null) { @@ -486,7 +488,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * Handle an "error" message, turning it into an {@link GraphQlResponse} * for single responses, or signaling an error for streams. */ - public void handleError(GraphQlWebSocketMessage message) { + void handleError(GraphQlWebSocketMessage message) { String id = message.getId(); RequestState requestState = this.requestStateMap.remove(id); if (requestState == null) { @@ -512,7 +514,7 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { /** * Handle a "complete" message. */ - public void handleComplete(GraphQlWebSocketMessage message) { + void handleComplete(GraphQlWebSocketMessage message) { String id = message.getId(); RequestState requestState = this.requestStateMap.remove(id); if (requestState == null) { @@ -528,22 +530,22 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { * Return a {@code Mono} that completes when the connection is closed * for any reason. */ - public Mono notifyWhenClosed() { + Mono notifyWhenClosed() { return this.connection.notifyWhenClosed(); } /** * Close the underlying connection. */ - public Mono close() { + Mono close() { return this.connection.close(CloseStatus.GOING_AWAY); } /** * Terminate and clean all in-progress requests with the given error. */ - public void terminateRequests(String message, CloseStatus status) { - this.requestStateMap.values().forEach(info -> info.emitDisconnectError(message, status)); + void terminateRequests(String message, CloseStatus status) { + this.requestStateMap.values().forEach((info) -> info.emitDisconnectError(message, status)); this.requestStateMap.clear(); } @@ -595,21 +597,21 @@ final class WebSocketGraphQlTransport implements GraphQlTransport { /** * Holds the request {@code Flux} and associated {@link FluxSink}. */ - private static class RequestSink { + private static final class RequestSink { @Nullable private FluxSink requestSink; - private final Flux requestFlux = Flux.create(sink -> { + private final Flux requestFlux = Flux.create((sink) -> { Assert.state(this.requestSink == null, "Expected single subscriber only for outbound messages"); this.requestSink = sink; }); - public Flux getRequestFlux() { + Flux getRequestFlux() { return this.requestFlux; } - public void sendRequest(GraphQlWebSocketMessage message) { + void sendRequest(GraphQlWebSocketMessage message) { Assert.state(this.requestSink != null, "Unexpected request before Flux is subscribed to"); this.requestSink.next(message); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/ArgumentValue.java b/spring-graphql/src/main/java/org/springframework/graphql/data/ArgumentValue.java index 7d35f9b1..b25f89c4 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/ArgumentValue.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/ArgumentValue.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data; @@ -39,8 +40,8 @@ import org.springframework.util.ObjectUtils; * object. * * - * @author Rossen Stoyanchev * @param the type of value contained + * @author Rossen Stoyanchev * @since 1.1.0 * @see Nullable vs Optional */ @@ -115,6 +116,7 @@ public final class ArgumentValue { /** * Static factory method for an argument value that was provided, even if * it was set to {@literal "null}. + * @param the type of value * @param value the value to hold in the instance */ public static ArgumentValue ofNullable(@Nullable T value) { @@ -123,6 +125,7 @@ public final class ArgumentValue { /** * Static factory method for an argument value that was omitted. + * @param the type of value */ @SuppressWarnings("unchecked") public static ArgumentValue omitted() { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlArgumentBinder.java b/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlArgumentBinder.java index 4bf0d545..d7f01c39 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlArgumentBinder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlArgumentBinder.java @@ -139,7 +139,7 @@ public class GraphQlArgumentBinder { DataFetchingEnvironment environment, @Nullable String name, ResolvableType targetType) throws BindException { - Object rawValue = (name != null ? environment.getArgument(name) : environment.getArguments()); + Object rawValue = (name != null) ? environment.getArgument(name) : environment.getArguments(); boolean isOmitted = (name != null && !environment.getArguments().containsKey(name)); ArgumentsBindingResult bindingResult = new ArgumentsBindingResult(targetType); @@ -246,9 +246,9 @@ public class GraphQlArgumentBinder { Constructor constructor = BeanUtils.getResolvableConstructor(targetClass); - Object value = (constructor.getParameterCount() > 0 ? + Object value = (constructor.getParameterCount() > 0) ? bindMapToObjectViaConstructor(rawMap, constructor, targetType, bindingResult) : - bindMapToObjectViaSetters(rawMap, constructor, targetType, bindingResult)); + bindMapToObjectViaSetters(rawMap, constructor, targetType, bindingResult); bindingResult.popNestedPath(); @@ -360,7 +360,7 @@ public class GraphQlArgumentBinder { Object value = null; try { TypeConverter converter = - (this.typeConverter != null ? this.typeConverter : new SimpleTypeConverter()); + (this.typeConverter != null) ? this.typeConverter : new SimpleTypeConverter(); value = converter.convertIfNecessary( rawValue, (Class) clazz, new TypeDescriptor(type, null, null)); @@ -385,9 +385,9 @@ public class GraphQlArgumentBinder { } private static String initObjectName(ResolvableType targetType) { - return (targetType.getSource() instanceof MethodParameter methodParameter ? + return (targetType.getSource() instanceof MethodParameter methodParameter) ? Conventions.getVariableNameForParameter(methodParameter) : - ClassUtils.getShortNameAsProperty(targetType.resolve(Object.class))); + ClassUtils.getShortNameAsProperty(targetType.resolve(Object.class)); } @Override @@ -400,7 +400,7 @@ public class GraphQlArgumentBinder { return null; } - public void rejectArgumentValue( + void rejectArgumentValue( String field, @Nullable Object rawValue, String code, String defaultMessage) { addError(new FieldError( diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlRepository.java b/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlRepository.java index bb47e4e5..59b60d59 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlRepository.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/GraphQlRepository.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethod.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethod.java index 9a428f90..c493bdec 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethod.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethod.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method; import java.lang.annotation.Annotation; @@ -77,6 +78,8 @@ public class HandlerMethod { /** * Constructor with a handler instance and a method. + * @param bean the handler instance + * @param method the handler method */ public HandlerMethod(Object bean, Method method) { Assert.notNull(bean, "Bean is required"); @@ -94,6 +97,9 @@ public class HandlerMethod { * Constructor with a bean name for the handler along with a {@code BeanFactory} * to allow {@link #createWithResolvedBean() resolving} the handler instance * later. + * @param beanName the bean name + * @param beanFactory the bean factory to use for bean resolution + * @param method the handler method */ public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) { Assert.hasText(beanName, "Bean name is required"); @@ -115,6 +121,7 @@ public class HandlerMethod { /** * Copy constructor for use from subclasses that accept more arguments. + * @param handlerMethod the handler method */ protected HandlerMethod(HandlerMethod handlerMethod) { this(handlerMethod, handlerMethod.bean); @@ -191,6 +198,7 @@ public class HandlerMethod { /** * Return the actual return value type. + * @param returnValue the return value instance, can be {@code null} */ public MethodParameter getReturnValueType(@Nullable Object returnValue) { return new ReturnValueMethodParameter(returnValue); @@ -208,6 +216,7 @@ public class HandlerMethod { * if no annotation can be found on the given method itself. *

Also supports merged composed annotations with attribute * overrides as of Spring Framework 4.3. + * @param the annotation type * @param annotationType the type of annotation to introspect the method for * @return the annotation, or {@code null} if none found * @see AnnotatedElementUtils#findMergedAnnotation @@ -219,6 +228,7 @@ public class HandlerMethod { /** * Return whether the parameter is declared with the given annotation type. + * @param the annotation type * @param annotationType the annotation type to look for * @see AnnotatedElementUtils#hasAnnotation */ @@ -331,6 +341,9 @@ public class HandlerMethod { * processing time may be a JDK dynamic proxy (lazy initialization, prototype * beans, and others). Endpoint classes that require proxying should prefer * class-based proxy mechanisms. + * @param method the handler method + * @param targetBean the bean instance + * @param args the method arguments */ protected void assertTargetBean(Method method, Object targetBean, Object[] args) { Class methodDeclaringClass = method.getDeclaringClass(); @@ -347,9 +360,9 @@ public class HandlerMethod { protected String formatInvokeError(String text, Object[] args) { String formattedArgs = IntStream.range(0, args.length) - .mapToObj(i -> (args[i] != null ? + .mapToObj((i) -> (args[i] != null) ? "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" : - "[" + i + "] [null]")) + "[" + i + "] [null]") .collect(Collectors.joining(",\n", " ", " ")); return text + "\n" + @@ -401,21 +414,7 @@ public class HandlerMethod { if (index < ifcAnns.length) { Annotation[] paramAnns = ifcAnns[index]; if (paramAnns.length > 0) { - List merged = new ArrayList<>(anns.length + paramAnns.length); - merged.addAll(Arrays.asList(anns)); - for (Annotation paramAnn : paramAnns) { - boolean existingType = false; - for (Annotation ann : anns) { - if (ann.annotationType() == paramAnn.annotationType()) { - existingType = true; - break; - } - } - if (!existingType) { - merged.add(adaptAnnotation(paramAnn)); - } - } - anns = merged.toArray(new Annotation[0]); + anns = mergeAnnotations(anns, paramAnns); } } } @@ -424,6 +423,25 @@ public class HandlerMethod { } return anns; } + + private Annotation[] mergeAnnotations(Annotation[] anns, Annotation[] paramAnns) { + List merged = new ArrayList<>(anns.length + paramAnns.length); + merged.addAll(Arrays.asList(anns)); + for (Annotation paramAnn : paramAnns) { + boolean existingType = false; + for (Annotation ann : anns) { + if (ann.annotationType() == paramAnn.annotationType()) { + existingType = true; + break; + } + } + if (!existingType) { + merged.add(adaptAnnotation(paramAnn)); + } + } + anns = merged.toArray(new Annotation[0]); + return anns; + } } @@ -435,7 +453,7 @@ public class HandlerMethod { @Nullable private final Object returnValue; - public ReturnValueMethodParameter(@Nullable Object returnValue) { + ReturnValueMethodParameter(@Nullable Object returnValue) { super(-1); this.returnValue = returnValue; } @@ -447,7 +465,7 @@ public class HandlerMethod { @Override public Class getParameterType() { - return (this.returnValue != null ? this.returnValue.getClass() : super.getParameterType()); + return (this.returnValue != null) ? this.returnValue.getClass() : super.getParameterType(); } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolver.java index 6e948920..e4cd87ce 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method; import graphql.schema.DataFetchingEnvironment; @@ -35,20 +36,18 @@ public interface HandlerMethodArgumentResolver { /** * Whether this resolver supports the given {@link MethodParameter}. + * @param parameter the method parameter to check for support */ boolean supportsParameter(MethodParameter parameter); /** * Resolve a method parameter to a value. - * * @param parameter the method parameter to resolve. This parameter must * have previously checked via {@link #supportsParameter}. * @param environment the environment to use to resolve the value - * * @return the resolved value, which may be {@code null} if not resolved; * the value may also be a {@link reactor.core.publisher.Mono} if it * requires asynchronous resolution. - * * @throws Exception in case of errors with the preparation of argument values */ @Nullable diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolverComposite.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolverComposite.java index dd7fd899..b94addd1 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolverComposite.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/HandlerMethodArgumentResolverComposite.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method; import java.util.ArrayList; @@ -43,6 +44,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu /** * Add the given {@link HandlerMethodArgumentResolver}. + * @param resolver the argument resolver */ public void addResolver(HandlerMethodArgumentResolver resolver) { this.argumentResolvers.add(resolver); @@ -84,10 +86,11 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu /** * Find a registered {@link HandlerMethodArgumentResolver} that supports * the given method parameter. + * @param parameter the method parameter */ @Nullable public HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { - return this.argumentResolverCache.computeIfAbsent(parameter, p -> { + return this.argumentResolverCache.computeIfAbsent(parameter, (p) -> { for (HandlerMethodArgumentResolver resolver : this.argumentResolvers) { if (resolver.supportsParameter(parameter)) { return resolver; @@ -97,4 +100,4 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu }); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/InvocableHandlerMethodSupport.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/InvocableHandlerMethodSupport.java index 2c3d4000..1cd10338 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/InvocableHandlerMethodSupport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/InvocableHandlerMethodSupport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method; import java.lang.reflect.InvocationTargetException; @@ -69,6 +70,7 @@ public abstract class InvocableHandlerMethodSupport extends HandlerMethod { /** * Invoke the handler method with the given argument values. + * @param graphQLContext the GraphQL context for this data fetching operation * @param argValues the values to use to invoke the method * @return the value returned from the method or a {@code Mono} * if the invocation fails. @@ -89,7 +91,7 @@ public abstract class InvocableHandlerMethodSupport extends HandlerMethod { } catch (IllegalArgumentException ex) { assertTargetBean(method, getBean(), argValues); - String text = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument"); + String text = (ex.getMessage() != null) ? ex.getMessage() : "Illegal argument"; return Mono.error(new IllegalStateException(formatInvokeError(text, argValues), ex)); } catch (InvocationTargetException ex) { @@ -143,15 +145,16 @@ public abstract class InvocableHandlerMethodSupport extends HandlerMethod { /** * Use this method to resolve the arguments asynchronously. This is only * useful when at least one of the values is a {@link Mono} + * @param args the arguments to be resolved asynchronously */ @SuppressWarnings("unchecked") protected Mono toArgsMono(Object[] args) { List> monoList = new ArrayList<>(); for (Object arg : args) { - Mono argMono = (arg instanceof Mono ? (Mono) arg : Mono.justOrEmpty(arg)); + Mono argMono = ((arg instanceof Mono) ? (Mono) arg : Mono.justOrEmpty(arg)); monoList.add(argMono.defaultIfEmpty(NO_VALUE)); } - return Mono.zip(monoList, values -> { + return Mono.zip(monoList, (values) -> { for (int i = 0; i < values.length; i++) { if (values[i] == NO_VALUE) { values[i] = null; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Argument.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Argument.java index 6e378f82..2ee80cbf 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Argument.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Argument.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Arguments.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Arguments.java index 0fdd7bc2..d604020a 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Arguments.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/Arguments.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java index c4ee2e85..4e695ab6 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/BatchMapping.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/ContextValue.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/ContextValue.java index 0a2e1ef2..44357931 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/ContextValue.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/ContextValue.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/GraphQlExceptionHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/GraphQlExceptionHandler.java index 9ab606f8..377401b0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/GraphQlExceptionHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/GraphQlExceptionHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/LocalContextValue.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/LocalContextValue.java index 23bc1083..9e906c49 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/LocalContextValue.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/LocalContextValue.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/MutationMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/MutationMapping.java index 727bed45..984e4b6c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/MutationMapping.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/MutationMapping.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/QueryMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/QueryMapping.java index 9abc721a..02a1bf53 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/QueryMapping.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/QueryMapping.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SchemaMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SchemaMapping.java index dff610ec..fe0cf0d7 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SchemaMapping.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SchemaMapping.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SubscriptionMapping.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SubscriptionMapping.java index c862ae13..342a9e7f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SubscriptionMapping.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/SubscriptionMapping.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation; import java.lang.annotation.Documented; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java index cba16081..720d949c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.annotation.Annotation; @@ -103,8 +104,6 @@ import org.springframework.validation.DataBinder; * is configured for use. * * - * - * * @author Rossen Stoyanchev * @author Brian Clozel * @since 1.0.0 @@ -113,17 +112,17 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I private static final ClassLoader classLoader = AnnotatedControllerConfigurer.class.getClassLoader(); - private final static boolean springDataPresent = ClassUtils.isPresent( + private static final boolean springDataPresent = ClassUtils.isPresent( "org.springframework.data.projection.SpelAwareProxyProjectionFactory", classLoader); - private final static boolean springSecurityPresent = ClassUtils.isPresent( + private static final boolean springSecurityPresent = ClassUtils.isPresent( "org.springframework.security.core.context.SecurityContext", classLoader); - private final static boolean beanValidationPresent = ClassUtils.isPresent( + private static final boolean beanValidationPresent = ClassUtils.isPresent( "jakarta.validation.executable.ExecutableValidator", classLoader); - private final static Log logger = LogFactory.getLog(AnnotatedControllerConfigurer.class); + private static final Log logger = LogFactory.getLog(AnnotatedControllerConfigurer.class); /** * Bean name prefix for target beans behind scoped proxies. Used to exclude those @@ -165,6 +164,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I * that assists in binding GraphQL arguments onto * {@link org.springframework.graphql.data.method.annotation.Argument @Argument} * annotated method parameters. + * @param registrar the formatter registrar */ public void addFormatterRegistrar(FormatterRegistrar registrar) { registrar.registerFormatters(this.conversionService); @@ -175,6 +175,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I * {@link org.springframework.graphql.data.method.annotation.Argument @Argument} * should falls back to direct field access in case the target object does * not use accessor methods. + * @param fallBackOnDirectFieldAccess whether we should fall back on direct field access * @since 1.2.0 */ public void setFallBackOnDirectFieldAccess(boolean fallBackOnDirectFieldAccess) { @@ -185,7 +186,6 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I * Add a {@link HandlerMethodArgumentResolver} for custom controller method * arguments. Such custom resolvers are ordered after built-in resolvers * except for {@link SourceMethodArgumentResolver}, which is always last. - * * @param resolver the resolver to add. * @since 1.2.0 */ @@ -206,11 +206,9 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I * exceptions from non-controller {@link DataFetcher}s since exceptions from * {@code @SchemaMapping} controller methods are handled automatically at * the point of invocation. - * * @return a resolver instance that can be plugged into * {@link org.springframework.graphql.execution.GraphQlSource.Builder#exceptionResolvers(List) * GraphQlSource.Builder} - * * @since 1.2.0 */ public DataFetcherExceptionResolver getExceptionResolver() { @@ -352,7 +350,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I else { dataFetcher = registerBatchLoader(info); } - runtimeWiringBuilder.type(info.getCoordinates().getTypeName(), typeBuilder -> + runtimeWiringBuilder.type(info.getCoordinates().getTypeName(), (typeBuilder) -> typeBuilder.dataFetcher(info.getCoordinates().getFieldName(), dataFetcher)); }); } @@ -482,17 +480,17 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I private HandlerMethod createHandlerMethod(Method method, Object handler, Class handlerType) { Method theMethod = AopUtils.selectInvocableMethod(method, handlerType); - return (handler instanceof String ? + return (handler instanceof String) ? new HandlerMethod((String) handler, obtainApplicationContext().getAutowireCapableBeanFactory(), theMethod) : - new HandlerMethod(handler, theMethod)); + new HandlerMethod(handler, theMethod); } private String formatMappings(Class handlerType, Collection infos) { String formattedType = Arrays.stream(ClassUtils.getPackageName(handlerType).split("\\.")) - .map(p -> p.substring(0, 1)) + .map((p) -> p.substring(0, 1)) .collect(Collectors.joining(".", "", "." + handlerType.getSimpleName())); return infos.stream() - .map(mappingInfo -> { + .map((mappingInfo) -> { Method method = mappingInfo.getHandlerMethod().getMethod(); String methodParameters = Arrays.stream(method.getGenericParameterTypes()) .map(Type::getTypeName) @@ -511,7 +509,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I BatchLoaderRegistry registry = obtainApplicationContext().getBean(BatchLoaderRegistry.class); BatchLoaderRegistry.RegistrationSpec registration = registry.forName(dataLoaderKey); if (info.getMaxBatchSize() > 0) { - registration.withOptions(options -> options.setMaxBatchSize(info.getMaxBatchSize())); + registration.withOptions((options) -> options.setMaxBatchSize(info.getMaxBatchSize())); } HandlerMethod handlerMethod = info.getHandlerMethod(); @@ -551,6 +549,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I * Alternative to {@link #configure(RuntimeWiring.Builder)} that registers * data fetchers in a {@link GraphQLCodeRegistry.Builder}. This could be * used with programmatic creation of {@link graphql.schema.GraphQLSchema}. + * @param codeRegistryBuilder the code registry to be processed */ @SuppressWarnings("rawtypes") public void configure(GraphQLCodeRegistry.Builder codeRegistryBuilder) { @@ -577,7 +576,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I private final HandlerMethod handlerMethod; - public MappingInfo( + MappingInfo( String typeName, String field, boolean batchMapping, int maxBatchSize, HandlerMethod handlerMethod) { @@ -587,20 +586,20 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I this.handlerMethod = handlerMethod; } - public FieldCoordinates getCoordinates() { + FieldCoordinates getCoordinates() { return this.coordinates; } @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public boolean isBatchMapping() { + boolean isBatchMapping() { return this.batchMapping; } - public int getMaxBatchSize() { + int getMaxBatchSize() { return this.maxBatchSize; } - public HandlerMethod getHandlerMethod() { + HandlerMethod getHandlerMethod() { return this.handlerMethod; } @@ -639,7 +638,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I this.argumentResolvers = argumentResolvers; this.methodValidationHelper = - (helper != null ? helper.getValidationHelperFor(info.getHandlerMethod()) : null); + (helper != null) ? helper.getValidationHelperFor(info.getHandlerMethod()) : null; // Register controllers early to validate exception handler return types Class controllerType = info.getHandlerMethod().getBeanType(); @@ -664,7 +663,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I /** * Return the {@link HandlerMethod} used to fetch data. */ - public HandlerMethod getHandlerMethod() { + HandlerMethod getHandlerMethod() { return this.info.getHandlerMethod(); } @@ -690,13 +689,13 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I DataFetchingEnvironment env, DataFetcherHandlerMethod handlerMethod, Object result) { if (this.subscription && result instanceof Publisher publisher) { - result = Flux.from(publisher).onErrorResume(ex -> handleSubscriptionError(ex, env, handlerMethod)); + result = Flux.from(publisher).onErrorResume((ex) -> handleSubscriptionError(ex, env, handlerMethod)); } else if (result instanceof Mono) { - result = ((Mono) result).onErrorResume(ex -> (Mono) handleException(ex, env, handlerMethod)); + result = ((Mono) result).onErrorResume((ex) -> (Mono) handleException(ex, env, handlerMethod)); } else if (result instanceof Flux) { - result = ((Flux) result).onErrorResume(ex -> (Mono) handleException(ex, env, handlerMethod)); + result = ((Flux) result).onErrorResume((ex) -> (Mono) handleException(ex, env, handlerMethod)); } return result; } @@ -705,7 +704,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I Throwable ex, DataFetchingEnvironment env, DataFetcherHandlerMethod handlerMethod) { return this.exceptionResolver.resolveException(ex, env, handlerMethod.getBean()) - .map(errors -> DataFetcherResult.newResult().errors(errors).build()) + .map((errors) -> DataFetcherResult.newResult().errors(errors).build()) .switchIfEmpty(Mono.error(ex)); } @@ -714,7 +713,7 @@ public class AnnotatedControllerConfigurer implements ApplicationContextAware, I Throwable ex, DataFetchingEnvironment env, DataFetcherHandlerMethod handlerMethod) { return (Publisher) this.exceptionResolver.resolveException(ex, env, handlerMethod.getBean()) - .flatMap(errors -> Mono.error(new SubscriptionPublisherException(errors, ex))) + .flatMap((errors) -> Mono.error(new SubscriptionPublisherException(errors, ex))) .switchIfEmpty(Mono.error(ex)); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java index e3a9fa56..0b814055 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; @@ -72,7 +73,6 @@ import org.springframework.web.method.ControllerAdviceBean; * * @author Rossen Stoyanchev * @author Brian Clozel - * @since 1.2.0 */ final class AnnotatedControllerExceptionResolver { @@ -98,9 +98,9 @@ final class AnnotatedControllerExceptionResolver { * are validated to ensure they are within a range of supported types. * @param controllerType the controller type to register */ - public void registerController(Class controllerType) { + void registerController(Class controllerType) { this.controllerCache.computeIfAbsent( - controllerType, type -> new MethodResolver(findExceptionHandlers(controllerType))); + controllerType, (type) -> new MethodResolver(findExceptionHandlers(controllerType))); } /** @@ -110,7 +110,7 @@ final class AnnotatedControllerExceptionResolver { * for use at runtime. * @param context the context to look into */ - public void registerControllerAdvice(ApplicationContext context) { + void registerControllerAdvice(ApplicationContext context) { Map detectedControllerAdvice = new HashMap<>(); for (ControllerAdviceBean bean : ControllerAdviceBean.findAnnotatedBeans(context)) { Class beanType = bean.getBeanType(); @@ -121,12 +121,11 @@ final class AnnotatedControllerExceptionResolver { } } } - detectedControllerAdvice.keySet().stream().sorted(OrderComparator.INSTANCE).forEach(bean -> { - this.controllerAdviceCache.put(bean, detectedControllerAdvice.get(bean)); - }); + detectedControllerAdvice.keySet().stream().sorted(OrderComparator.INSTANCE).forEach((bean) -> + this.controllerAdviceCache.put(bean, detectedControllerAdvice.get(bean))); if (logger.isDebugEnabled()) { logger.debug("@GraphQlException methods in ControllerAdvice beans: " + - (this.controllerAdviceCache.size() == 0 ? "none" : this.controllerAdviceCache.size())); + ((this.controllerAdviceCache.size() == 0) ? "none" : this.controllerAdviceCache.size())); } } @@ -134,7 +133,7 @@ final class AnnotatedControllerExceptionResolver { private static Map, Method> findExceptionHandlers(Class handlerType) { Map handlerMap = MethodIntrospector.selectMethods( - handlerType, (MethodIntrospector.MetadataLookup) method -> + handlerType, (MethodIntrospector.MetadataLookup) (method) -> AnnotatedElementUtils.findMergedAnnotation(method, GraphQlExceptionHandler.class)); Map, Method> mappings = new HashMap<>(handlerMap.size()); @@ -172,7 +171,7 @@ final class AnnotatedControllerExceptionResolver { * @return a {@code Mono} with resolved {@code GraphQLError}s as specified in * {@link DataFetcherExceptionResolver#resolveException(Throwable, DataFetchingEnvironment)} */ - public Mono> resolveException( + Mono> resolveException( Throwable ex, DataFetchingEnvironment environment, @Nullable Object controller) { Object controllerOrAdvice = null; @@ -229,7 +228,7 @@ final class AnnotatedControllerExceptionResolver { while (exToExpose != null) { exceptions.add(exToExpose); Throwable cause = exToExpose.getCause(); - exToExpose = (cause != exToExpose ? cause : null); + exToExpose = (cause != exToExpose) ? cause : null; } Object[] arguments = new Object[exceptions.size() + 1]; exceptions.toArray(arguments); // efficient arraycopy call in ArrayList @@ -277,7 +276,7 @@ final class AnnotatedControllerExceptionResolver { * @return the exception handler to use, or {@code null} if no match */ @Nullable - public MethodHolder resolveMethod(Throwable exception) { + MethodHolder resolveMethod(Throwable exception) { MethodHolder method = resolveMethodByExceptionType(exception.getClass()); if (method == null) { Throwable cause = exception.getCause(); @@ -295,7 +294,7 @@ final class AnnotatedControllerExceptionResolver { method = getMappedMethod(exceptionType); this.resolvedExceptionCache.put(exceptionType, method); } - return (method != NO_MATCH ? method : null); + return (method != NO_MATCH) ? method : null; } private MethodHolder getMappedMethod(Class exceptionType) { @@ -341,11 +340,11 @@ final class AnnotatedControllerExceptionResolver { this.adapter = ReturnValueAdapter.createFor(this.returnType); } - public Method getMethod() { + Method getMethod() { return this.method; } - public Mono> adapt(@Nullable Object result, Throwable ex) { + Mono> adapt(@Nullable Object result, Throwable ex) { return this.adapter.adapt(result, this.returnType, ex); } @@ -420,24 +419,24 @@ final class AnnotatedControllerExceptionResolver { } - /** Adapter for void */ + /* Adapter for void */ ReturnValueAdapter forVoid = (result, returnType, ex) -> Mono.just(Collections.emptyList()); - /** Adapter for a single GraphQLError */ + /* Adapter for a single GraphQLError */ ReturnValueAdapter forSingleError = (result, returnType, ex) -> - (result == null ? - Mono.empty() : - Mono.just(Collections.singletonList((GraphQLError) result))); + (result != null) ? + Mono.just(Collections.singletonList((GraphQLError) result)) : + Mono.empty(); - /** Adapter for a collection of GraphQLError's */ + /* Adapter for a collection of GraphQLError's */ ReturnValueAdapter forCollection = (result, returnType, ex) -> - (result == null ? - Mono.empty() : - Mono.just((result instanceof List ? + (result != null) ? + Mono.just((result instanceof List) ? (List) result : - new ArrayList<>((Collection) result)))); + new ArrayList<>((Collection) result)) : + Mono.empty(); - /** Adapter for Object */ + /* Adapter for Object */ ReturnValueAdapter forObject = (result, returnType, ex) -> { if (result == null) { return Mono.empty(); @@ -457,15 +456,15 @@ final class AnnotatedControllerExceptionResolver { } }; - /** Adapter for {@code Mono} */ + /* Adapter for {@code Mono} */ ReturnValueAdapter forMonoVoid = (result, returnType, ex) -> - (result == null ? Mono.empty() : Mono.just(Collections.emptyList())); + (result != null) ? Mono.just(Collections.emptyList()) : Mono.empty(); - /** Adapter for a {@code Mono} wrapping any of the other synchronous return value types */ + /* Adapter for a {@code Mono} wrapping any of the other synchronous return value types */ ReturnValueAdapter forMono = (result, returnType, ex) -> - (result == null ? - Mono.empty() : - ((Mono) result).flatMap(o -> forObject.adapt(o, returnType, ex)).switchIfEmpty(Mono.error(ex))); + (result != null) ? + ((Mono) result).flatMap((o) -> forObject.adapt(o, returnType, ex)).switchIfEmpty(Mono.error(ex)) : + Mono.empty(); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolver.java index 854591d4..602c912b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import graphql.schema.DataFetchingEnvironment; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentValueValueExtractor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentValueValueExtractor.java index f2f71c74..bf8eb572 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentValueValueExtractor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentValueValueExtractor.java @@ -19,22 +19,24 @@ package org.springframework.graphql.data.method.annotation.support; import jakarta.validation.valueextraction.ExtractedValue; import jakarta.validation.valueextraction.UnwrapByDefault; import jakarta.validation.valueextraction.ValueExtractor; + import org.springframework.graphql.data.ArgumentValue; /** * {@link ValueExtractor} that enables {@code @Valid} with {@link ArgumentValue}, * and helps to extract the value from it. * + * @author Rossen Stoyanchev * @since 1.2.2 */ @UnwrapByDefault public final class ArgumentValueValueExtractor implements ValueExtractor> { - @Override - public void extractValues(ArgumentValue argumentValue, ValueReceiver receiver) { - if (!argumentValue.isOmitted()) { - receiver.value(null, argumentValue.value()); - } - } + @Override + public void extractValues(ArgumentValue argumentValue, ValueReceiver receiver) { + if (!argumentValue.isOmitted()) { + receiver.value(null, argumentValue.value()); + } + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolver.java index 4b4bfa6c..3291fb8c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import graphql.schema.DataFetchingEnvironment; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolver.java index 08d39a38..6a077057 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.annotation.Annotation; @@ -97,7 +98,7 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg @Override public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception { return getCurrentAuthentication(parameter) - .mapNotNull(auth -> resolvePrincipal(parameter, auth.getPrincipal())) + .mapNotNull((auth) -> resolvePrincipal(parameter, auth.getPrincipal())) .transform((argument) -> isPublisherOrMono(parameter) ? Mono.just(argument) : argument); } @@ -109,7 +110,7 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg @SuppressWarnings("unchecked") private Mono getCurrentAuthentication(MethodParameter parameter) { Object value = PrincipalMethodArgumentResolver.resolveAuthentication(parameter); - return (value instanceof Authentication auth ? Mono.just(auth) : (Mono) value); + return (value instanceof Authentication auth) ? Mono.just(auth) : (Mono) value; } @Nullable diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/BatchLoaderHandlerMethod.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/BatchLoaderHandlerMethod.java index 0a255542..34f30922 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/BatchLoaderHandlerMethod.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/BatchLoaderHandlerMethod.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.security.Principal; @@ -50,7 +51,7 @@ import org.springframework.util.ClassUtils; */ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { - private final static boolean springSecurityPresent = ClassUtils.isPresent( + private static final boolean springSecurityPresent = ClassUtils.isPresent( "org.springframework.security.core.context.SecurityContext", AnnotatedControllerConfigurer.class.getClassLoader()); @@ -66,7 +67,6 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { /** * Invoke the underlying batch loader method with a collection of keys to * return a Map of key-value pairs. - * * @param keys the keys for which to load values * @param environment the environment available to batch loaders * @param the type of keys in the map @@ -80,7 +80,7 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { Object result = doInvoke(environment.getContext(), args); return toMonoMap(result); } - return toArgsMono(args).flatMap(argValues -> { + return toArgsMono(args).flatMap((argValues) -> { Object result = doInvoke(environment.getContext(), argValues); return toMonoMap(result); }); @@ -89,7 +89,6 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { /** * Invoke the underlying batch loader method with a collection of input keys * to return a collection of matching values. - * * @param keys the keys for which to load values * @param environment the environment available to batch loaders * @param the type of values returned @@ -101,7 +100,7 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { Object result = doInvoke(environment.getContext(), args); return toFlux(result); } - return toArgsMono(args).flatMapMany(resolvedArgs -> { + return toArgsMono(args).flatMapMany((resolvedArgs) -> { Object result = doInvoke(environment.getContext(), resolvedArgs); return toFlux(result); }); @@ -164,7 +163,7 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { } private boolean doesNotHaveAsyncArgs(Object[] args) { - return Arrays.stream(args).noneMatch(arg -> arg instanceof Mono); + return Arrays.stream(args).noneMatch((arg) -> arg instanceof Mono); } @SuppressWarnings("unchecked") @@ -176,7 +175,7 @@ public class BatchLoaderHandlerMethod extends InvocableHandlerMethodSupport { return (Mono>) result; } else if (result instanceof CompletableFuture) { - return Mono.fromFuture((CompletableFuture>) result); + return Mono.fromFuture((CompletableFuture>) result); } return Mono.error(new IllegalStateException("Unexpected return value: " + result)); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolver.java index 1335c00f..1537dff9 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.annotation.Annotation; @@ -72,7 +73,7 @@ public class ContextValueMethodArgumentResolver implements HandlerMethodArgument @Nullable GraphQLContext graphQlContext) { Class parameterType = parameter.getParameterType(); - Object value = (graphQlContext != null ? graphQlContext.get(contextValueName) : null); + Object value = (graphQlContext != null) ? graphQlContext.get(contextValueName) : null; boolean isOptional = parameterType.equals(Optional.class); boolean isMono = parameterType.equals(Mono.class); @@ -85,14 +86,14 @@ public class ContextValueMethodArgumentResolver implements HandlerMethodArgument if (value == null) { value = Mono.empty(); } - else if (!( value instanceof Mono)) { + else if (!(value instanceof Mono)) { value = Mono.just(value); } return Mono.just(value); } if (isOptional) { - return (value instanceof Optional ? value : Optional.ofNullable(value)); + return (value instanceof Optional) ? value : Optional.ofNullable(value); } return value; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContinuationHandlerMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContinuationHandlerMethodArgumentResolver.java index 51613f45..903e5666 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContinuationHandlerMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ContinuationHandlerMethodArgumentResolver.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import graphql.schema.DataFetchingEnvironment; + import org.springframework.core.MethodParameter; import org.springframework.graphql.data.method.HandlerMethodArgumentResolver; @@ -27,14 +29,14 @@ import org.springframework.graphql.data.method.HandlerMethodArgumentResolver; */ public class ContinuationHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { - @Override - public boolean supportsParameter(MethodParameter parameter) { - return "kotlin.coroutines.Continuation".equals(parameter.getParameterType().getName()); - } + @Override + public boolean supportsParameter(MethodParameter parameter) { + return "kotlin.coroutines.Continuation".equals(parameter.getParameterType().getName()); + } - @Override - public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) { - return null; - } + @Override + public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) { + return null; + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethod.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethod.java index 0eadc916..8bd208d7 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethod.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethod.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.Arrays; +import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BiConsumer; @@ -52,7 +54,7 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { private final HandlerMethodArgumentResolverComposite resolvers; private final BiConsumer validationHelper; - + private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); private final boolean subscription; @@ -63,6 +65,7 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { * @param handlerMethod the handler method * @param resolvers the argument resolvers * @param validationHelper to apply bean validation with + * @param executor an {@link Executor} to use for {@link Callable} return values * @param subscription whether the field being fetched is of subscription type */ public DataFetcherHandlerMethod( @@ -73,7 +76,7 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { super(handlerMethod, executor); Assert.isTrue(!resolvers.getResolvers().isEmpty(), "No argument resolvers"); this.resolvers = resolvers; - this.validationHelper = (validationHelper != null ? validationHelper : (controller, args) -> {}); + this.validationHelper = (validationHelper != null) ? validationHelper : (controller, args) -> { }; this.subscription = subscription; } @@ -95,9 +98,7 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { * The {@code providedArgs} parameter however may supply argument values to * be used directly, i.e. without argument resolution. Provided argument * values are checked before argument resolvers. - * * @param environment the environment to resolve arguments from - * * @return the raw value returned by the invoked method, possibly a * {@code Mono} in case a method argument requires asynchronous resolution; * {@code Mono} is returned if invocation fails. @@ -110,6 +111,8 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { /** * Variant of {@link #invoke(DataFetchingEnvironment)} that also accepts * "given" arguments, which are matched by type. + * @param environment the data fetching environment for this operation + * @param providedArgs the argument values to be used directly * @since 1.2.0 */ @Nullable @@ -122,17 +125,17 @@ public class DataFetcherHandlerMethod extends InvocableHandlerMethodSupport { return Mono.error(ex); } - if (Arrays.stream(args).noneMatch(arg -> arg instanceof Mono)) { + if (Arrays.stream(args).noneMatch((arg) -> arg instanceof Mono)) { return validateAndInvoke(args, environment); } return this.subscription ? - toArgsMono(args).flatMapMany(argValues -> { + toArgsMono(args).flatMapMany((argValues) -> { Object result = validateAndInvoke(argValues, environment); Assert.state(result instanceof Publisher, "Expected a Publisher from a Subscription response"); return Flux.from((Publisher) result); }) : - toArgsMono(args).flatMap(argValues -> { + toArgsMono(args).flatMap((argValues) -> { Object result = validateAndInvoke(argValues, environment); if (result instanceof Mono mono) { return mono; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentMethodArgumentResolver.java index 9d7313f3..577a9e4c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.Locale; @@ -27,7 +28,7 @@ import org.springframework.graphql.data.method.HandlerMethodArgumentResolver; /** * Resolver for {@link DataFetchingEnvironment} and related values that can be - * accessed through the {@link DataFetchingEnvironment} such as: + * accessed through the {@link DataFetchingEnvironment}. This includes: *
    *
  • {@link GraphQLContext} *
  • {@link DataFetchingFieldSelectionSet} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataLoaderMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataLoaderMethodArgumentResolver.java index a23f5aa6..02d2155e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataLoaderMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/DataLoaderMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.ParameterizedType; @@ -41,7 +42,7 @@ import org.springframework.util.Assert; * @since 1.0.0 */ public class DataLoaderMethodArgumentResolver implements HandlerMethodArgumentResolver { - + @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.getParameterType().equals(DataLoader.class); @@ -80,8 +81,8 @@ public class DataLoaderMethodArgumentResolver implements HandlerMethodArgumentRe ParameterizedType parameterizedType = (ParameterizedType) genericType; if (parameterizedType.getActualTypeArguments().length == 2) { Type valueType = parameterizedType.getActualTypeArguments()[1]; - return (valueType instanceof Class ? - (Class) valueType : ResolvableType.forType(valueType).resolve()); + return (valueType instanceof Class) ? + (Class) valueType : ResolvableType.forType(valueType).resolve(); } } return null; @@ -92,7 +93,7 @@ public class DataLoaderMethodArgumentResolver implements HandlerMethodArgumentRe @Nullable Class valueType, @Nullable String parameterName) { String message = "Cannot resolve DataLoader for parameter" + - (parameterName != null ? " '" + parameterName + "'" : "[" + parameter.getParameterIndex() + "]" ) + + ((parameterName != null) ? " '" + parameterName + "'" : "[" + parameter.getParameterIndex() + "]") + " in method " + parameter.getMethod().toGenericString() + ". "; if (valueType == null) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolver.java index 26e6bcc3..5915bdc9 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import graphql.GraphQLContext; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/PrincipalMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/PrincipalMethodArgumentResolver.java index eb989c90..101c96d8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/PrincipalMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/PrincipalMethodArgumentResolver.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.security.Principal; import graphql.schema.DataFetchingEnvironment; +import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; import org.springframework.graphql.data.method.HandlerMethodArgumentResolver; @@ -26,7 +28,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.ReactiveSecurityContextHolder; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; -import reactor.core.publisher.Mono; /** * Resolver to obtain {@link Principal} from Spring Security context via diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolver.java index 223347f4..628f7a30 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolver.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; @@ -75,7 +76,7 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu Assert.notNull(applicationContext, "ApplicationContext must not be null"); this.projectionFactory.setBeanFactory(applicationContext); ClassLoader classLoader = applicationContext.getClassLoader(); - if(classLoader != null) { + if (classLoader != null) { this.projectionFactory.setBeanClassLoader(classLoader); } } @@ -98,8 +99,8 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu private static Class getTargetType(MethodParameter parameter) { Class type = parameter.getParameterType(); - return (type.equals(Optional.class) || type.equals(ArgumentValue.class) ? - parameter.nested().getNestedParameterType() : parameter.getParameterType()); + return (type.equals(Optional.class) || type.equals(ArgumentValue.class)) ? + parameter.nested().getNestedParameterType() : parameter.getParameterType(); } @Override @@ -117,15 +118,15 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu } Map arguments = environment.getArguments(); - Object rawValue = (name != null ? arguments.get(name) : arguments); - Object value = (rawValue != null ? createProjection(targetType, rawValue) : null); + Object rawValue = (name != null) ? arguments.get(name) : arguments; + Object value = (rawValue != null) ? createProjection(targetType, rawValue) : null; if (isOptional) { return Optional.ofNullable(value); } else if (isArgumentValue) { - return (name != null && arguments.containsKey(name) ? - ArgumentValue.ofNullable(value) : ArgumentValue.omitted()); + return (name != null && arguments.containsKey(name)) ? + ArgumentValue.ofNullable(value) : ArgumentValue.omitted(); } else { return value; @@ -140,7 +141,7 @@ public class ProjectedPayloadMethodArgumentResolver implements HandlerMethodArgu * or the map of arguments * @return the created project instance */ - protected Object createProjection(Class targetType, Object rawValue){ + protected Object createProjection(Class targetType, Object rawValue) { return this.projectionFactory.createProjection(targetType, rawValue); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessor.java index bc4676b9..397e9daa 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessor.java @@ -54,8 +54,6 @@ import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.web.bind.annotation.ControllerAdvice; -import static org.springframework.core.annotation.MergedAnnotations.SearchStrategy.TYPE_HIERARCHY; - /** * {@link BeanFactoryInitializationAotProcessor} implementation for registering * runtime hints discoverable through GraphQL controllers, such as: @@ -80,11 +78,10 @@ import static org.springframework.core.annotation.MergedAnnotations.SearchStrate * * @author Brian Clozel * @see org.springframework.graphql.data.method.HandlerMethodArgumentResolver - * @since 1.1.0 */ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor { - private final static boolean springDataPresent = ClassUtils.isPresent( + private static final boolean springDataPresent = ClassUtils.isPresent( "org.springframework.data.projection.SpelAwareProxyProjectionFactory", SchemaMappingBeanFactoryInitializationAotProcessor.class.getClassLoader()); @@ -94,8 +91,8 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI List> controllers = new ArrayList<>(); List> controllerAdvices = new ArrayList<>(); Arrays.stream(beanFactory.getBeanDefinitionNames()) - .map(beanName -> RegisteredBean.of(beanFactory, beanName).getBeanClass()) - .forEach(beanClass -> { + .map((beanName) -> RegisteredBean.of(beanFactory, beanName).getBeanClass()) + .forEach((beanClass) -> { if (isController(beanClass)) { controllers.add(beanClass); } @@ -107,11 +104,11 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI } private boolean isController(AnnotatedElement element) { - return MergedAnnotations.from(element, TYPE_HIERARCHY).isPresent(Controller.class); + return MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).isPresent(Controller.class); } private boolean isControllerAdvice(AnnotatedElement element) { - return MergedAnnotations.from(element, TYPE_HIERARCHY).isPresent(ControllerAdvice.class); + return MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).isPresent(ControllerAdvice.class); } @@ -124,7 +121,7 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI private final HandlerMethodArgumentResolverComposite argumentResolvers; - public SchemaMappingBeanFactoryInitializationAotContribution(List> controllers, List> controllerAdvices) { + SchemaMappingBeanFactoryInitializationAotContribution(List> controllers, List> controllerAdvices) { this.controllers = controllers; this.controllerAdvices = controllerAdvices; this.argumentResolvers = createArgumentResolvers(); @@ -141,19 +138,19 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI public void applyTo(GenerationContext context, BeanFactoryInitializationCode initializationCode) { RuntimeHints runtimeHints = context.getRuntimeHints(); registerSpringDataSpelSupport(runtimeHints); - this.controllers.forEach(controller -> { + this.controllers.forEach((controller) -> { runtimeHints.reflection().registerType(controller, MemberCategory.INTROSPECT_DECLARED_METHODS); ReflectionUtils.doWithMethods(controller, - method -> processSchemaMappingMethod(runtimeHints, method), + (method) -> processSchemaMappingMethod(runtimeHints, method), this::isGraphQlHandlerMethod); ReflectionUtils.doWithMethods(controller, - method -> processExceptionHandlerMethod(runtimeHints, method), + (method) -> processExceptionHandlerMethod(runtimeHints, method), this::isExceptionHandlerMethod); }); - this.controllerAdvices.forEach(controllerAdvice -> { + this.controllerAdvices.forEach((controllerAdvice) -> { runtimeHints.reflection().registerType(controllerAdvice, MemberCategory.INTROSPECT_DECLARED_METHODS); ReflectionUtils.doWithMethods(controllerAdvice, - method -> processExceptionHandlerMethod(runtimeHints, method), + (method) -> processExceptionHandlerMethod(runtimeHints, method), this::isExceptionHandlerMethod); }); } @@ -163,18 +160,18 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI runtimeHints.reflection() .registerType(SpelAwareProxyProjectionFactory.class) .registerType(TypeReference.of("org.springframework.data.projection.SpelEvaluatingMethodInterceptor$TargetWrapper"), - builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + (builder) -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS)); } } private boolean isGraphQlHandlerMethod(AnnotatedElement element) { - MergedAnnotations annotations = MergedAnnotations.from(element, TYPE_HIERARCHY); + MergedAnnotations annotations = MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY); return annotations.isPresent(SchemaMapping.class) || annotations.isPresent(BatchMapping.class); } private boolean isExceptionHandlerMethod(AnnotatedElement element) { - return MergedAnnotations.from(element, TYPE_HIERARCHY).isPresent(GraphQlExceptionHandler.class); + return MergedAnnotations.from(element, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY).isPresent(GraphQlExceptionHandler.class); } private void processSchemaMappingMethod(RuntimeHints runtimeHints, Method method) { @@ -229,7 +226,7 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI } - private static class NoHintsRequired implements MethodParameterRuntimeHintsRegistrar { + private static final class NoHintsRequired implements MethodParameterRuntimeHintsRegistrar { @Override public void apply(RuntimeHints runtimeHints) { @@ -242,14 +239,14 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI private final MethodParameter methodParameter; - public ArgumentBindingHints(MethodParameter methodParameter) { + ArgumentBindingHints(MethodParameter methodParameter) { this.methodParameter = methodParameter; } @Override public void apply(RuntimeHints runtimeHints) { Type parameterType = this.methodParameter.getGenericParameterType(); - if (ArgumentValue.class.isAssignableFrom(methodParameter.getParameterType())) { + if (ArgumentValue.class.isAssignableFrom(this.methodParameter.getParameterType())) { parameterType = this.methodParameter.nested().getNestedGenericParameterType(); } bindingRegistrar.registerReflectionHints(runtimeHints.reflection(), parameterType); @@ -261,7 +258,7 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI private final MethodParameter methodParameter; - public DataLoaderHints(MethodParameter methodParameter) { + DataLoaderHints(MethodParameter methodParameter) { this.methodParameter = methodParameter; } @@ -277,7 +274,7 @@ class SchemaMappingBeanFactoryInitializationAotProcessor implements BeanFactoryI private final MethodParameter methodParameter; - public ProjectedPayloadHints(MethodParameter methodParameter) { + ProjectedPayloadHints(MethodParameter methodParameter) { this.methodParameter = methodParameter; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SortMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SortMethodArgumentResolver.java index 851ce1b4..30d9e2c7 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SortMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SortMethodArgumentResolver.java @@ -57,11 +57,11 @@ public class SortMethodArgumentResolver implements HandlerMethodArgumentResolver Sort sort = this.sortStrategy.extract(environment); if (parameter.isOptional()) { - sort = (sort == Sort.unsorted() ? null : sort); + sort = (sort == Sort.unsorted()) ? null : sort; return Optional.ofNullable(sort); } - return (sort != null ? sort : Sort.unsorted()); + return (sort != null) ? sort : Sort.unsorted(); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SourceMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SourceMethodArgumentResolver.java index 83c0be24..b5fdbea0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SourceMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SourceMethodArgumentResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.net.URI; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SubrangeMethodArgumentResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SubrangeMethodArgumentResolver.java index e39ef21b..949b39b9 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SubrangeMethodArgumentResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SubrangeMethodArgumentResolver.java @@ -30,6 +30,7 @@ import org.springframework.util.Assert; * Resolver for a method argument of type {@link Subrange} initialized * from "first", "last", "before", and "after" GraphQL arguments. * + * @param

    the type of position in the subrange * @author Rossen Stoyanchev * @since 1.2.0 */ @@ -62,12 +63,15 @@ public class SubrangeMethodArgumentResolver

    implements HandlerMethodArgumentR forward = false; } } - P pos = (cursor != null ? this.cursorStrategy.fromCursor(cursor) : null); + P pos = (cursor != null) ? this.cursorStrategy.fromCursor(cursor) : null; return createSubrange(pos, count, forward); } /** * Allows subclasses to create an extension of {@link Subrange}. + * @param pos the position in the subrange + * @param count the number of elements in the subrange + * @param forward whether the scroll direction is forward or backward from this position */ protected Subrange

    createSubrange(@Nullable P pos, @Nullable Integer count, boolean forward) { return new Subrange<>(pos, count, forward); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ValidationHelper.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ValidationHelper.java index ea189963..778eb614 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ValidationHelper.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/ValidationHelper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.annotation.Annotation; @@ -43,9 +44,8 @@ import org.springframework.validation.beanvalidation.SpringValidatorAdapter; * requires bean validation. * * @author Rossen Stoyanchev - * @since 1.2.0 */ -class ValidationHelper { +final class ValidationHelper { private final Validator validator; @@ -62,7 +62,7 @@ class ValidationHelper { * {@link Validated}, {@link Valid}, or {@link Constraint} annotations. */ @Nullable - public BiConsumer getValidationHelperFor(HandlerMethod handlerMethod) { + BiConsumer getValidationHelperFor(HandlerMethod handlerMethod) { boolean requiresMethodValidation = false; Class[] methodValidationGroups = null; @@ -88,18 +88,18 @@ class ValidationHelper { } else if (annot.annotationType().equals(Validated.class)) { Class[] groups = ((Validated) annot).value(); - parameterValidator = (parameterValidator != null ? + parameterValidator = (parameterValidator != null) ? parameterValidator.andThen(new MethodParameterValidator(i, groups)) : - new MethodParameterValidator(i, groups)); + new MethodParameterValidator(i, groups); } } } - BiConsumer result = (requiresMethodValidation ? - new HandlerMethodValidator(handlerMethod, methodValidationGroups) : null); + BiConsumer result = (requiresMethodValidation) ? + new HandlerMethodValidator(handlerMethod, methodValidationGroups) : null; if (parameterValidator != null) { - return (result != null ? result.andThen(parameterValidator) : parameterValidator); + return (result != null) ? result.andThen(parameterValidator) : parameterValidator; } return result; @@ -120,7 +120,7 @@ class ValidationHelper { * {@link Validator} bean declared, or {@code null} otherwise. */ @Nullable - public static ValidationHelper createIfValidatorPresent(ApplicationContext context) { + static ValidationHelper createIfValidatorPresent(ApplicationContext context) { Validator validator = context.getBeanProvider(Validator.class).getIfAvailable(); if (validator instanceof LocalValidatorFactoryBean) { validator = ((LocalValidatorFactoryBean) validator).getValidator(); @@ -128,13 +128,13 @@ class ValidationHelper { else if (validator instanceof SpringValidatorAdapter) { validator = validator.unwrap(Validator.class); } - return (validator != null ? create(validator) : null); + return (validator != null) ? create(validator) : null; } /** * Factory method with a given {@link Validator} instance. */ - public static ValidationHelper create(Validator validator) { + static ValidationHelper create(Validator validator) { return new ValidationHelper(validator); } @@ -151,7 +151,7 @@ class ValidationHelper { HandlerMethodValidator(HandlerMethod handlerMethod, @Nullable Class[] validationGroups) { Assert.notNull(handlerMethod, "HandlerMethod is required"); this.method = handlerMethod.getMethod(); - this.validationGroups = (validationGroups != null ? validationGroups : new Class[] {}); + this.validationGroups = (validationGroups != null) ? validationGroups : new Class[] {}; } @Override @@ -181,7 +181,7 @@ class ValidationHelper { MethodParameterValidator(int index, @Nullable Class[] validationGroups) { this.index = index; - this.validationGroups = (validationGroups != null ? validationGroups : new Class[] {}); + this.validationGroups = (validationGroups != null) ? validationGroups : new Class[] {}; } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/package-info.java b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/package-info.java index 9c464ed1..fea82553 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/package-info.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/package-info.java @@ -1,3 +1,19 @@ +/* + * Copyright 2020-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /** * Resolvers for method parameters of annotated handler methods. */ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Base64CursorEncoder.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Base64CursorEncoder.java index 333874ba..f201e011 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Base64CursorEncoder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Base64CursorEncoder.java @@ -28,7 +28,6 @@ import java.util.Base64; *

    To create an instance, use {@link CursorEncoder#base64()}. * * @author Rossen Stoyanchev - * @since 1.2.0 */ final class Base64CursorEncoder implements CursorEncoder { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CompositeConnectionAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CompositeConnectionAdapter.java index 06e05e74..4c79a3b8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CompositeConnectionAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CompositeConnectionAdapter.java @@ -27,7 +27,6 @@ import org.springframework.util.Assert; * the first one that supports a given Object container type, and delegates to it. * * @author Rossen Stoyanchev - * @since 1.2.0 */ final class CompositeConnectionAdapter implements ConnectionAdapter { @@ -45,18 +44,22 @@ final class CompositeConnectionAdapter implements ConnectionAdapter { return (getAdapter(containerType) != null); } + @Override public Collection getContent(Object container) { return getRequiredAdapter(container).getContent(container); } + @Override public boolean hasPrevious(Object container) { return getRequiredAdapter(container).hasPrevious(container); } + @Override public boolean hasNext(Object container) { return getRequiredAdapter(container).hasNext(container); } + @Override public String cursorAt(Object container, int index) { return getRequiredAdapter(container).cursorAt(container, index); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapter.java index e332261d..f5e7f6f6 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapter.java @@ -30,26 +30,33 @@ public interface ConnectionAdapter { /** * Whether the adapter supports the given Object container type. + * @param containerType the container type to check for support */ boolean supports(Class containerType); /** * Return the contained items as a List. + * @param the type of objects in the collection + * @param container the container of elements */ Collection getContent(Object container); /** * Whether there are more pages before this one. + * @param container the container of elements */ boolean hasPrevious(Object container); /** * Whether there are more pages after this one. + * @param container the container of elements */ boolean hasNext(Object container); /** * Return a cursor for the item at the given index. + * @param container the container of elements + * @param index the index of an element in the container */ String cursorAt(Object container, int index); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapterSupport.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapterSupport.java index 752d90bb..7fa4886d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapterSupport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionAdapterSupport.java @@ -22,6 +22,7 @@ import org.springframework.util.Assert; * Convenient base class for implementations of * {@link org.springframework.graphql.data.pagination.ConnectionAdapter}. * + * @param

    the position type * @author Rossen Stoyanchev * @since 1.2.0 */ @@ -32,6 +33,7 @@ public class ConnectionAdapterSupport

    { /** * Constructor with a {@link CursorStrategy} to use. + * @param cursorStrategy the cursor strategy to use */ protected ConnectionAdapterSupport(CursorStrategy

    cursorStrategy) { Assert.notNull(cursorStrategy, "CursorStrategy is required"); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java index 8b8a3347..7455e605 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/ConnectionFieldTypeVisitor.java @@ -143,7 +143,7 @@ public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub { @Nullable private static GraphQLObjectType getAsObjectType(@Nullable GraphQLFieldDefinition field) { - return (getType(field) instanceof GraphQLObjectType type ? type : null); + return (getType(field) instanceof GraphQLObjectType type) ? type : null; } @Nullable @@ -162,7 +162,7 @@ public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub { return null; } GraphQLOutputType type = field.getType(); - return (type instanceof GraphQLNonNull nonNullType ? nonNullType.getWrappedType() : type); + return (type instanceof GraphQLNonNull nonNullType) ? nonNullType.getWrappedType() : type; } @@ -183,7 +183,7 @@ public final class ConnectionFieldTypeVisitor extends GraphQLTypeVisitorStub { */ private record ConnectionDataFetcher(DataFetcher delegate, ConnectionAdapter adapter) implements DataFetcher { - private final static Connection EMPTY_CONNECTION = + private static final Connection EMPTY_CONNECTION = new DefaultConnection<>(Collections.emptyList(), new DefaultPageInfo(null, null, false, false)); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CursorStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CursorStrategy.java index 6691560f..e1805a46 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CursorStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/CursorStrategy.java @@ -24,6 +24,7 @@ package org.springframework.graphql.data.pagination; * {@link #withEncoder(CursorStrategy, CursorEncoder)} to further encode and * decode cursor Strings to make them opaque for clients. * + * @param

    the type of position * @author Rossen Stoyanchev * @since 1.2.0 */ @@ -31,6 +32,7 @@ public interface CursorStrategy

    { /** * Whether the strategy supports the given type of position Object. + * @param targetType the type of position to be checked */ boolean supports(Class targetType); @@ -52,6 +54,9 @@ public interface CursorStrategy

    { /** * Decorate the given {@code CursorStrategy} with encoding and decoding * that makes the String cursor opaque to clients. + * @param the type of position for the given strategy + * @param strategy the cursor strategy to decorate + * @param encoder strategy for encoding the cursor */ static EncodingCursorStrategy withEncoder(CursorStrategy strategy, CursorEncoder encoder) { return new EncodingCursorStrategy<>(strategy, encoder); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/EncodingCursorStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/EncodingCursorStrategy.java index 0f7b9fb9..071260a4 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/EncodingCursorStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/EncodingCursorStrategy.java @@ -25,6 +25,7 @@ import org.springframework.util.Assert; *

    To create an instance, use * {@link CursorStrategy#withEncoder(CursorStrategy, CursorEncoder)}. * + * @param the type of position * @author Rossen Stoyanchev * @since 1.2.0 */ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/NoOpCursorEncoder.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/NoOpCursorEncoder.java index 2be8a430..dff4000c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/NoOpCursorEncoder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/NoOpCursorEncoder.java @@ -22,7 +22,6 @@ package org.springframework.graphql.data.pagination; *

    To create an instance, use {@link CursorEncoder#noOpEncoder()}. * * @author Rossen Stoyanchev - * @since 1.2.0 */ final class NoOpCursorEncoder implements CursorEncoder { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Subrange.java b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Subrange.java index abd98724..bf390fd0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Subrange.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/pagination/Subrange.java @@ -26,6 +26,7 @@ import org.springframework.lang.Nullable; * Container for parameters that limit result elements to a subrange including a * relative position, number of elements, and direction. * + * @param

    the type of position in the entire collection * @author Rossen Stoyanchev * @since 1.2.0 */ @@ -41,10 +42,13 @@ public class Subrange

    { /** * Constructor with the relative position, count, and direction. + * @param position the position in the entire collection + * @param count the number of elements in the subrange + * @param forward whether the subrange is forward or backward from ths position */ public Subrange(@Nullable P position, @Nullable Integer count, boolean forward) { this.position = Optional.ofNullable(position); - this.count = (count != null ? OptionalInt.of(count) : OptionalInt.empty()); + this.count = (count != null) ? OptionalInt.of(count) : OptionalInt.empty(); this.forward = forward; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AbstractSortStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AbstractSortStrategy.java index 35890390..ad182c30 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AbstractSortStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AbstractSortStrategy.java @@ -41,7 +41,7 @@ public abstract class AbstractSortStrategy implements SortStrategy { List properties = getProperties(environment); if (!ObjectUtils.isEmpty(properties)) { Sort.Direction direction = getDirection(environment); - direction = (direction != null ? direction : Sort.DEFAULT_DIRECTION); + direction = (direction != null) ? direction : Sort.DEFAULT_DIRECTION; List sortOrders = new ArrayList<>(properties.size()); for (String property : properties) { sortOrders.add(new Sort.Order(direction, property)); @@ -53,11 +53,13 @@ public abstract class AbstractSortStrategy implements SortStrategy { /** * Return the sort properties to use, or an empty list if there are none. + * @param environment the data fetching environment for this operation */ protected abstract List getProperties(DataFetchingEnvironment environment); /** * Return the sort direction to use, or {@code null}. + * @param environment the data fetching environment for this operation */ @Nullable protected abstract Sort.Direction getDirection(DataFetchingEnvironment environment); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationRuntimeWiringConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationRuntimeWiringConfigurer.java index 0f2fe3dd..b551ab40 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationRuntimeWiringConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationRuntimeWiringConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.query; import java.util.List; @@ -42,11 +43,10 @@ import org.springframework.util.Assert; * already have registrations. * * @author Rossen Stoyanchev - * @since 1.0.0 */ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer { - private final static Log logger = LogFactory.getLog(AutoRegistrationRuntimeWiringConfigurer.class); + private static final Log logger = LogFactory.getLog(AutoRegistrationRuntimeWiringConfigurer.class); private final Map dataFetcherFactories; @@ -107,7 +107,7 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer @Override public boolean providesDataFetcher(FieldWiringEnvironment environment) { - if (dataFetcherFactories.isEmpty()) { + if (AutoRegistrationRuntimeWiringConfigurer.this.dataFetcherFactories.isEmpty()) { return false; } @@ -118,7 +118,7 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer String outputTypeName = getOutputTypeName(environment); boolean result = (outputTypeName != null && - dataFetcherFactories.containsKey(outputTypeName) && + AutoRegistrationRuntimeWiringConfigurer.this.dataFetcherFactories.containsKey(outputTypeName) && !hasDataFetcherFor(environment.getFieldDefinition())); if (!result) { @@ -150,7 +150,7 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer } private GraphQLType removeNonNullWrapper(GraphQLType outputType) { - return (outputType instanceof GraphQLNonNull wrapper ? wrapper.getWrappedType() : outputType); + return (outputType instanceof GraphQLNonNull wrapper) ? wrapper.getWrappedType() : outputType; } private boolean isConnectionType(GraphQLType type) { @@ -162,7 +162,7 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer private boolean hasDataFetcherFor(FieldDefinition fieldDefinition) { if (this.existingQueryDataFetcherPredicate == null) { Map map = this.builder.build().getDataFetcherForType("Query"); - this.existingQueryDataFetcherPredicate = fieldName -> map.get(fieldName) != null; + this.existingQueryDataFetcherPredicate = (fieldName) -> map.get(fieldName) != null; } return this.existingQueryDataFetcherPredicate.test(fieldDefinition.getName()); } @@ -171,7 +171,7 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer if (logger.isTraceEnabled()) { String query = environment.getFieldDefinition().getName(); logger.trace((match ? "Matched" : "Skipped") + - " output typeName " + (typeName != null ? "'" + typeName + "'" : "null") + + " output typeName " + ((typeName != null) ? "'" + typeName + "'" : "null") + " for query '" + query + "'"); } } @@ -182,12 +182,12 @@ class AutoRegistrationRuntimeWiringConfigurer implements RuntimeWiringConfigurer String outputTypeName = getOutputTypeName(environment); logTraceMessage(environment, outputTypeName, true); - DataFetcherFactory factory = dataFetcherFactories.get(outputTypeName); + DataFetcherFactory factory = AutoRegistrationRuntimeWiringConfigurer.this.dataFetcherFactories.get(outputTypeName); Assert.notNull(factory, "Expected DataFetcher factory for typeName '" + outputTypeName + "'"); GraphQLType type = removeNonNullWrapper(environment.getFieldType()); return (isConnectionType(type) ? factory.scrollable() : - (type instanceof GraphQLList ? factory.many() : factory.single())); + (type instanceof GraphQLList) ? factory.many() : factory.single()); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java index fe1c1ade..4d9a4c12 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/AutoRegistrationTypeVisitor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.query; import java.util.Map; @@ -39,9 +40,9 @@ import org.springframework.lang.Nullable; * already have registrations. * * @author Rossen Stoyanchev - * @deprecated in favor of {@link AutoRegistrationRuntimeWiringConfigurer} + * @deprecated since 1.0.0 in favor of {@link AutoRegistrationRuntimeWiringConfigurer} */ -@Deprecated +@Deprecated(since = "1.0.0", forRemoval = true) class AutoRegistrationTypeVisitor extends GraphQLTypeVisitorStub { private final Map>> dataFetcherFactories; @@ -52,7 +53,7 @@ class AutoRegistrationTypeVisitor extends GraphQLTypeVisitorStub { * @param dataFetcherFactories map with GraphQL type names as keys and * functions as values to create a DataFetcher for single or many values */ - public AutoRegistrationTypeVisitor(Map>> dataFetcherFactories) { + AutoRegistrationTypeVisitor(Map>> dataFetcherFactories) { this.dataFetcherFactories = dataFetcherFactories; } @@ -71,9 +72,9 @@ class AutoRegistrationTypeVisitor extends GraphQLTypeVisitorStub { return TraversalControl.ABORT; } - DataFetcher dataFetcher = (fieldType instanceof GraphQLList ? + DataFetcher dataFetcher = (fieldType instanceof GraphQLList) ? getDataFetcher(((GraphQLList) fieldType).getWrappedType(), false) : - getDataFetcher(fieldType, true)); + getDataFetcher(fieldType, true); if (dataFetcher != null) { GraphQLCodeRegistry.Builder registry = context.getVarFromParents(GraphQLCodeRegistry.Builder.class); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/JsonKeysetCursorStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/JsonKeysetCursorStrategy.java index a8437ca6..75aff66f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/JsonKeysetCursorStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/JsonKeysetCursorStrategy.java @@ -86,6 +86,7 @@ public final class JsonKeysetCursorStrategy implements CursorStrategy fromCursor(String cursor) { DataBuffer buffer = this.bufferFactory.wrap(cursor.getBytes(StandardCharsets.UTF_8)); Map map = ((Decoder>) this.decoder).decode(buffer, MAP_TYPE, null, null); - return (map != null ? map : Collections.emptyMap()); + return (map != null) ? map : Collections.emptyMap(); } @@ -136,9 +137,9 @@ public final class JsonKeysetCursorStrategy implements CursorStrategy propertyPaths; @@ -54,9 +53,9 @@ class PropertySelection { /** - * @return the property paths as list. + * Return the property paths as list. */ - public List toList() { + List toList() { return this.propertyPaths.stream().map(PropertyPath::toDotPath).toList(); } @@ -64,14 +63,13 @@ class PropertySelection { /** * Create a property selection for the given {@link TypeInformation type} and * {@link DataFetchingFieldSelectionSet}. - * * @param typeInfo the type to inspect * @param selectionSet the field selection to apply * @return a property selection holding all selectable property paths. */ - public static PropertySelection create(TypeInformation typeInfo, DataFetchingFieldSelectionSet selectionSet) { + static PropertySelection create(TypeInformation typeInfo, DataFetchingFieldSelectionSet selectionSet) { FieldSelection selection = new DataFetchingFieldSelection(selectionSet); - List paths = getPropertyPaths(typeInfo, selection, path -> PropertyPath.from(path, typeInfo)); + List paths = getPropertyPaths(typeInfo, selection, (path) -> PropertyPath.from(path, typeInfo)); return new PropertySelection(paths); } @@ -111,8 +109,8 @@ class PropertySelection { private static boolean isConnectionEdges(SelectedField selectedField) { return selectedField.getName().equals("edges") && - selectedField.getParentField().getType() instanceof GraphQLNamedOutputType namedType && - namedType.getName().endsWith("Connection"); + selectedField.getParentField().getType() instanceof GraphQLNamedOutputType namedType && + namedType.getName().endsWith("Connection"); } private static boolean isConnectionEdgeNode(SelectedField selectedField) { @@ -141,13 +139,12 @@ class PropertySelection { interface FieldSelection extends Iterable { /** - * @return {@code true} if the field selection is empty + * Return {@code true} if the field selection is empty. */ boolean isEmpty(); /** * Obtain the field selection (nested fields) for a given {@code field}. - * * @param field the field for which nested fields should be obtained * @return the field selection. Can be empty. */ @@ -174,7 +171,7 @@ class PropertySelection { @Override public boolean isEmpty() { - return selectedFields.isEmpty(); + return this.selectedFields.isEmpty(); } @Override @@ -183,14 +180,14 @@ class PropertySelection { for (SelectedField selectedField : this.allFields) { if (field.equals(selectedField.getParentField())) { - selectedFields = (selectedFields != null ? selectedFields : new ArrayList<>()); + selectedFields = (selectedFields != null) ? selectedFields : new ArrayList<>(); selectedFields.add(selectedField); } } - return (selectedFields != null ? + return (selectedFields != null) ? new DataFetchingFieldSelection(selectedFields, this.allFields) : - EmptyFieldSelection.INSTANCE); + EmptyFieldSelection.INSTANCE; } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java index 352a8a99..58c8de37 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java @@ -101,7 +101,7 @@ import org.springframework.validation.BindException; */ public abstract class QueryByExampleDataFetcher { - private final static Log logger = LogFactory.getLog(QueryByExampleDataFetcher.class); + private static final Log logger = LogFactory.getLog(QueryByExampleDataFetcher.class); private final TypeInformation domainType; @@ -147,7 +147,7 @@ public abstract class QueryByExampleDataFetcher { List definedArguments = environment.getFieldDefinition().getArguments(); if (definedArguments.size() == 1) { String name = definedArguments.get(0).getName(); - if (arguments.get(name) instanceof Map) { + if (arguments.get(name) instanceof Map) { return name; } } @@ -202,6 +202,8 @@ public abstract class QueryByExampleDataFetcher { * without a {@code CursorStrategy} and default {@link ScrollSubrange}. * For default values, see the respective methods on {@link Builder} and * {@link ReactiveBuilder}. + * @param executors repositories to consider for registration + * @param reactiveExecutors reactive repositories to consider for registration */ public static RuntimeWiringConfigurer autoRegistrationConfigurer( List> executors, @@ -215,10 +217,8 @@ public abstract class QueryByExampleDataFetcher { * {@link graphql.schema.idl.WiringFactory} to find queries with a return * type whose name matches to the domain type name of the given repositories * and registers {@link DataFetcher}s for them. - * *

    Note: This applies only to top-level queries and * repositories annotated with {@link GraphQlRepository @GraphQlRepository}. - * * @param executors repositories to consider for registration * @param reactiveExecutors reactive repositories to consider for registration * @param cursorStrategy for decoding cursors in pagination requests; @@ -301,13 +301,13 @@ public abstract class QueryByExampleDataFetcher { * registers {@link DataFetcher}s for those queries. *

    Note: currently, this method will match only to * queries under the top-level "Query" type in the GraphQL schema. - * * @param executors repositories to consider for registration * @param reactiveExecutors reactive repositories to consider for registration * @return the created visitor - * @deprecated in favor of {@link #autoRegistrationConfigurer(List, List)} + * @deprecated since 1.0.0, in favor of {@link #autoRegistrationConfigurer(List, List)} */ - @Deprecated + @Deprecated(since = "1.0.0", forRemoval = true) + @SuppressWarnings("removal") public static GraphQLTypeVisitor autoRegistrationTypeVisitor( List> executors, List> reactiveExecutors) { @@ -318,7 +318,7 @@ public abstract class QueryByExampleDataFetcher { String typeName = RepositoryUtils.getGraphQlTypeName(executor); if (typeName != null) { Builder builder = customize(executor, builder(executor)); - factories.put(typeName, single -> single ? builder.single() : builder.many()); + factories.put(typeName, (single) -> single ? builder.single() : builder.many()); } } @@ -326,7 +326,7 @@ public abstract class QueryByExampleDataFetcher { String typeName = RepositoryUtils.getGraphQlTypeName(executor); if (typeName != null) { ReactiveBuilder builder = customize(executor, builder(executor)); - factories.put(typeName, single -> single ? builder.single() : builder.many()); + factories.put(typeName, (single) -> single ? builder.single() : builder.many()); } } @@ -336,7 +336,7 @@ public abstract class QueryByExampleDataFetcher { @SuppressWarnings({"unchecked", "rawtypes"}) private static Builder customize(QueryByExampleExecutor executor, Builder builder) { - if(executor instanceof QueryByExampleBuilderCustomizer customizer){ + if (executor instanceof QueryByExampleBuilderCustomizer customizer) { return customizer.customize(builder); } return builder; @@ -344,7 +344,7 @@ public abstract class QueryByExampleDataFetcher { @SuppressWarnings({"unchecked", "rawtypes"}) private static ReactiveBuilder customize(ReactiveQueryByExampleExecutor executor, ReactiveBuilder builder) { - if(executor instanceof ReactiveQueryByExampleBuilderCustomizer customizer){ + if (executor instanceof ReactiveQueryByExampleBuilderCustomizer customizer) { return customizer.customize(builder); } return builder; @@ -402,6 +402,7 @@ public abstract class QueryByExampleDataFetcher { * into the target {@code projectionType}. Projection types can be * either interfaces with property getters to expose or regular classes * outside the entity type hierarchy for DTO projections. + * @param

    the result type * @param projectionType projection type * @return a new {@link Builder} instance with all previously * configured options and {@code projectionType} applied @@ -435,6 +436,8 @@ public abstract class QueryByExampleDataFetcher { * from the beginning, or {@link KeysetScrollPosition#reverse()} the same * to go back from the end. *

    By default a count of 20 and {@link ScrollPosition#offset()} are used. + * @param defaultCount the default scroll count to use + * @param defaultPosition a function that returns the forward/backward scroll position * @since 1.2.5 */ public Builder defaultScrollSubrange( @@ -449,6 +452,7 @@ public abstract class QueryByExampleDataFetcher { * not specify a cursor and/or a count of items. *

    By default, this is {@link OffsetScrollPosition#offset()} with a * count of 20. + * @param defaultSubrange the default scroll subrange to use, can be {@code null} * @return a new {@link Builder} instance with all previously configured * options and {@code Sort} applied * @deprecated in favor of {@link #defaultScrollSubrange(int, Function)} @@ -458,8 +462,8 @@ public abstract class QueryByExampleDataFetcher { public Builder defaultScrollSubrange(@Nullable ScrollSubrange defaultSubrange) { return new Builder<>(this.executor, this.domainType, this.resultType, this.cursorStrategy, - (defaultSubrange != null ? defaultSubrange.count().getAsInt() : null), - (defaultSubrange != null ? forward -> defaultSubrange.position().get() : null), + (defaultSubrange != null) ? defaultSubrange.count().getAsInt() : null, + (defaultSubrange != null) ? (forward) -> defaultSubrange.position().get() : null, this.sort); } @@ -497,9 +501,9 @@ public abstract class QueryByExampleDataFetcher { public DataFetcher> scrollable() { return new ScrollableEntityFetcher<>( this.executor, this.domainType, this.resultType, - (this.cursorStrategy != null ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy()), - (this.defaultScrollCount != null ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount()), - (this.defaultScrollPosition != null ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition()), + (this.cursorStrategy != null) ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy(), + (this.defaultScrollCount != null) ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount(), + (this.defaultScrollPosition != null) ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition(), this.sort); } @@ -511,8 +515,7 @@ public abstract class QueryByExampleDataFetcher { *

    This is supported by {@link #autoRegistrationConfigurer(List, List) * Auto-registration}, which detects if a repository implements this * interface and applies it accordingly. - * - * @param + * @param domain type * @since 1.1.1 */ public interface QueryByExampleBuilderCustomizer { @@ -578,13 +581,14 @@ public abstract class QueryByExampleDataFetcher { * into the target {@code projectionType}. Projection types can be * either interfaces with property getters to expose or regular classes * outside the entity type hierarchy for DTO projections. + * @param

    the result type * @param projectionType projection type * @return a new {@link ReactiveBuilder} instance with all previously * configured options and {@code projectionType} applied */ public

    ReactiveBuilder projectAs(Class

    projectionType) { Assert.notNull(projectionType, "Projection type must not be null"); - return new ReactiveBuilder<>(this.executor, this.domainType, + return new ReactiveBuilder<>(this.executor, this.domainType, projectionType, this.cursorStrategy, this.defaultScrollCount, this.defaultScrollPosition, this.sort); } @@ -611,6 +615,8 @@ public abstract class QueryByExampleDataFetcher { * from the beginning, or {@link KeysetScrollPosition#reverse()} the same * to go back from the end. *

    By default a count of 20 and {@link ScrollPosition#offset()} are used. + * @param defaultCount the default scroll count to use + * @param defaultPosition a function that returns the forward/backward scroll position * @since 1.2.5 */ public ReactiveBuilder defaultScrollSubrange( @@ -625,6 +631,7 @@ public abstract class QueryByExampleDataFetcher { * not specify a cursor and/or a count of items. *

    By default, this is {@link OffsetScrollPosition#offset()} with a * count of 20. + * @param defaultSubrange the default scroll subrange to use, can be {@code null} * @return a new {@link Builder} instance with all previously configured * options and {@code Sort} applied * @deprecated in favor of {@link #defaultScrollSubrange(int, Function)} @@ -634,8 +641,8 @@ public abstract class QueryByExampleDataFetcher { public ReactiveBuilder defaultScrollSubrange(@Nullable ScrollSubrange defaultSubrange) { return new ReactiveBuilder<>(this.executor, this.domainType, this.resultType, this.cursorStrategy, - (defaultSubrange != null ? defaultSubrange.count().getAsInt() : null), - (defaultSubrange != null ? forward -> defaultSubrange.position().get() : null), + (defaultSubrange != null) ? defaultSubrange.count().getAsInt() : null, + (defaultSubrange != null) ? (forward) -> defaultSubrange.position().get() : null, this.sort); } @@ -673,9 +680,9 @@ public abstract class QueryByExampleDataFetcher { public DataFetcher>> scrollable() { return new ReactiveScrollableEntityFetcher<>( this.executor, this.domainType, this.resultType, - (this.cursorStrategy != null ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy()), - (this.defaultScrollCount != null ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount()), - (this.defaultScrollPosition != null ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition()), + (this.cursorStrategy != null) ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy(), + (this.defaultScrollCount != null) ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount(), + (this.defaultScrollPosition != null) ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition(), this.sort); } @@ -687,8 +694,7 @@ public abstract class QueryByExampleDataFetcher { *

    This is supported by {@link #autoRegistrationConfigurer(List, List) * Auto-registration}, which detects if a repository implements this * interface and applies it accordingly. - * - * @param + * @param the domain type * @since 1.1.1 */ public interface ReactiveQueryByExampleBuilderCustomizer { @@ -728,7 +734,7 @@ public abstract class QueryByExampleDataFetcher { @Override @SuppressWarnings({"ConstantConditions", "unchecked"}) public R get(DataFetchingEnvironment env) throws BindException { - return this.executor.findBy(buildExample(env), query -> { + return this.executor.findBy(buildExample(env), (query) -> { FluentQuery.FetchableFluentQuery queryToUse = (FluentQuery.FetchableFluentQuery) query; if (this.sort.isSorted()) { @@ -777,7 +783,7 @@ public abstract class QueryByExampleDataFetcher { @Override @SuppressWarnings("unchecked") public Iterable get(DataFetchingEnvironment env) throws BindException { - return this.executor.findBy(buildExample(env), query -> { + return this.executor.findBy(buildExample(env), (query) -> { FluentQuery.FetchableFluentQuery queryToUse = (FluentQuery.FetchableFluentQuery) query; if (this.sort.isSorted()) { @@ -874,7 +880,7 @@ public abstract class QueryByExampleDataFetcher { @Override @SuppressWarnings("unchecked") public Mono get(DataFetchingEnvironment env) throws BindException { - return this.executor.findBy(buildExample(env), query -> { + return this.executor.findBy(buildExample(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; if (this.sort.isSorted()) { @@ -922,7 +928,7 @@ public abstract class QueryByExampleDataFetcher { @Override @SuppressWarnings("unchecked") public Flux get(DataFetchingEnvironment env) throws BindException { - return this.executor.findBy(buildExample(env), query -> { + return this.executor.findBy(buildExample(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; if (this.sort.isSorted()) { @@ -989,7 +995,7 @@ public abstract class QueryByExampleDataFetcher { @Override @SuppressWarnings("unchecked") public Mono> get(DataFetchingEnvironment env) throws BindException { - return this.executor.findBy(buildExample(env), query -> { + return this.executor.findBy(buildExample(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; if (this.sort.isSorted()) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java index 532aacae..d1c72ac7 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java @@ -107,7 +107,7 @@ import org.springframework.util.MultiValueMap; */ public abstract class QuerydslDataFetcher { - private final static Log logger = LogFactory.getLog(QueryByExampleDataFetcher.class); + private static final Log logger = LogFactory.getLog(QueryByExampleDataFetcher.class); private static final QuerydslPredicateBuilder BUILDER = new QuerydslPredicateBuilder( DefaultConversionService.getSharedInstance(), SimpleEntityPathResolver.INSTANCE); @@ -153,7 +153,7 @@ public abstract class QuerydslDataFetcher { for (Map.Entry entry : getArgumentValues(environment).entrySet()) { Object value = entry.getValue(); - List values = (value instanceof List ? (List) value : Collections.singletonList(value)); + List values = (value instanceof List) ? (List) value : Collections.singletonList(value); parameters.put(entry.getKey(), values); } @@ -225,6 +225,8 @@ public abstract class QuerydslDataFetcher { * without a {@code CursorStrategy} and default {@link ScrollSubrange}. * For default values, see the respective methods on {@link Builder} and * {@link ReactiveBuilder}. + * @param executors repositories to consider for registration + * @param reactiveExecutors reactive repositories to consider for registration */ public static RuntimeWiringConfigurer autoRegistrationConfigurer( List> executors, @@ -244,7 +246,6 @@ public abstract class QuerydslDataFetcher { * If a repository is also an instance of {@link QuerydslBinderCustomizer}, * this is transparently detected and applied through the * {@code QuerydslDataFetcher} builder methods. - * * @param executors repositories to consider for registration * @param reactiveExecutors reactive repositories to consider for registration * @param cursorStrategy for decoding cursors in pagination requests; @@ -337,14 +338,13 @@ public abstract class QuerydslDataFetcher { * If a repository is also an instance of {@link QuerydslBinderCustomizer}, * this is transparently detected and applied through the * {@code QuerydslDataFetcher} builder methods. - * * @param executors repositories to consider for registration * @param reactiveExecutors reactive repositories to consider for registration * @return the created visitor - * @deprecated in favor of {@link #autoRegistrationConfigurer(List, List)} + * @deprecated since 1.0.0 in favor of {@link #autoRegistrationConfigurer(List, List)} */ - @SuppressWarnings({"unchecked", "rawtypes"}) - @Deprecated + @SuppressWarnings({"unchecked", "rawtypes", "removal"}) + @Deprecated(since = "1.0.0", forRemoval = true) public static GraphQLTypeVisitor autoRegistrationTypeVisitor( List> executors, List> reactiveExecutors) { @@ -355,7 +355,7 @@ public abstract class QuerydslDataFetcher { String typeName = RepositoryUtils.getGraphQlTypeName(executor); if (typeName != null) { Builder builder = customize(executor, QuerydslDataFetcher.builder(executor).customizer(customizer(executor))); - factories.put(typeName, single -> single ? builder.single() : builder.many()); + factories.put(typeName, (single) -> single ? builder.single() : builder.many()); } } @@ -363,7 +363,7 @@ public abstract class QuerydslDataFetcher { String typeName = RepositoryUtils.getGraphQlTypeName(executor); if (typeName != null) { ReactiveBuilder builder = customize(executor, QuerydslDataFetcher.builder(executor).customizer(customizer(executor))); - factories.put(typeName, single -> single ? builder.single() : builder.many()); + factories.put(typeName, (single) -> single ? builder.single() : builder.many()); } } @@ -372,7 +372,7 @@ public abstract class QuerydslDataFetcher { @SuppressWarnings({"unchecked", "rawtypes"}) private static Builder customize(QuerydslPredicateExecutor executor, Builder builder) { - if(executor instanceof QuerydslBuilderCustomizer customizer){ + if (executor instanceof QuerydslBuilderCustomizer customizer) { return customizer.customize(builder); } return builder; @@ -380,7 +380,7 @@ public abstract class QuerydslDataFetcher { @SuppressWarnings({"unchecked", "rawtypes"}) private static ReactiveBuilder customize(ReactiveQuerydslPredicateExecutor executor, ReactiveBuilder builder) { - if(executor instanceof ReactiveQuerydslBuilderCustomizer customizer){ + if (executor instanceof ReactiveQuerydslBuilderCustomizer customizer) { return customizer.customize(builder); } return builder; @@ -388,9 +388,9 @@ public abstract class QuerydslDataFetcher { @SuppressWarnings("rawtypes") private static QuerydslBinderCustomizer customizer(Object executor) { - return (executor instanceof QuerydslBinderCustomizer ? + return (executor instanceof QuerydslBinderCustomizer) ? (QuerydslBinderCustomizer>) executor : - NO_OP_BINDER_CUSTOMIZER); + NO_OP_BINDER_CUSTOMIZER; } @@ -448,6 +448,7 @@ public abstract class QuerydslDataFetcher { * into the target {@code projectionType}. Projection types can be * either interfaces with property getters to expose or regular classes * outside the entity type hierarchy for DTO projections. + * @param

    the result type * @param projectionType projection type * @return a new {@link Builder} instance with all previously * configured options and {@code projectionType} applied @@ -483,6 +484,8 @@ public abstract class QuerydslDataFetcher { * from the beginning, or {@link KeysetScrollPosition#reverse()} the same * to go back from the end. *

    By default a count of 20 and {@link ScrollPosition#offset()} are used. + * @param defaultCount the default scroll count to use + * @param defaultPosition the function that returns the forward/backward scroll position. * @since 1.2.5 */ public Builder defaultScrollSubrange( @@ -496,6 +499,7 @@ public abstract class QuerydslDataFetcher { * Configure a {@link ScrollSubrange} to use when a paginated request does * not specify a cursor and/or a count of items. *

    By default, this is {@link OffsetScrollPosition#offset()} with a count of 20. + * @param defaultSubrange the default scroll subrange to use, can be {@code null} * @return a new {@link Builder} instance * @since 1.2.0 * @deprecated in favor of {@link #defaultScrollSubrange(int, Function)} @@ -504,8 +508,8 @@ public abstract class QuerydslDataFetcher { @Deprecated(since = "1.2.5", forRemoval = true) public Builder defaultScrollSubrange(@Nullable ScrollSubrange defaultSubrange) { return new Builder<>(this.executor, this.domainType, this.resultType, this.cursorStrategy, - (defaultSubrange != null ? defaultSubrange.count().getAsInt() : null), - (defaultSubrange != null ? forward -> defaultSubrange.position().get() : null), + (defaultSubrange != null) ? defaultSubrange.count().getAsInt() : null, + (defaultSubrange != null) ? (forward) -> defaultSubrange.position().get() : null, this.sort, this.customizer); } @@ -519,7 +523,7 @@ public abstract class QuerydslDataFetcher { Assert.notNull(sort, "Sort must not be null"); return new Builder<>(this.executor, this.domainType, this.resultType, this.cursorStrategy, this.defaultScrollCount, this.defaultScrollPosition, - sort, customizer); + sort, this.customizer); } /** @@ -529,7 +533,6 @@ public abstract class QuerydslDataFetcher { * itself, this is automatically detected and applied during * {@link #autoRegistrationConfigurer(List, List) auto-registration}. * For manual registration, you will need to use this method to apply it. - * * @param customizer to customize the binding of the GraphQL request to * Querydsl Predicate * @return a new {@link Builder} instance with all previously configured @@ -566,9 +569,9 @@ public abstract class QuerydslDataFetcher { public DataFetcher> scrollable() { return new ScrollableEntityFetcher<>( this.executor, this.domainType, this.resultType, - (this.cursorStrategy != null ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy()), - (this.defaultScrollCount != null ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount()), - (this.defaultScrollPosition != null ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition()), + (this.cursorStrategy != null) ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy(), + (this.defaultScrollCount != null) ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount(), + (this.defaultScrollPosition != null) ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition(), this.sort, this.customizer); } @@ -577,12 +580,11 @@ public abstract class QuerydslDataFetcher { /** * Callback interface that can be used to customize QuerydslDataFetcher - * {@link Builder} to change its configuration. + * {@link Builder} to change its configuration. *

    This is supported by {@link #autoRegistrationConfigurer(List, List) * Auto-registration}, which detects if a repository implements this * interface and applies it accordingly. - * - * @param + * @param the domain type * @since 1.1.1 */ public interface QuerydslBuilderCustomizer { @@ -651,6 +653,7 @@ public abstract class QuerydslDataFetcher { * into the target {@code projectionType}. Projection types can be * either interfaces with property getters to expose or regular classes * outside the entity type hierarchy for DTO projections. + * @param

    the project type * @param projectionType projection type * @return a new {@link Builder} instance with all previously * configured options and {@code projectionType} applied @@ -686,6 +689,8 @@ public abstract class QuerydslDataFetcher { * from the beginning, or {@link KeysetScrollPosition#reverse()} the same * to go back from the end. *

    By default a count of 20 and {@link ScrollPosition#offset()} are used. + * @param defaultCount the default scroll count to use + * @param defaultPosition a function that returns the forward/backward scroll position * @since 1.2.5 */ public ReactiveBuilder defaultScrollSubrange( @@ -699,6 +704,7 @@ public abstract class QuerydslDataFetcher { * Configure a {@link ScrollSubrange} to use when a paginated request does * not specify a cursor and/or a count of items. *

    By default, this is {@link OffsetScrollPosition#offset()} with a count of 20. + * @param defaultSubrange the default scroll subrange to use, can be {@code null} * @return a new {@link Builder} instance * @since 1.2.0 * @deprecated in favor of {@link #defaultScrollSubrange(int, Function)} @@ -708,8 +714,8 @@ public abstract class QuerydslDataFetcher { public ReactiveBuilder defaultScrollSubrange(@Nullable ScrollSubrange defaultSubrange) { return new ReactiveBuilder<>(this.executor, this.domainType, this.resultType, this.cursorStrategy, - (defaultSubrange != null ? defaultSubrange.count().getAsInt() : null), - (defaultSubrange != null ? forward -> defaultSubrange.position().get() : null), + (defaultSubrange != null) ? defaultSubrange.count().getAsInt() : null, + (defaultSubrange != null) ? (forward) -> defaultSubrange.position().get() : null, this.sort, this.customizer); } @@ -733,7 +739,6 @@ public abstract class QuerydslDataFetcher { * itself, this is automatically detected and applied during * {@link #autoRegistrationConfigurer(List, List) auto-registration}. * For manual registration, you will need to use this method to apply it. - * * @param customizer to customize the GraphQL query to Querydsl * Predicate binding with * @return a new {@link Builder} instance with all previously configured @@ -770,9 +775,9 @@ public abstract class QuerydslDataFetcher { public DataFetcher>> scrollable() { return new ReactiveScrollableEntityFetcher<>( this.executor, this.domainType, this.resultType, - (this.cursorStrategy != null ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy()), - (this.defaultScrollCount != null ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount()), - (this.defaultScrollPosition != null ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition()), + (this.cursorStrategy != null) ? this.cursorStrategy : RepositoryUtils.defaultCursorStrategy(), + (this.defaultScrollCount != null) ? this.defaultScrollCount : RepositoryUtils.defaultScrollCount(), + (this.defaultScrollPosition != null) ? this.defaultScrollPosition : RepositoryUtils.defaultScrollPosition(), this.sort, this.customizer); } @@ -786,7 +791,7 @@ public abstract class QuerydslDataFetcher { * Auto-registration}, which detects if a repository implements this * interface and applies it accordingly. * - * @param + * @param the domain type * @since 1.1.1 */ public interface ReactiveQuerydslBuilderCustomizer { @@ -828,15 +833,15 @@ public abstract class QuerydslDataFetcher { @Override @SuppressWarnings({"ConstantConditions", "unchecked"}) public R get(DataFetchingEnvironment env) { - return this.executor.findBy(buildPredicate(env), query -> { + return this.executor.findBy(buildPredicate(env), (query) -> { FetchableFluentQuery queryToUse = (FetchableFluentQuery) query; - if (this.sort.isSorted()){ + if (this.sort.isSorted()) { queryToUse = queryToUse.sortBy(this.sort); } Class resultType = this.resultType; - if (requiresProjection(resultType)){ + if (requiresProjection(resultType)) { queryToUse = queryToUse.as(resultType); } else { @@ -878,14 +883,14 @@ public abstract class QuerydslDataFetcher { @Override @SuppressWarnings("unchecked") public Iterable get(DataFetchingEnvironment env) { - return this.executor.findBy(buildPredicate(env), query -> { + return this.executor.findBy(buildPredicate(env), (query) -> { FetchableFluentQuery queryToUse = (FetchableFluentQuery) query; - if (this.sort.isSorted()){ + if (this.sort.isSorted()) { queryToUse = queryToUse.sortBy(this.sort); } - if (requiresProjection(this.resultType)){ + if (requiresProjection(this.resultType)) { queryToUse = queryToUse.as(this.resultType); } else { @@ -971,14 +976,14 @@ public abstract class QuerydslDataFetcher { @Override @SuppressWarnings("unchecked") public Mono get(DataFetchingEnvironment env) { - return this.executor.findBy(buildPredicate(env), query -> { + return this.executor.findBy(buildPredicate(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; - if (this.sort.isSorted()){ + if (this.sort.isSorted()) { queryToUse = queryToUse.sortBy(this.sort); } - if (requiresProjection(this.resultType)){ + if (requiresProjection(this.resultType)) { queryToUse = queryToUse.as(this.resultType); } else { @@ -1021,14 +1026,14 @@ public abstract class QuerydslDataFetcher { @Override @SuppressWarnings("unchecked") public Flux get(DataFetchingEnvironment env) { - return this.executor.findBy(buildPredicate(env), query -> { + return this.executor.findBy(buildPredicate(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; - if (this.sort.isSorted()){ + if (this.sort.isSorted()) { queryToUse = queryToUse.sortBy(this.sort); } - if (requiresProjection(this.resultType)){ + if (requiresProjection(this.resultType)) { queryToUse = queryToUse.as(this.resultType); } else { @@ -1091,14 +1096,14 @@ public abstract class QuerydslDataFetcher { @Override @SuppressWarnings("unchecked") public Mono> get(DataFetchingEnvironment env) { - return this.executor.findBy(buildPredicate(env), query -> { + return this.executor.findBy(buildPredicate(env), (query) -> { FluentQuery.ReactiveFluentQuery queryToUse = (FluentQuery.ReactiveFluentQuery) query; - if (this.sort.isSorted()){ + if (this.sort.isSorted()) { queryToUse = queryToUse.sortBy(this.sort); } - if (requiresProjection(this.resultType)){ + if (requiresProjection(this.resultType)) { queryToUse = queryToUse.as(this.resultType); } else { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/RepositoryUtils.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/RepositoryUtils.java index 4c18a242..b99c2434 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/RepositoryUtils.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/RepositoryUtils.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.query; import java.lang.reflect.Type; @@ -40,16 +41,19 @@ import org.springframework.util.StringUtils; * * @author Rossen Stoyanchev * @author Oliver Drotbohm - * @since 1.0.0 */ -class RepositoryUtils { +final class RepositoryUtils { + + private RepositoryUtils() { + + } @SuppressWarnings("unchecked") - public static Class getDomainType(Object executor) { + static Class getDomainType(Object executor) { return (Class) getRepositoryMetadata(executor).getDomainType(); } - public static RepositoryMetadata getRepositoryMetadata(Object executor) { + static RepositoryMetadata getRepositoryMetadata(Object executor) { Assert.isInstanceOf(Repository.class, executor); Type[] genericInterfaces = executor.getClass().getGenericInterfaces(); @@ -68,7 +72,7 @@ class RepositoryUtils { } @Nullable - public static String getGraphQlTypeName(Object repository) { + static String getGraphQlTypeName(Object repository) { GraphQlRepository annotation = AnnotatedElementUtils.findMergedAnnotation(repository.getClass(), GraphQlRepository.class); @@ -81,19 +85,19 @@ class RepositoryUtils { } - public static CursorStrategy defaultCursorStrategy() { + static CursorStrategy defaultCursorStrategy() { return CursorStrategy.withEncoder(new ScrollPositionCursorStrategy(), CursorEncoder.base64()); } - public static int defaultScrollCount() { + static int defaultScrollCount() { return 20; } - public static Function defaultScrollPosition() { - return forward -> ScrollPosition.offset(); + static Function defaultScrollPosition() { + return (forward) -> ScrollPosition.offset(); } - public static ScrollSubrange getScrollSubrange( + static ScrollSubrange getScrollSubrange( DataFetchingEnvironment env, CursorStrategy cursorStrategy) { boolean forward = true; @@ -106,7 +110,7 @@ class RepositoryUtils { forward = false; } } - ScrollPosition pos = (cursor != null ? cursorStrategy.fromCursor(cursor) : null); + ScrollPosition pos = (cursor != null) ? cursorStrategy.fromCursor(cursor) : null; return ScrollSubrange.create(pos, count, forward); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollPositionCursorStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollPositionCursorStrategy.java index 55c87735..52893894 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollPositionCursorStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollPositionCursorStrategy.java @@ -51,6 +51,7 @@ public final class ScrollPositionCursorStrategy implements CursorStrategy> keysetCursorStrategy) { Assert.notNull(keysetCursorStrategy, "'keysetCursorStrategy' is required"); @@ -80,7 +81,7 @@ public final class ScrollPositionCursorStrategy implements CursorStrategy 0 ? index : 0); + return ScrollPosition.offset((index > 0) ? index : 0); } else if (cursor.startsWith(KEYSET_PREFIX)) { Map keys = this.keysetCursorStrategy.fromCursor(cursor.substring(2)); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollSubrange.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollSubrange.java index 8507becd..488bf2f1 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollSubrange.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/ScrollSubrange.java @@ -49,6 +49,9 @@ public final class ScrollSubrange extends Subrange { /** * Public constructor. + * @param pos the reference position, or {@code null} if not specified + * @param count how many to return, or {@code null} if not specified + * @param forward whether scroll forward (true) or backward (false) * @deprecated in favor of {@link #create}, to be removed in 1.3. */ @Deprecated(since = "1.2.4", forRemoval = true) @@ -111,7 +114,7 @@ public final class ScrollSubrange extends Subrange { } else { // Advance back by 1 at least to item before position - int advanceCount = (count != null ? count : 1); + int advanceCount = (count != null) ? count : 1; if (position.getOffset() >= advanceCount) { position = position.advanceBy(-advanceCount); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/SliceConnectionAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/SliceConnectionAdapter.java index 07dbf2c0..2f91a747 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/SliceConnectionAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/SliceConnectionAdapter.java @@ -38,6 +38,7 @@ public final class SliceConnectionAdapter /** * Constructor with the {@link CursorStrategy} to use to encode the * {@code ScrollPosition} of page items. + * @param strategy the cursor strategy to use */ public SliceConnectionAdapter(CursorStrategy strategy) { super(strategy); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/SortStrategy.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/SortStrategy.java index 52746cf8..1ed2e69c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/SortStrategy.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/SortStrategy.java @@ -32,6 +32,7 @@ public interface SortStrategy { /** * Return a {@link Sort} instance by extracting the sort information from * GraphQL arguments, or {@link Sort#unsorted()} otherwise. + * @param environment the data fetching environment */ Sort extract(DataFetchingEnvironment environment); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/AbstractGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/AbstractGraphQlSourceBuilder.java index 535513cb..8c418900 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/AbstractGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/AbstractGraphQlSourceBuilder.java @@ -38,6 +38,7 @@ import org.springframework.lang.Nullable; * Implementation of {@link GraphQlSource.Builder} that leaves it to subclasses * to initialize {@link GraphQLSchema}. * + * @param the builder type * @author Rossen Stoyanchev * @author Brian Clozel * @since 1.0.0 @@ -90,8 +91,8 @@ public abstract class AbstractGraphQlSourceBuilder configurer) { - this.graphQlConfigurer = (this.graphQlConfigurer != null ? - this.graphQlConfigurer.andThen(configurer) : configurer); + this.graphQlConfigurer = (this.graphQlConfigurer != null) ? + this.graphQlConfigurer.andThen(configurer) : configurer; return self(); } @@ -147,13 +148,14 @@ public abstract class AbstractGraphQlSourceBuilder builder.codeRegistry(outputCodeRegistry)); + return schema.transformWithoutTypes((builder) -> builder.codeRegistry(outputCodeRegistry)); } /** * Protected method to apply the * {@link #configureGraphQl(Consumer) configured graphQlConfigurer}'s. * Subclasses can use this to customize {@link GraphQL.Builder} further. + * @param builder the builder to be customized * @since 1.2.5 */ protected void applyGraphQlConfigurers(GraphQL.Builder builder) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java index 2c92f4aa..a7ad92fe 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; @@ -55,7 +56,6 @@ public interface BatchLoaderRegistry extends DataLoaderRegistrar { * {@code @SchemaMapping} handler methods can transparenly locate and * inject a {@code DataLoader} argument based on the generic type * {@code }. - * * @param keyType the type of keys that will be used as input * @param valueType the type of value that will be returned as output * @param the key type @@ -71,7 +71,6 @@ public interface BatchLoaderRegistry extends DataLoaderRegistrar { *

    Note: when this method is used, the parameter name * of a {@code DataLoader} argument in a {@code @SchemaMapping} handler * method needs to match the name given here. - * * @param name the name to use to register a {@code DataLoader} * @param the type of keys that will be used as input * @param the type of values that will be used as output diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ClassNameTypeResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ClassNameTypeResolver.java index c6881521..c51002f0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ClassNameTypeResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ClassNameTypeResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.LinkedHashMap; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolver.java index 87f7a3a0..1c240cda 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolver.java @@ -38,44 +38,43 @@ import org.springframework.util.Assert; * * @author Mykyta Ivchenko * @author Rossen Stoyanchev - * @since 1.0.1 */ class CompositeSubscriptionExceptionResolver implements SubscriptionExceptionResolver { - private static final Log logger = LogFactory.getLog(CompositeSubscriptionExceptionResolver.class); + private static final Log logger = LogFactory.getLog(CompositeSubscriptionExceptionResolver.class); - private final List resolvers; + private final List resolvers; - CompositeSubscriptionExceptionResolver(List resolvers) { - Assert.notNull(resolvers, "'resolvers' is required"); - this.resolvers = resolvers; - } + CompositeSubscriptionExceptionResolver(List resolvers) { + Assert.notNull(resolvers, "'resolvers' is required"); + this.resolvers = resolvers; + } - @Override - public Mono> resolveException(Throwable exception) { - return Flux.fromIterable(this.resolvers) - .flatMap(resolver -> resolver.resolveException(exception)) - .next() - .onErrorResume(error -> Mono.just(handleResolverException(error, exception))) - .defaultIfEmpty(createDefaultError()); - } + @Override + public Mono> resolveException(Throwable exception) { + return Flux.fromIterable(this.resolvers) + .flatMap((resolver) -> resolver.resolveException(exception)) + .next() + .onErrorResume((error) -> Mono.just(handleResolverException(error, exception))) + .defaultIfEmpty(createDefaultError()); + } - private List handleResolverException( - Throwable resolverException, Throwable originalException) { + private List handleResolverException( + Throwable resolverException, Throwable originalException) { - if (logger.isWarnEnabled()) { - logger.warn("Failure while resolving " + originalException.getClass().getName(), resolverException); - } - return createDefaultError(); - } + if (logger.isWarnEnabled()) { + logger.warn("Failure while resolving " + originalException.getClass().getName(), resolverException); + } + return createDefaultError(); + } - private List createDefaultError() { - return Collections.singletonList(GraphqlErrorBuilder.newError() - .message("Subscription error") - .errorType(ErrorType.INTERNAL_ERROR) - .build()); - } + private List createDefaultError() { + return Collections.singletonList(GraphqlErrorBuilder.newError() + .message("Subscription error") + .errorType(ErrorType.INTERNAL_ERROR) + .build()); + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurer.java index fc9ae6ae..d2e33bf0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.Collection; @@ -67,7 +68,7 @@ public class ConnectionTypeDefinitionConfigurer implements TypeDefinitionConfigu .fieldDefinition(initFieldDefinition("endCursor", STRING_TYPE)) .build()); - typeNames.forEach(typeName -> { + typeNames.forEach((typeName) -> { String connectionTypeName = typeName + "Connection"; String edgeTypeName = typeName + "Edge"; @@ -90,19 +91,19 @@ public class ConnectionTypeDefinitionConfigurer implements TypeDefinitionConfigu return Stream.concat( registry.types().values().stream(), registry.objectTypeExtensions().values().stream().flatMap(Collection::stream)) - .filter(definition -> definition instanceof ImplementingTypeDefinition) - .flatMap(definition -> { + .filter((definition) -> definition instanceof ImplementingTypeDefinition) + .flatMap((definition) -> { ImplementingTypeDefinition typeDefinition = (ImplementingTypeDefinition) definition; return typeDefinition.getFieldDefinitions().stream() - .map(fieldDefinition -> { + .map((fieldDefinition) -> { Type type = fieldDefinition.getType(); - return (type instanceof NonNullType ? ((NonNullType) type).getType() : type); + return (type instanceof NonNullType) ? ((NonNullType) type).getType() : type; }) - .filter(type -> type instanceof TypeName) - .map(type -> ((TypeName) type).getName()) - .filter(name -> name.endsWith("Connection")) - .filter(name -> registry.getType(name).isEmpty()) - .map(name -> name.substring(0, name.length() - "Connection".length())); + .filter((type) -> type instanceof TypeName) + .map((type) -> ((TypeName) type).getName()) + .filter((name) -> name.endsWith("Connection")) + .filter((name) -> registry.getType(name).isEmpty()) + .map((name) -> name.substring(0, name.length() - "Connection".length())); }) .collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java index c69fac00..feb8e346 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ContextDataFetcherDecorator.java @@ -88,13 +88,13 @@ final class ContextDataFetcherDecorator implements DataFetcher { if (this.subscription) { Assert.state(value instanceof Publisher, "Expected Publisher for a subscription"); - Flux flux = Flux.from((Publisher) value).onErrorResume(exception -> { + Flux flux = Flux.from((Publisher) value).onErrorResume((exception) -> { // Already handled, e.g. controller methods? if (exception instanceof SubscriptionPublisherException) { return Mono.error(exception); } return this.subscriptionExceptionResolver.resolveException(exception) - .flatMap(errors -> Mono.error(new SubscriptionPublisherException(errors, exception))); + .flatMap((errors) -> Mono.error(new SubscriptionPublisherException(errors, exception))); }); return flux.contextWrite(snapshot::updateContext); } @@ -123,7 +123,7 @@ final class ContextDataFetcherDecorator implements DataFetcher { /** * Type visitor to apply {@link ContextDataFetcherDecorator}. */ - private static class ContextTypeVisitor extends GraphQLTypeVisitorStub { + private static final class ContextTypeVisitor extends GraphQLTypeVisitorStub { private final SubscriptionExceptionResolver exceptionResolver; @@ -143,7 +143,7 @@ final class ContextDataFetcherDecorator implements DataFetcher { if (applyDecorator(dataFetcher)) { boolean handlesSubscription = visitorHelper.isSubscriptionType(parent); - dataFetcher = new ContextDataFetcherDecorator(dataFetcher, handlesSubscription, exceptionResolver); + dataFetcher = new ContextDataFetcherDecorator(dataFetcher, handlesSubscription, this.exceptionResolver); codeRegistry.dataFetcher(parent, fieldDefinition, dataFetcher); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java index 24e5c58e..0c60bdac 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolverAdapter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.Collections; @@ -104,7 +105,7 @@ public abstract class DataFetcherExceptionResolverAdapter implements DataFetcher .call(); } catch (Exception ex2) { - logger.warn("Failed to resolve " + exception, ex2); + this.logger.warn("Failed to resolve " + exception, ex2); return null; } } @@ -118,7 +119,7 @@ public abstract class DataFetcherExceptionResolverAdapter implements DataFetcher @Nullable protected List resolveToMultipleErrors(Throwable ex, DataFetchingEnvironment env) { GraphQLError error = resolveToSingleError(ex, env); - return (error != null ? Collections.singletonList(error) : null); + return (error != null) ? Collections.singletonList(error) : null; } /** @@ -140,7 +141,7 @@ public abstract class DataFetcherExceptionResolverAdapter implements DataFetcher * @return the created instance * @deprecated as of 1.0.1, please use {@link DataFetcherExceptionResolver#forSingleError(BiFunction)} */ - @Deprecated + @Deprecated(since = "1.0.1", forRemoval = true) public static DataFetcherExceptionResolverAdapter from( BiFunction resolver) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java index fae2ed82..52557fff 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataLoaderRegistrar.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import graphql.ExecutionInput; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java index 8a52466e..c1fe8324 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.ArrayList; @@ -52,9 +53,9 @@ import org.springframework.util.StringUtils; */ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { - private final List> loaders = new ArrayList<>(); + private final List> loaders = new ArrayList<>(); - private final List> mappedLoaders = new ArrayList<>(); + private final List> mappedLoaders = new ArrayList<>(); private final Supplier defaultOptionsSupplier; @@ -69,6 +70,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { /** * Constructor with a default {@link DataLoaderOptions} supplier to use as * a starting point for batch loader registrations. + * @param defaultOptionsSupplier the supplier for data loader options * @since 1.1.0 */ public DefaultBatchLoaderRegistry(Supplier defaultOptionsSupplier) { @@ -126,11 +128,11 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { @Nullable private Consumer optionsConsumer; - public DefaultRegistrationSpec(Class valueType) { + DefaultRegistrationSpec(Class valueType) { this.valueType = valueType; } - public DefaultRegistrationSpec(String name) { + DefaultRegistrationSpec(String name) { this.name = name; this.valueType = null; } @@ -143,8 +145,8 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { @Override public RegistrationSpec withOptions(Consumer optionsConsumer) { - this.optionsConsumer = (this.optionsConsumer != null ? - this.optionsConsumer.andThen(optionsConsumer) : optionsConsumer); + this.optionsConsumer = (this.optionsConsumer != null) ? + this.optionsConsumer.andThen(optionsConsumer) : optionsConsumer; return this; } @@ -177,7 +179,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { private Supplier initOptionsSupplier() { Supplier optionsSupplier = () -> - new DataLoaderOptions(this.options != null ? + new DataLoaderOptions((this.options != null) ? this.options : DefaultBatchLoaderRegistry.this.defaultOptionsSupplier.get()); if (this.optionsConsumer == null) { @@ -197,7 +199,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { * {@link BatchLoaderWithContext} that delegates to a {@link Flux} batch * loading function and exposes Reactor context to it. */ - private static class ReactorBatchLoader implements BatchLoaderWithContext { + private static final class ReactorBatchLoader implements BatchLoaderWithContext { private final String name; @@ -214,11 +216,11 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { this.optionsSupplier = optionsSupplier; } - public String getName() { + String getName() { return this.name; } - public DataLoaderOptions getOptions() { + DataLoaderOptions getOptions() { return this.optionsSupplier.get(); } @@ -246,7 +248,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { * {@link MappedBatchLoaderWithContext} that delegates to a {@link Mono} * batch loading function and exposes Reactor context to it. */ - private static class ReactorMappedBatchLoader implements MappedBatchLoaderWithContext { + private static final class ReactorMappedBatchLoader implements MappedBatchLoaderWithContext { private final String name; @@ -263,11 +265,11 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { this.optionsSupplier = optionsSupplier; } - public String getName() { + String getName() { return this.name; } - public DataLoaderOptions getOptions() { + DataLoaderOptions getOptions() { return this.optionsSupplier.get(); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultExecutionGraphQlService.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultExecutionGraphQlService.java index e79b67b3..ebd5e4b8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultExecutionGraphQlService.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultExecutionGraphQlService.java @@ -97,7 +97,7 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService { (this.hasDataLoaderRegistrations ? registerDataLoaders(executionInput) : executionInput); return Mono.fromFuture(this.graphQlSource.graphQl().executeAsync(updatedExecutionInput)) - .map(result -> new DefaultExecutionGraphQlResponse(updatedExecutionInput, result)); + .map((result) -> new DefaultExecutionGraphQlResponse(updatedExecutionInput, result)); }); } @@ -107,7 +107,7 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService { if (existingRegistry == DataLoaderDispatcherInstrumentationState.EMPTY_DATALOADER_REGISTRY) { DataLoaderRegistry newRegistry = DataLoaderRegistry.newRegistry().build(); applyDataLoaderRegistrars(newRegistry, graphQLContext); - executionInput = executionInput.transform(builder -> builder.dataLoaderRegistry(newRegistry)); + executionInput = executionInput.transform((builder) -> builder.dataLoaderRegistry(newRegistry)); } else { applyDataLoaderRegistrars(existingRegistry, graphQLContext); @@ -116,7 +116,7 @@ public class DefaultExecutionGraphQlService implements ExecutionGraphQlService { } private void applyDataLoaderRegistrars(DataLoaderRegistry registry, GraphQLContext graphQLContext) { - this.dataLoaderRegistrars.forEach(registrar -> registrar.registerDataLoaders(registry, graphQLContext)); + this.dataLoaderRegistrars.forEach((registrar) -> registrar.registerDataLoaders(registry, graphQLContext)); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java index 2c946379..3b0a7c21 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilder.java @@ -52,7 +52,6 @@ import org.springframework.util.Assert; * * @author Rossen Stoyanchev * @author Brian Clozel - * @since 1.0.0 */ final class DefaultSchemaResourceGraphQlSourceBuilder extends AbstractGraphQlSourceBuilder @@ -141,7 +140,7 @@ final class DefaultSchemaResourceGraphQlSourceBuilder RuntimeWiring runtimeWiring = initRuntimeWiring(); TypeResolver typeResolver = initTypeResolver(); - registry.types().values().forEach(def -> { + registry.types().values().forEach((def) -> { if (def instanceof UnionTypeDefinition || def instanceof InterfaceTypeDefinition) { runtimeWiring.getTypeResolvers().putIfAbsent(def.getName(), typeResolver); } @@ -151,15 +150,15 @@ final class DefaultSchemaResourceGraphQlSourceBuilder // visitors may transform the schema, for example to add Connection types. if (this.schemaReportConsumer != null) { - this.schemaReportRunner = schema -> { + this.schemaReportRunner = (schema) -> { SchemaReport report = SchemaMappingInspector.inspect(schema, runtimeWiring); this.schemaReportConsumer.accept(report); }; } - return (this.schemaFactory != null ? + return (this.schemaFactory != null) ? this.schemaFactory.apply(registry, runtimeWiring) : - new SchemaGenerator().makeExecutableSchema(registry, runtimeWiring)); + new SchemaGenerator().makeExecutableSchema(registry, runtimeWiring); } private TypeDefinitionRegistry parse(Resource schemaResource) { @@ -180,14 +179,14 @@ final class DefaultSchemaResourceGraphQlSourceBuilder private RuntimeWiring initRuntimeWiring() { RuntimeWiring.Builder builder = RuntimeWiring.newRuntimeWiring(); - this.runtimeWiringConfigurers.forEach(configurer -> configurer.configure(builder)); + this.runtimeWiringConfigurers.forEach((configurer) -> configurer.configure(builder)); List factories = new ArrayList<>(); WiringFactory factory = builder.build().getWiringFactory(); if (!factory.getClass().equals(NoopWiringFactory.class)) { factories.add(factory); } - this.runtimeWiringConfigurers.forEach(configurer -> configurer.configure(builder, factories)); + this.runtimeWiringConfigurers.forEach((configurer) -> configurer.configure(builder, factories)); if (!factories.isEmpty()) { builder.wiringFactory(new CombinedWiringFactory(factories)); } @@ -196,7 +195,7 @@ final class DefaultSchemaResourceGraphQlSourceBuilder } private TypeResolver initTypeResolver() { - return (this.typeResolver != null ? this.typeResolver : new ClassNameTypeResolver()); + return (this.typeResolver != null) ? this.typeResolver : new ClassNameTypeResolver(); } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java index 76b4ea0c..46c1a5ec 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultTypeVisitorHelper.java @@ -27,7 +27,6 @@ import org.springframework.lang.Nullable; * against {@link GraphQLSchema}. * * @author Rossen Stoyanchev - * @since 1.2.1 */ final class DefaultTypeVisitorHelper implements TypeVisitorHelper { @@ -36,11 +35,11 @@ final class DefaultTypeVisitorHelper implements TypeVisitorHelper { /** - * Package private constructor + * Package private constructor. */ DefaultTypeVisitorHelper(GraphQLSchema schema) { GraphQLObjectType subscriptionType = schema.getSubscriptionType(); - this.subscriptionTypeName = (subscriptionType != null ? subscriptionType.getName() : null); + this.subscriptionTypeName = (subscriptionType != null) ? subscriptionType.getName() : null; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java index 8cbc88c9..2ecd06e3 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandler.java @@ -41,7 +41,6 @@ import org.springframework.util.Assert; * in a sequence until one returns a list of {@link GraphQLError}'s. * * @author Rossen Stoyanchev - * @since 1.0.0 */ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler { @@ -67,11 +66,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler ContextSnapshot snapshot = ContextSnapshot.captureFrom(env.getGraphQlContext()); try { return Flux.fromIterable(this.resolvers) - .flatMap(resolver -> resolver.resolveException(exception, env)) - .map(errors -> DataFetcherExceptionHandlerResult.newResult().errors(errors).build()) + .flatMap((resolver) -> resolver.resolveException(exception, env)) + .map((errors) -> DataFetcherExceptionHandlerResult.newResult().errors(errors).build()) .next() - .doOnNext(result -> logResolvedException(exception, result)) - .onErrorResume(resolverEx -> Mono.just(handleResolverError(resolverEx, exception, env))) + .doOnNext((result) -> logResolvedException(exception, result)) + .onErrorResume((resolverEx) -> Mono.just(handleResolverError(resolverEx, exception, env))) .switchIfEmpty(Mono.fromCallable(() -> createInternalError(exception, env))) .contextWrite(snapshot::updateContext) .toFuture(); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ExternalSchemaGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ExternalSchemaGraphQlSourceBuilder.java index e4170a95..95b2e0c8 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ExternalSchemaGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ExternalSchemaGraphQlSourceBuilder.java @@ -27,7 +27,6 @@ import org.springframework.util.Assert; * {@link GraphQLSchema}. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class ExternalSchemaGraphQlSourceBuilder extends AbstractGraphQlSourceBuilder @@ -36,7 +35,7 @@ final class ExternalSchemaGraphQlSourceBuilder private final GraphQLSchema schema; - public ExternalSchemaGraphQlSourceBuilder(GraphQLSchema schema) { + ExternalSchemaGraphQlSourceBuilder(GraphQLSchema schema) { Assert.notNull(schema, "GraphQLSchema is required"); this.schema = schema; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlContextAccessor.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlContextAccessor.java index 3e8c1736..575af5d4 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlContextAccessor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlContextAccessor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; @@ -39,7 +40,7 @@ public class GraphQlContextAccessor implements ContextAccessor keyPredicate, Map readValues) { - context.stream().forEach(entry -> { + context.stream().forEach((entry) -> { if (keyPredicate.test(entry.getKey())) { readValues.put(entry.getKey(), entry.getValue()); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlSource.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlSource.java index 119893b0..f05a6ceb 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlSource.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/GraphQlSource.java @@ -69,6 +69,7 @@ public interface GraphQlSource { /** * Return a {@link GraphQlSource} builder that uses an externally prepared * {@link GraphQLSchema}. + * @param schema the GraphQL schema */ static Builder builder(GraphQLSchema schema) { return new ExternalSchemaGraphQlSourceBuilder(schema); @@ -79,6 +80,7 @@ public interface GraphQlSource { /** * Common configuration options for all {@link GraphQlSource} builders, * independent of how {@link GraphQLSchema} is created. + * @param the builder type */ interface Builder> { @@ -125,8 +127,8 @@ public interface GraphQlSource { * {@link #typeVisitors(List)} if it's not necessary to change the schema. * @param typeVisitors the type visitors to register * @return the current builder - * @see graphql.schema.SchemaTransformer#transformSchema(GraphQLSchema, GraphQLTypeVisitor) * @since 1.1.0 + * @see graphql.schema.SchemaTransformer#transformSchema(GraphQLSchema, GraphQLTypeVisitor) */ B typeVisitorsToTransformSchema(List typeVisitors); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/ReactiveSecurityDataFetcherExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/ReactiveSecurityDataFetcherExceptionResolver.java index b5033664..7f539a50 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/ReactiveSecurityDataFetcherExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/ReactiveSecurityDataFetcherExceptionResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.Collections; @@ -62,7 +63,7 @@ public class ReactiveSecurityDataFetcherExceptionResolver implements DataFetcher } if (ex instanceof AccessDeniedException) { return ReactiveSecurityContextHolder.getContext() - .map(context -> Collections.singletonList( + .map((context) -> Collections.singletonList( SecurityExceptionResolverUtils.resolveAccessDenied(environment, this.trustResolver, context))) .switchIfEmpty(Mono.fromCallable(() -> Collections.singletonList( SecurityExceptionResolverUtils.resolveUnauthorized(environment)))); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/RuntimeWiringConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/RuntimeWiringConfigurer.java index e45ce931..23b568a6 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/RuntimeWiringConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/RuntimeWiringConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaMappingInspector.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaMappingInspector.java index 10f94b07..42c46e9f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaMappingInspector.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaMappingInspector.java @@ -81,7 +81,7 @@ import org.springframework.util.MultiValueMap; * @since 1.2.0 */ @SuppressWarnings("rawtypes") -public class SchemaMappingInspector { +public final class SchemaMappingInspector { private static final Log logger = LogFactory.getLog(SchemaMappingInspector.class); @@ -211,7 +211,7 @@ public class SchemaMappingInspector { } private GraphQLType unwrapIfNonNull(GraphQLType type) { - return (type instanceof GraphQLNonNull graphQLNonNull ? graphQLNonNull.getWrappedType() : type); + return (type instanceof GraphQLNonNull graphQLNonNull) ? graphQLNonNull.getWrappedType() : type; } private boolean isPaginatedType(GraphQLType type) { @@ -277,7 +277,7 @@ public class SchemaMappingInspector { } private static String typeNameToString(GraphQLType type) { - return (type instanceof GraphQLNamedType namedType ? namedType.getName() : type.toString()); + return (type instanceof GraphQLNamedType namedType) ? namedType.getName() : type.toString(); } private boolean addAndCheckIfAlreadyInspected(GraphQLType type) { @@ -331,6 +331,8 @@ public class SchemaMappingInspector { /** * Variant of {@link #inspect(GraphQLSchema, RuntimeWiring)} with a map of * {@code DataFetcher} registrations. + * @param schema the schema to inspect + * @param dataFetchers the map of registered {@code DataFetcher} instances * @since 1.2.5 */ public static SchemaReport inspect(GraphQLSchema schema, Map> dataFetchers) { @@ -341,7 +343,7 @@ public class SchemaMappingInspector { /** * Helps to build a {@link SchemaReport}. */ - private class ReportBuilder { + private final class ReportBuilder { private final List unmappedFields = new ArrayList<>(); @@ -349,19 +351,19 @@ public class SchemaMappingInspector { private final List skippedTypes = new ArrayList<>(); - public void unmappedField(FieldCoordinates coordinates) { + void unmappedField(FieldCoordinates coordinates) { this.unmappedFields.add(coordinates); } - public void unmappedRegistration(FieldCoordinates coordinates, DataFetcher dataFetcher) { + void unmappedRegistration(FieldCoordinates coordinates, DataFetcher dataFetcher) { this.unmappedRegistrations.put(coordinates, dataFetcher); } - public void skippedType(GraphQLType type, FieldCoordinates coordinates) { + void skippedType(GraphQLType type, FieldCoordinates coordinates) { this.skippedTypes.add(new DefaultSkippedType(type, coordinates)); } - public SchemaReport build() { + SchemaReport build() { return new DefaultSchemaReport(this.unmappedFields, this.unmappedRegistrations, this.skippedTypes); } @@ -379,7 +381,7 @@ public class SchemaMappingInspector { private final List skippedTypes; - public DefaultSchemaReport( + DefaultSchemaReport( List unmappedFields, Map> unmappedRegistrations, List skippedTypes) { @@ -426,8 +428,8 @@ public class SchemaMappingInspector { private String formatUnmappedFields() { MultiValueMap map = new LinkedMultiValueMap<>(); - this.unmappedFields.forEach(coordinates -> { - List fields = map.computeIfAbsent(coordinates.getTypeName(), s -> new ArrayList<>()); + this.unmappedFields.forEach((coordinates) -> { + List fields = map.computeIfAbsent(coordinates.getTypeName(), (s) -> new ArrayList<>()); fields.add(coordinates.getFieldName()); }); return map.toString(); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaReport.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaReport.java index 5a8ee775..0c7d578d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaReport.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SchemaReport.java @@ -71,6 +71,7 @@ public interface SchemaReport { /** * Return the {@code DataFetcher} for the given field coordinates, if registered. + * @param coordinates the field coordinates */ @Nullable DataFetcher dataFetcher(FieldCoordinates coordinates); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityContextThreadLocalAccessor.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityContextThreadLocalAccessor.java index ed2ca52f..ff56c68c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityContextThreadLocalAccessor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityContextThreadLocalAccessor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import io.micrometer.context.ThreadLocalAccessor; @@ -33,7 +34,7 @@ import org.springframework.util.ClassUtils; */ public class SecurityContextThreadLocalAccessor implements ThreadLocalAccessor { - private final static boolean springSecurityPresent = ClassUtils.isPresent( + private static final boolean springSecurityPresent = ClassUtils.isPresent( "org.springframework.security.core.context.SecurityContext", SecurityContextThreadLocalAccessor.class.getClassLoader()); @@ -77,9 +78,9 @@ public class SecurityContextThreadLocalAccessor implements ThreadLocalAccessor { + private static final class DelegateAccessor implements ThreadLocalAccessor { @Override public Object key() { @@ -105,7 +106,7 @@ public class SecurityContextThreadLocalAccessor implements ThreadLocalAccessor { + private static final class NoOpAccessor implements ThreadLocalAccessor { @Override public Object key() { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityDataFetcherExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityDataFetcherExceptionResolver.java index 2aabd3c1..f1a67eab 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityDataFetcherExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityDataFetcherExceptionResolver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import graphql.GraphQLError; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityExceptionResolverUtils.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityExceptionResolverUtils.java index dd84e95a..7fdc0cfa 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityExceptionResolverUtils.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SecurityExceptionResolverUtils.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import graphql.GraphQLError; @@ -26,9 +27,12 @@ import org.springframework.security.core.context.SecurityContext; * Package private delegate class shared by the reactive and non-reactive resolver types. * * @author Rossen Stoyanchev - * @since 1.0.0 */ -class SecurityExceptionResolverUtils { +final class SecurityExceptionResolverUtils { + + private SecurityExceptionResolverUtils() { + + } static GraphQLError resolveUnauthorized(DataFetchingEnvironment environment) { return GraphqlErrorBuilder.newError(environment) diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SelfDescribingDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SelfDescribingDataFetcher.java index 643d431b..b430feac 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SelfDescribingDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SelfDescribingDataFetcher.java @@ -24,6 +24,7 @@ import org.springframework.core.ResolvableType; * Specialized {@link DataFetcher} that exposes additional details such as * return type information. * + * @param the type of data returned by the {@code DataFetcher} * @author Brian Clozel * @author Rossen Stoyanchev * @since 1.2.0 diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolver.java index 4fd441a2..44b80837 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolver.java @@ -44,35 +44,35 @@ import reactor.core.publisher.Mono; @FunctionalInterface public interface SubscriptionExceptionResolver { - /** - * Resolve the given exception to a list of {@link GraphQLError}'s to be - * sent in an error message to the client. - * @param exception the exception from the Publisher - * @return a {@code Mono} with the GraphQL errors to send to the client; - * if the {@code Mono} completes with an empty List, the exception is resolved - * without any errors to send; if the {@code Mono} completes empty, without - * emitting a List, the exception remains unresolved, and that allows other - * resolvers to resolve it. - */ - Mono> resolveException(Throwable exception); + /** + * Resolve the given exception to a list of {@link GraphQLError}'s to be + * sent in an error message to the client. + * @param exception the exception from the Publisher + * @return a {@code Mono} with the GraphQL errors to send to the client; + * if the {@code Mono} completes with an empty List, the exception is resolved + * without any errors to send; if the {@code Mono} completes empty, without + * emitting a List, the exception remains unresolved, and that allows other + * resolvers to resolve it. + */ + Mono> resolveException(Throwable exception); - /** - * Factory method to create a {@link SubscriptionExceptionResolver} to - * resolve an exception to a single GraphQL error. Effectively, a shortcut - * for creating {@link SubscriptionExceptionResolverAdapter} and overriding - * its {@code resolveToSingleError} method. - * @param resolver the resolver function to map the exception - * @return the created instance - */ - static SubscriptionExceptionResolverAdapter forSingleError(Function resolver) { - return new SubscriptionExceptionResolverAdapter() { + /** + * Factory method to create a {@link SubscriptionExceptionResolver} to + * resolve an exception to a single GraphQL error. Effectively, a shortcut + * for creating {@link SubscriptionExceptionResolverAdapter} and overriding + * its {@code resolveToSingleError} method. + * @param resolver the resolver function to map the exception + * @return the created instance + */ + static SubscriptionExceptionResolverAdapter forSingleError(Function resolver) { + return new SubscriptionExceptionResolverAdapter() { - @Override - protected GraphQLError resolveToSingleError(Throwable ex) { - return resolver.apply(ex); - } - }; - } + @Override + protected GraphQLError resolveToSingleError(Throwable ex) { + return resolver.apply(ex); + } + }; + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolverAdapter.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolverAdapter.java index 92c5a418..bb88117f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolverAdapter.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionExceptionResolverAdapter.java @@ -48,76 +48,76 @@ import org.springframework.lang.Nullable; */ public abstract class SubscriptionExceptionResolverAdapter implements SubscriptionExceptionResolver { - protected final Log logger = LogFactory.getLog(getClass()); + protected final Log logger = LogFactory.getLog(getClass()); - private boolean threadLocalContextAware; + private boolean threadLocalContextAware; - /** - * Subclasses can set this to indicate that ThreadLocal context from the - * transport handler (e.g. HTTP handler) should be restored when resolving - * exceptions. - *

    Note: This property is applicable only if transports - * use ThreadLocal's' (e.g. Spring MVC) and if a {@link ThreadLocalAccessor} - * is registered to extract ThreadLocal values of interest. There is no - * impact from setting this property otherwise. - *

    By default this is set to "false" in which case there is no attempt - * to propagate ThreadLocal context. - * @param threadLocalContextAware whether this resolver needs access to - * ThreadLocal context or not. - */ - public void setThreadLocalContextAware(boolean threadLocalContextAware) { - this.threadLocalContextAware = threadLocalContextAware; - } + /** + * Subclasses can set this to indicate that ThreadLocal context from the + * transport handler (e.g. HTTP handler) should be restored when resolving + * exceptions. + *

    Note: This property is applicable only if transports + * use ThreadLocal's' (e.g. Spring MVC) and if a {@link ThreadLocalAccessor} + * is registered to extract ThreadLocal values of interest. There is no + * impact from setting this property otherwise. + *

    By default this is set to "false" in which case there is no attempt + * to propagate ThreadLocal context. + * @param threadLocalContextAware whether this resolver needs access to + * ThreadLocal context or not. + */ + public void setThreadLocalContextAware(boolean threadLocalContextAware) { + this.threadLocalContextAware = threadLocalContextAware; + } - /** - * Whether ThreadLocal context needs to be restored for this resolver. - */ - public boolean isThreadLocalContextAware() { - return this.threadLocalContextAware; - } + /** + * Whether ThreadLocal context needs to be restored for this resolver. + */ + public boolean isThreadLocalContextAware() { + return this.threadLocalContextAware; + } - @SuppressWarnings({"unused", "try", "deprecation"}) - @Override - public final Mono> resolveException(Throwable exception) { - if (this.threadLocalContextAware) { - return Mono.deferContextual(contextView -> { - ContextSnapshot snapshot = ContextSnapshot.captureFrom(contextView); - try { - List errors = snapshot.wrap(() -> resolveToMultipleErrors(exception)).call(); - return Mono.justOrEmpty(errors); - } - catch (Exception ex2) { - logger.warn("Failed to resolve " + exception, ex2); - return Mono.empty(); - } - }); - } - else { - return Mono.justOrEmpty(resolveToMultipleErrors(exception)); - } - } + @SuppressWarnings({"unused", "try", "deprecation"}) + @Override + public final Mono> resolveException(Throwable exception) { + if (this.threadLocalContextAware) { + return Mono.deferContextual((contextView) -> { + ContextSnapshot snapshot = ContextSnapshot.captureFrom(contextView); + try { + List errors = snapshot.wrap(() -> resolveToMultipleErrors(exception)).call(); + return Mono.justOrEmpty(errors); + } + catch (Exception ex2) { + this.logger.warn("Failed to resolve " + exception, ex2); + return Mono.empty(); + } + }); + } + else { + return Mono.justOrEmpty(resolveToMultipleErrors(exception)); + } + } - /** - * Override this method to resolve the Exception to multiple GraphQL errors. - * @param exception the exception to resolve - * @return the resolved errors or {@code null} if unresolved - */ - @Nullable - protected List resolveToMultipleErrors(Throwable exception) { - GraphQLError error = resolveToSingleError(exception); - return (error != null ? Collections.singletonList(error) : null); - } + /** + * Override this method to resolve the Exception to multiple GraphQL errors. + * @param exception the exception to resolve + * @return the resolved errors or {@code null} if unresolved + */ + @Nullable + protected List resolveToMultipleErrors(Throwable exception) { + GraphQLError error = resolveToSingleError(exception); + return (error != null) ? Collections.singletonList(error) : null; + } - /** - * Override this method to resolve the Exception to a single GraphQL error. - * @param exception the exception to resolve - * @return the resolved error or {@code null} if unresolved - */ - @Nullable - protected GraphQLError resolveToSingleError(Throwable exception) { - return null; - } + /** + * Override this method to resolve the Exception to a single GraphQL error. + * @param exception the exception to resolve + * @return the resolved error or {@code null} if unresolved + */ + @Nullable + protected GraphQLError resolveToSingleError(Throwable exception) { + return null; + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionPublisherException.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionPublisherException.java index 82ad10fb..851f7d9b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionPublisherException.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/SubscriptionPublisherException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; @@ -37,26 +38,28 @@ import org.springframework.core.NestedRuntimeException; @SuppressWarnings("serial") public final class SubscriptionPublisherException extends NestedRuntimeException { - private final List errors; + private final List errors; - /** - * Constructor with the resolved GraphQL errors and the original exception - * from the GraphQL subscription {@link org.reactivestreams.Publisher}. - */ - public SubscriptionPublisherException(List errors, Throwable cause) { - super("GraphQL subscription ended with error(s): " + errors, cause); - this.errors = errors; - } + /** + * Constructor with the resolved GraphQL errors and the original exception + * from the GraphQL subscription {@link org.reactivestreams.Publisher}. + * @param errors the list of resolved GraphQL errors + * @param cause the original exception + */ + public SubscriptionPublisherException(List errors, Throwable cause) { + super("GraphQL subscription ended with error(s): " + errors, cause); + this.errors = errors; + } - /** - * Return the GraphQL errors the exception was resolved to by the configured - * {@link SubscriptionExceptionResolver}'s. These errors can be included in - * an error message to be sent to the client by the underlying transport. - */ - public List getErrors() { - return this.errors; - } + /** + * Return the GraphQL errors the exception was resolved to by the configured + * {@link SubscriptionExceptionResolver}'s. These errors can be included in + * an error message to be sent to the client by the underlying transport. + */ + public List getErrors() { + return this.errors; + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeDefinitionConfigurer.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeDefinitionConfigurer.java index 96d0387a..7e78718e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeDefinitionConfigurer.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeDefinitionConfigurer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import graphql.schema.GraphQLSchema; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java index e75ade9c..b02be750 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/TypeVisitorHelper.java @@ -33,12 +33,14 @@ public interface TypeVisitorHelper { /** * Whether the given type is the subscription type. + * @param type the GraphQL type to check */ boolean isSubscriptionType(GraphQLNamedType type); /** * Create an instance with the given {@link GraphQLSchema}. + * @param schema the GraphQL schema to use */ static TypeVisitorHelper create(GraphQLSchema schema) { return new DefaultTypeVisitorHelper(schema); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConvention.java b/spring-graphql/src/main/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConvention.java index c994e8a8..1c46b7a4 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConvention.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConvention.java @@ -66,7 +66,8 @@ public class DefaultDataFetcherObservationConvention implements DataFetcherObser protected KeyValue outcome(DataFetcherObservationContext context) { if (context.getError() != null) { return OUTCOME_ERROR; - } return OUTCOME_SUCCESS; + } + return OUTCOME_SUCCESS; } protected KeyValue fieldName(DataFetcherObservationContext context) { @@ -76,7 +77,8 @@ public class DefaultDataFetcherObservationConvention implements DataFetcherObser protected KeyValue errorType(DataFetcherObservationContext context) { if (context.getError() != null) { return KeyValue.of(DataFetcherLowCardinalityKeyNames.ERROR_TYPE, context.getError().getClass().getSimpleName()); - } return ERROR_TYPE_NONE; + } + return ERROR_TYPE_NONE; } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/observation/ExecutionRequestObservationContext.java b/spring-graphql/src/main/java/org/springframework/graphql/observation/ExecutionRequestObservationContext.java index 044468cd..919b90bf 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/observation/ExecutionRequestObservationContext.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/observation/ExecutionRequestObservationContext.java @@ -19,6 +19,7 @@ package org.springframework.graphql.observation; import graphql.ExecutionInput; import graphql.ExecutionResult; import io.micrometer.observation.Observation; + import org.springframework.lang.Nullable; /** @@ -30,58 +31,58 @@ import org.springframework.lang.Nullable; */ public class ExecutionRequestObservationContext extends Observation.Context { - private final ExecutionInput executionInput; + private final ExecutionInput executionInput; - @Nullable - private ExecutionResult executionResult; + @Nullable + private ExecutionResult executionResult; - public ExecutionRequestObservationContext(ExecutionInput executionInput) { - this.executionInput = executionInput; - } + public ExecutionRequestObservationContext(ExecutionInput executionInput) { + this.executionInput = executionInput; + } - /** - * Return the {@link ExecutionInput input} for the request execution. - * @since 1.1.4 - */ - public ExecutionInput getExecutionInput() { - return this.executionInput; - } + /** + * Return the {@link ExecutionInput input} for the request execution. + * @since 1.1.4 + */ + public ExecutionInput getExecutionInput() { + return this.executionInput; + } - /** - * Return the {@link ExecutionInput input} for the request execution. - * @deprecated since 1.1.4 in favor of {@link #getExecutionInput()} - */ - @Deprecated(since = "1.1.4", forRemoval = true) - public ExecutionInput getCarrier() { - return this.executionInput; - } + /** + * Return the {@link ExecutionInput input} for the request execution. + * @deprecated since 1.1.4 in favor of {@link #getExecutionInput()} + */ + @Deprecated(since = "1.1.4", forRemoval = true) + public ExecutionInput getCarrier() { + return this.executionInput; + } - /** - * Return the {@link ExecutionResult result} for the request execution. - * @since 1.1.4 - */ - @Nullable - public ExecutionResult getExecutionResult() { - return this.executionResult; - } + /** + * Return the {@link ExecutionResult result} for the request execution. + * @since 1.1.4 + */ + @Nullable + public ExecutionResult getExecutionResult() { + return this.executionResult; + } - /** - * Set the {@link ExecutionResult result} for the request execution. - * @param executionResult the execution result - * @since 1.1.4 - */ - public void setExecutionResult(ExecutionResult executionResult) { - this.executionResult = executionResult; - } + /** + * Set the {@link ExecutionResult result} for the request execution. + * @param executionResult the execution result + * @since 1.1.4 + */ + public void setExecutionResult(ExecutionResult executionResult) { + this.executionResult = executionResult; + } - /** - * Return the {@link ExecutionResult result} for the request execution. - * @deprecated since 1.1.4 in favor of {@link #getExecutionResult()} - */ - @Nullable - @Deprecated(since = "1.1.4", forRemoval = true) - public ExecutionResult getResponse() { - return this.executionResult; - } + /** + * Return the {@link ExecutionResult result} for the request execution. + * @deprecated since 1.1.4 in favor of {@link #getExecutionResult()} + */ + @Nullable + @Deprecated(since = "1.1.4", forRemoval = true) + public ExecutionResult getResponse() { + return this.executionResult; + } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationDocumentation.java b/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationDocumentation.java index ed66dca3..3d512a48 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationDocumentation.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationDocumentation.java @@ -140,7 +140,7 @@ public enum GraphQlObservationDocumentation implements ObservationDocumentation }, /** - * Class name of the data fetching error + * Class name of the data fetching error. */ ERROR_TYPE { @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationInstrumentation.java b/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationInstrumentation.java index 1fee0bd6..c876405a 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationInstrumentation.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/observation/GraphQlObservationInstrumentation.java @@ -16,6 +16,9 @@ package org.springframework.graphql.observation; +import java.util.concurrent.CompletionException; +import java.util.concurrent.CompletionStage; + import graphql.ExecutionResult; import graphql.GraphQLContext; import graphql.execution.instrumentation.InstrumentationContext; @@ -31,10 +34,8 @@ import graphql.schema.DataFetchingEnvironmentImpl; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; -import org.springframework.lang.Nullable; -import java.util.concurrent.CompletionException; -import java.util.concurrent.CompletionStage; +import org.springframework.lang.Nullable; /** * {@link graphql.execution.instrumentation.Instrumentation} that creates @@ -151,7 +152,8 @@ public class GraphQlObservationInstrumentation extends SimplePerformantInstrumen dataFetcherObservation.error(error.getCause()); dataFetcherObservation.stop(); throw completionException; - } else { + } + else { dataFetcherObservation.error(error); dataFetcherObservation.stop(); throw new CompletionException(error); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/DefaultWebGraphQlHandlerBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/server/DefaultWebGraphQlHandlerBuilder.java index f38e6954..51265642 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/DefaultWebGraphQlHandlerBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/DefaultWebGraphQlHandlerBuilder.java @@ -58,7 +58,7 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { @Override public WebGraphQlHandler.Builder interceptors(List interceptors) { this.interceptors.addAll(interceptors); - interceptors.forEach(interceptor -> { + interceptors.forEach((interceptor) -> { if (interceptor instanceof WebSocketGraphQlInterceptor) { Assert.isNull(this.webSocketInterceptor, "There can be at most 1 WebSocketInterceptor"); this.webSocketInterceptor = (WebSocketGraphQlInterceptor) interceptor; @@ -70,19 +70,21 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { @Override public WebGraphQlHandler build() { - Chain endOfChain = request -> this.service.execute(request).map(WebGraphQlResponse::new); + Chain endOfChain = (request) -> this.service.execute(request).map(WebGraphQlResponse::new); Chain executionChain = this.interceptors.stream() .reduce(WebGraphQlInterceptor::andThen) - .map(interceptor -> interceptor.apply(endOfChain)) + .map((interceptor) -> interceptor.apply(endOfChain)) .orElse(endOfChain); return new WebGraphQlHandler() { @Override public WebSocketGraphQlInterceptor getWebSocketInterceptor() { - return (webSocketInterceptor != null ? - webSocketInterceptor : new WebSocketGraphQlInterceptor() {}); + return ((DefaultWebGraphQlHandlerBuilder.this.webSocketInterceptor != null) ? + DefaultWebGraphQlHandlerBuilder.this.webSocketInterceptor : new WebSocketGraphQlInterceptor() { + + }); } @Override diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/GraphQlRSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/GraphQlRSocketHandler.java index 9f0fc9e8..ba129388 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/GraphQlRSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/GraphQlRSocketHandler.java @@ -61,12 +61,12 @@ import org.springframework.util.MimeTypeUtils; * } * * @MessageMapping("graphql") - * public Mono> handle(Map payload) { + * public Mono<Map<String, Object>> handle(Map<String, Object> payload) { * return this.handler.handle(payload); * } * * @MessageMapping("graphql") - * public Flux> handleSubscription(Map payload) { + * public Flux<Map<String, Object>> handleSubscription(Map<String, Object> payload) { * return this.handler.handleSubscription(payload); * } * } @@ -107,17 +107,18 @@ public class GraphQlRSocketHandler { } private static Chain initChain(ExecutionGraphQlService service, List interceptors) { - Chain endOfChain = request -> service.execute(request).map(RSocketGraphQlResponse::new); + Chain endOfChain = (request) -> service.execute(request).map(RSocketGraphQlResponse::new); return interceptors.isEmpty() ? endOfChain : interceptors.stream() .reduce(RSocketGraphQlInterceptor::andThen) - .map(interceptor -> interceptor.apply(endOfChain)) + .map((interceptor) -> interceptor.apply(endOfChain)) .orElse(endOfChain); } /** * Handle a {@code Request-Response} interaction. For queries and mutations. + * @param payload the decoded GraphQL request payload */ public Mono> handle(Map payload) { return handleInternal(payload).map(ExecutionGraphQlResponse::toMap); @@ -125,10 +126,11 @@ public class GraphQlRSocketHandler { /** * Handle a {@code Request-Stream} interaction. For subscriptions. + * @param payload the decoded GraphQL request payload */ public Flux> handleSubscription(Map payload) { return handleInternal(payload) - .flatMapMany(response -> { + .flatMapMany((response) -> { if (response.getData() instanceof Publisher) { Publisher publisher = response.getData(); return Flux.from(publisher).map(ExecutionResult::toSpecification); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/RSocketGraphQlInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/server/RSocketGraphQlInterceptor.java index cdfeb9e0..f159eefa 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/RSocketGraphQlInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/RSocketGraphQlInterceptor.java @@ -53,7 +53,7 @@ public interface RSocketGraphQlInterceptor { * @return a new interceptor that chains the two */ default RSocketGraphQlInterceptor andThen(RSocketGraphQlInterceptor nextInterceptor) { - return (request, chain) -> intercept(request, nextRequest -> nextInterceptor.intercept(nextRequest, chain)); + return (request, chain) -> intercept(request, (nextRequest) -> nextInterceptor.intercept(nextRequest, chain)); } /** @@ -62,7 +62,7 @@ public interface RSocketGraphQlInterceptor { * @return a new chain instance */ default Chain apply(Chain chain) { - return request -> intercept(request, chain); + return (request) -> intercept(request, chain); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlInterceptor.java index eb6c43ec..2e7dd331 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlInterceptor.java @@ -59,7 +59,7 @@ public interface WebGraphQlInterceptor { * @return a new interceptor that chains the two */ default WebGraphQlInterceptor andThen(WebGraphQlInterceptor nextInterceptor) { - return (request, chain) -> intercept(request, nextRequest -> { + return (request, chain) -> intercept(request, (nextRequest) -> { if (request instanceof WebSocketGraphQlRequest) { Assert.isTrue(nextRequest instanceof WebSocketGraphQlRequest, "Expected WebSocketGraphQlRequest but was: " + nextRequest.getClass().getName()); @@ -74,7 +74,7 @@ public interface WebGraphQlInterceptor { * @return a new chain instance */ default Chain apply(Chain chain) { - return request -> intercept(request, chain); + return (request) -> intercept(request, chain); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlRequest.java index ffa938ee..43aca472 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlRequest.java @@ -83,6 +83,13 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements /** * Variant of {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, Map, GraphQlRequest, String, Locale)} * with a Map for the request body. + * @param uri the URL for the HTTP request or WebSocket handshake + * @param headers the HTTP request headers + * @param cookies the HTTP request cookies + * @param attributes request attributes + * @param body the deserialized content of the GraphQL request + * @param id an identifier for the GraphQL request + * @param locale the locale from the HTTP request, if any * @since 1.1.3 */ public WebGraphQlRequest( @@ -122,6 +129,11 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements /** * Create an instance. + * @param uri the URL for the HTTP request or WebSocket handshake + * @param headers the HTTP request headers + * @param body the deserialized content of the GraphQL request + * @param id an identifier for the GraphQL request + * @param locale the locale from the HTTP request, if any * @deprecated as of 1.1.3 in favor of * {@link #WebGraphQlRequest(URI, HttpHeaders, MultiValueMap, Map, GraphQlRequest, String, Locale)} */ @@ -143,7 +155,7 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements this.uri = UriComponentsBuilder.fromUri(uri).build(true); this.headers = headers; - this.cookies = (cookies != null ? CollectionUtils.unmodifiableMultiValueMap(cookies) : EMPTY_COOKIES); + this.cookies = (cookies != null) ? CollectionUtils.unmodifiableMultiValueMap(cookies) : EMPTY_COOKIES; this.attributes = Collections.unmodifiableMap(attributes); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlInterceptor.java index def46297..11c5ddfe 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlInterceptor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server; import java.util.Map; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java index d3d1a388..00a7a578 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketGraphQlRequest.java @@ -43,9 +43,15 @@ public class WebSocketGraphQlRequest extends WebGraphQlRequest { /** * Create an instance. + * @param uri the URL for the HTTP request or WebSocket handshake + * @param headers the HTTP request headers + * @param body the deserialized content of the GraphQL request + * @param id the id from the GraphQL over WebSocket {@code "subscribe"} message + * @param locale the locale from the HTTP request, if any + * @param sessionInfo the WebSocket session id * @deprecated as of 1.1.3 in favor of the constructor with cookies */ - @Deprecated + @Deprecated(since = "1.1.3", forRemoval = true) public WebSocketGraphQlRequest( URI uri, HttpHeaders headers, Map body, String id, @Nullable Locale locale, WebSocketSessionInfo sessionInfo) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketSessionInfo.java b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketSessionInfo.java index 01eeda4e..4290a5cc 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketSessionInfo.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/WebSocketSessionInfo.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server; import java.net.InetSocketAddress; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessage.java b/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessage.java index 0eabbfb7..33a0f58c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessage.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessage.java @@ -97,6 +97,7 @@ public class GraphQlWebSocketMessage { /** * Return the payload. For a deserialized message, this is typically a * {@code Map} or {@code List} for an {@code "error"} message. + * @param

    teh payload type */ @SuppressWarnings("unchecked") public

    P getPayload() { @@ -120,14 +121,6 @@ public class GraphQlWebSocketMessage { } - @Override - public int hashCode() { - int hashCode = (this.type != null ? this.type.hashCode() : 0); - hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.id); - hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.payload); - return hashCode; - } - @Override public boolean equals(Object o) { if (!(o instanceof GraphQlWebSocketMessage)) { @@ -139,12 +132,20 @@ public class GraphQlWebSocketMessage { (ObjectUtils.nullSafeEquals(getPayload(), other.getPayload()))); } + @Override + public int hashCode() { + int hashCode = (this.type != null) ? this.type.hashCode() : 0; + hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.id); + hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.payload); + return hashCode; + } + @Override public String toString() { return "GraphQlWebSocketMessage[" + - (this.id != null ? "id=\"" + this.id + "\"" + ", " : "") + + ((this.id != null) ? "id=\"" + this.id + "\"" + ", " : "") + "type=\"" + this.type + "\"" + - (this.payload != null ? ", payload=" + this.payload : "") + "]"; + ((this.payload != null) ? ", payload=" + this.payload : "") + "]"; } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessageType.java b/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessageType.java index d5a89724..841eb562 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessageType.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/support/GraphQlWebSocketMessageType.java @@ -26,20 +26,44 @@ package org.springframework.graphql.server.support; */ public enum GraphQlWebSocketMessageType { + /** + * Indicates that the client wants to establish a connection within the existing socket. + */ CONNECTION_INIT("connection_init", false), + /** + * Expected response to the {@link #CONNECTION_INIT} message from the client acknowledging a successful connection with the server. + */ CONNECTION_ACK("connection_ack", false), + /** + * Useful for detecting failed connections, displaying latency metrics or other types of network probing. + */ PING("ping", false), + /** + * The response to the {@link #PING} message. Must be sent as soon as the {@link #PING} message is received. + */ PONG("pong", false), + /** + * Requests an operation specified in the message payload. + */ SUBSCRIBE("subscribe", true), + /** + * Operation execution result(s) from the source stream created by the binding {@link #SUBSCRIBE} message. + */ NEXT("next", true), + /** + * Operation execution error(s) in response to the {@link #SUBSCRIBE} message. + */ ERROR("error", true), + /** + * Indicates that the requested operation execution has completed. + */ COMPLETE("complete", false), /** diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/support/SerializableGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/server/support/SerializableGraphQlRequest.java index d73fb3bc..1e9878ba 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/support/SerializableGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/support/SerializableGraphQlRequest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server.support; import java.util.Map; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/CodecDelegate.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/CodecDelegate.java index bf860e1b..132ddf2d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/CodecDelegate.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/CodecDelegate.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server.webflux; import java.util.Collections; @@ -43,7 +44,6 @@ import org.springframework.web.reactive.socket.WebSocketSession; * Helper class for encoding and decoding GraphQL messages. * * @author Rossen Stoyanchev - * @since 1.0.0 */ final class CodecDelegate { @@ -79,7 +79,7 @@ final class CodecDelegate { @SuppressWarnings("unchecked") - public WebSocketMessage encode(WebSocketSession session, GraphQlWebSocketMessage message) { + WebSocketMessage encode(WebSocketSession session, GraphQlWebSocketMessage message) { DataBuffer buffer = ((Encoder) this.encoder).encodeValue( (T) message, session.bufferFactory(), MESSAGE_TYPE, MimeTypeUtils.APPLICATION_JSON, null); @@ -88,20 +88,20 @@ final class CodecDelegate { } @SuppressWarnings("ConstantConditions") - public GraphQlWebSocketMessage decode(WebSocketMessage webSocketMessage) { + GraphQlWebSocketMessage decode(WebSocketMessage webSocketMessage) { DataBuffer buffer = DataBufferUtils.retain(webSocketMessage.getPayload()); return (GraphQlWebSocketMessage) this.decoder.decode(buffer, MESSAGE_TYPE, null, null); } - public WebSocketMessage encodeConnectionAck(WebSocketSession session, Object ackPayload) { + WebSocketMessage encodeConnectionAck(WebSocketSession session, Object ackPayload) { return encode(session, GraphQlWebSocketMessage.connectionAck(ackPayload)); } - public WebSocketMessage encodeNext(WebSocketSession session, String id, Map responseMap) { + WebSocketMessage encodeNext(WebSocketSession session, String id, Map responseMap) { return encode(session, GraphQlWebSocketMessage.next(id, responseMap)); } - public WebSocketMessage encodeError(WebSocketSession session, String id, Throwable ex) { + WebSocketMessage encodeError(WebSocketSession session, String id, Throwable ex) { List errors = ((ex instanceof SubscriptionPublisherException) ? ((SubscriptionPublisherException) ex).getErrors() : Collections.singletonList(GraphqlErrorBuilder.newError() @@ -111,7 +111,7 @@ final class CodecDelegate { return encode(session, GraphQlWebSocketMessage.error(id, errors)); } - public WebSocketMessage encodeComplete(WebSocketSession session, String id) { + WebSocketMessage encodeComplete(WebSocketSession session, String id) { return encode(session, GraphQlWebSocketMessage.complete(id)); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java index deda89f9..9dd32592 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlHttpHandler.java @@ -49,7 +49,7 @@ public class GraphQlHttpHandler { new MediaType("application", "graphql-response+json"); private static final ParameterizedTypeReference> MAP_PARAMETERIZED_TYPE_REF = - new ParameterizedTypeReference>() {}; + new ParameterizedTypeReference>() { }; @SuppressWarnings("removal") private static final List SUPPORTED_MEDIA_TYPES = @@ -73,7 +73,7 @@ public class GraphQlHttpHandler { */ public Mono handleRequest(ServerRequest serverRequest) { return serverRequest.bodyToMono(SerializableGraphQlRequest.class) - .flatMap(body -> { + .flatMap((body) -> { WebGraphQlRequest graphQlRequest = new WebGraphQlRequest( serverRequest.uri(), serverRequest.headers().asHttpHeaders(), serverRequest.cookies(), serverRequest.attributes(), body, @@ -84,12 +84,12 @@ public class GraphQlHttpHandler { } return this.graphQlHandler.handleRequest(graphQlRequest); }) - .flatMap(response -> { + .flatMap((response) -> { if (logger.isDebugEnabled()) { logger.debug("Execution complete"); } ServerResponse.BodyBuilder builder = ServerResponse.ok(); - builder.headers(headers -> headers.putAll(response.getResponseHeaders())); + builder.headers((headers) -> headers.putAll(response.getResponseHeaders())); builder.contentType(selectResponseMediaType(serverRequest)); return builder.bodyValue(response.toMap()); }); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlWebSocketHandler.java index 0f9a40ac..17d5295f 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphQlWebSocketHandler.java @@ -126,17 +126,17 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { .subscribe(); session.closeStatus() - .doOnSuccess(closeStatus -> { + .doOnSuccess((closeStatus) -> { Map connectionInitPayload = connectionInitPayloadRef.get(); if (connectionInitPayload == null) { return; } - int statusCode = (closeStatus != null ? closeStatus.getCode() : 1005); + int statusCode = (closeStatus != null) ? closeStatus.getCode() : 1005; this.webSocketInterceptor.handleConnectionClosed(sessionInfo, statusCode, connectionInitPayload); }) .subscribe(); - return session.send(session.receive().flatMap(webSocketMessage -> { + return session.send(session.receive().flatMap((webSocketMessage) -> { GraphQlWebSocketMessage message = this.codecDelegate.decode(webSocketMessage); String id = message.getId(); Map payload = message.getPayload(); @@ -155,7 +155,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { logger.debug("Executing: " + request); } return this.graphQlHandler.handleRequest(request) - .flatMapMany(response -> handleResponse(session, id, subscriptions, response)) + .flatMapMany((response) -> handleResponse(session, id, subscriptions, response)) .doOnTerminate(() -> subscriptions.remove(id)); } case PING -> { @@ -178,9 +178,9 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { } return this.webSocketInterceptor.handleConnectionInitialization(sessionInfo, payload) .defaultIfEmpty(Collections.emptyMap()) - .map(ackPayload -> this.codecDelegate.encodeConnectionAck(session, ackPayload)) + .map((ackPayload) -> this.codecDelegate.encodeConnectionAck(session, ackPayload)) .flux() - .onErrorResume(ex -> GraphQlStatus.close(session, GraphQlStatus.UNAUTHORIZED_STATUS)); + .onErrorResume((ex) -> GraphQlStatus.close(session, GraphQlStatus.UNAUTHORIZED_STATUS)); } default -> { return GraphQlStatus.close(session, GraphQlStatus.INVALID_MESSAGE_STATUS); @@ -218,9 +218,9 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { } return responseFlux - .map(responseMap -> this.codecDelegate.encodeNext(session, id, responseMap)) + .map((responseMap) -> this.codecDelegate.encodeNext(session, id, responseMap)) .concatWith(Mono.fromCallable(() -> this.codecDelegate.encodeComplete(session, id))) - .onErrorResume(ex -> { + .onErrorResume((ex) -> { if (ex instanceof SubscriptionExistsException) { CloseStatus status = new CloseStatus(4409, "Subscriber for " + id + " already exists"); return GraphQlStatus.close(session, status); @@ -230,7 +230,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { } - private static class GraphQlStatus { + private static final class GraphQlStatus { static final CloseStatus INVALID_MESSAGE_STATUS = new CloseStatus(4400, "Invalid message"); @@ -247,7 +247,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { } - private static class WebFluxSessionInfo implements WebSocketSessionInfo { + private static final class WebFluxSessionInfo implements WebSocketSessionInfo { private final WebSocketSession session; @@ -288,7 +288,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { @SuppressWarnings("serial") - private static class SubscriptionExistsException extends RuntimeException { + private static final class SubscriptionExistsException extends RuntimeException { } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphiQlHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphiQlHandler.java index 913fe5f2..e1195f9b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphiQlHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/GraphiQlHandler.java @@ -70,6 +70,7 @@ public class GraphiQlHandler { /** * Render the GraphiQL page as "text/html", or if the "path" query parameter * is missing, add it and redirect back to the same URL. + * @param request the HTTP server request */ public Mono handleRequest(ServerRequest request) { return (request.queryParam("path").isPresent() ? diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/SchemaHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/SchemaHandler.java index 0c8c5c47..2c14cf5d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/SchemaHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webflux/SchemaHandler.java @@ -29,6 +29,7 @@ import org.springframework.web.reactive.function.server.ServerResponse; * {@link graphql.schema.GraphQLSchema} printed via {@link SchemaPrinter}. * * @author Rossen Stoyanchev + * @since 1.0.0 */ public class SchemaHandler { @@ -45,7 +46,7 @@ public class SchemaHandler { public Mono handleRequest(ServerRequest request) { return ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .bodyValue(this.printer.print(graphQlSource.schema())); + .bodyValue(this.printer.print(this.graphQlSource.schema())); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java index d87b87a9..393d4dc0 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandler.java @@ -59,7 +59,9 @@ public class GraphQlHttpHandler { private static final Log logger = LogFactory.getLog(GraphQlHttpHandler.class); private static final ParameterizedTypeReference> MAP_PARAMETERIZED_TYPE_REF = - new ParameterizedTypeReference<>() {}; + new ParameterizedTypeReference<>() { + + }; // To be removed in favor of Framework's MediaType.APPLICATION_GRAPHQL_RESPONSE private static final MediaType APPLICATION_GRAPHQL_RESPONSE = @@ -101,12 +103,12 @@ public class GraphQlHttpHandler { } CompletableFuture future = this.graphQlHandler.handleRequest(graphQlRequest) - .map(response -> { + .map((response) -> { if (logger.isDebugEnabled()) { logger.debug("Execution complete"); } ServerResponse.BodyBuilder builder = ServerResponse.ok(); - builder.headers(headers -> headers.putAll(response.getResponseHeaders())); + builder.headers((headers) -> headers.putAll(response.getResponseHeaders())); builder.contentType(selectResponseMediaType(serverRequest)); return builder.body(response.toMap()); }) @@ -130,7 +132,7 @@ public class GraphQlHttpHandler { private static MultiValueMap initCookies(ServerRequest serverRequest) { MultiValueMap source = serverRequest.cookies(); MultiValueMap target = new LinkedMultiValueMap<>(source.size()); - source.values().forEach(cookieList -> cookieList.forEach(cookie -> { + source.values().forEach((cookieList) -> cookieList.forEach((cookie) -> { HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue()); target.add(cookie.getName(), httpCookie); })); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java index ef5f43b6..00064a24 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java @@ -133,6 +133,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub /** * Initialize a {@link WebSocketHttpRequestHandler} that wraps this instance * and also inserts a {@link HandshakeInterceptor} for context propagation. + * @param handshakeHandler the handler for WebSocket handshake * @since 1.1.0 */ public WebSocketHttpRequestHandler initWebSocketHttpRequestHandler(HandshakeHandler handshakeHandler) { @@ -145,9 +146,10 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub * Return a {@link WebSocketHttpRequestHandler} that uses this instance as * its {@link WebGraphQlHandler} and adds a {@link HandshakeInterceptor} to * propagate context. + * @param handshakeHandler the handler for WebSocket handshake * @deprecated as of 1.1.0 in favor of {@link #initWebSocketHttpRequestHandler(HandshakeHandler)} */ - @Deprecated + @Deprecated(since = "1.1.0", forRemoval = true) public WebSocketHttpRequestHandler asWebSocketHttpRequestHandler(HandshakeHandler handshakeHandler) { return initWebSocketHttpRequestHandler(handshakeHandler); } @@ -240,7 +242,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub this.webSocketGraphQlInterceptor.handleConnectionInitialization(state.getSessionInfo(), payload) .defaultIfEmpty(Collections.emptyMap()) .publishOn(state.getScheduler()) // Serial blocking send via single thread - .doOnNext(ackPayload -> { + .doOnNext((ackPayload) -> { TextMessage outputMessage = encode(GraphQlWebSocketMessage.connectionAck(ackPayload)); try { session.sendMessage(outputMessage); @@ -249,7 +251,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub throw new IllegalStateException(ex); } }) - .onErrorResume(ex -> { + .onErrorResume((ex) -> { GraphQlStatus.closeSession(session, GraphQlStatus.UNAUTHORIZED_STATUS); return Mono.empty(); }) @@ -296,7 +298,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } return responseFlux - .map(responseMap -> encode(GraphQlWebSocketMessage.next(id, responseMap))) + .map((responseMap) -> encode(GraphQlWebSocketMessage.next(id, responseMap))) .concatWith(Mono.fromCallable(() -> encode(GraphQlWebSocketMessage.complete(id)))) .onErrorResume((ex) -> { if (ex instanceof SubscriptionExistsException) { @@ -345,7 +347,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub * {@code HandshakeInterceptor} that propagates ThreadLocal context through * the attributes map in {@code WebSocketSession}. */ - private static class ContextHandshakeInterceptor implements HandshakeInterceptor { + private static final class ContextHandshakeInterceptor implements HandshakeInterceptor { private static final String KEY = ContextSnapshot.class.getName(); @@ -365,7 +367,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub @Nullable Exception exception) { } - public static AutoCloseable setThreadLocals(WebSocketSession session) { + static AutoCloseable setThreadLocals(WebSocketSession session) { ContextSnapshot snapshot = (ContextSnapshot) session.getAttributes().get(KEY); Assert.notNull(snapshot, "Expected ContextSnapshot in WebSocketSession attributes"); return snapshot.setThreadLocals(); @@ -373,7 +375,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } - private static class GraphQlStatus { + private static final class GraphQlStatus { private static final CloseStatus INVALID_MESSAGE_STATUS = new CloseStatus(4400, "Invalid message"); @@ -414,7 +416,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } - private static class HttpOutputMessageAdapter extends ByteArrayOutputStream implements HttpOutputMessage { + private static final class HttpOutputMessageAdapter extends ByteArrayOutputStream implements HttpOutputMessage { private static final HttpHeaders noOpHeaders = new HttpHeaders(); @@ -445,7 +447,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub this.scheduler = Schedulers.newSingle("GraphQL-WsSession-" + graphQlSessionId); } - public WebSocketSessionInfo getSessionInfo() { + WebSocketSessionInfo getSessionInfo() { return this.sessionInfo; } @@ -483,7 +485,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } - private static class WebMvcSessionInfo implements WebSocketSessionInfo { + private static final class WebMvcSessionInfo implements WebSocketSessionInfo { private final WebSocketSession session; @@ -567,7 +569,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } @SuppressWarnings("serial") - private static class SubscriptionExistsException extends RuntimeException { + private static final class SubscriptionExistsException extends RuntimeException { } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphiQlHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphiQlHandler.java index fd03317c..d1db0914 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphiQlHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphiQlHandler.java @@ -70,6 +70,7 @@ public class GraphiQlHandler { /** * Render the GraphiQL page as "text/html", or if the "path" query parameter * is missing, add it and redirect back to the same URL. + * @param request the HTTP server request */ public ServerResponse handleRequest(ServerRequest request) { return (request.param("path").isPresent() ? diff --git a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/SchemaHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/SchemaHandler.java index a0954757..66800bcf 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/SchemaHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/SchemaHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server.webmvc; import graphql.schema.idl.SchemaPrinter; @@ -27,6 +28,7 @@ import org.springframework.web.servlet.function.ServerResponse; * {@link graphql.schema.GraphQLSchema} printed via {@link SchemaPrinter}. * * @author Rossen Stoyanchev + * @since 1.0.0 */ public class SchemaHandler { @@ -43,7 +45,7 @@ public class SchemaHandler { public ServerResponse handleRequest(ServerRequest request) { return ServerResponse.ok() .contentType(MediaType.TEXT_PLAIN) - .body(this.printer.print(graphQlSource.schema())); + .body(this.printer.print(this.graphQlSource.schema())); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java index 92a4de0f..47d55c1c 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java @@ -126,7 +126,7 @@ public abstract class AbstractGraphQlResponse implements GraphQlResponse { else { Assert.isTrue(value instanceof List, () -> "Invalid path " + path + ", data: " + response.getData()); int index = (int) segment; - value = (index < ((List) value).size() ? ((List) value).get(index) : null); + value = (index < ((List) value).size()) ? ((List) value).get(index) : null; } } return value; @@ -142,7 +142,7 @@ public abstract class AbstractGraphQlResponse implements GraphQlResponse { return Collections.emptyList(); } return response.getErrors().stream() - .filter(error -> { + .filter((error) -> { String errorPath = error.getPath(); return (!errorPath.isEmpty() && (errorPath.startsWith(path) || path.startsWith(errorPath))); }) @@ -160,7 +160,7 @@ public abstract class AbstractGraphQlResponse implements GraphQlResponse { return this.parsedPath; } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") @Override public boolean hasValue() { return (this.value != null); @@ -172,7 +172,7 @@ public abstract class AbstractGraphQlResponse implements GraphQlResponse { return (T) this.value; } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") @Override public ResponseError getError() { if (getValue() != null) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/CachingDocumentSource.java b/spring-graphql/src/main/java/org/springframework/graphql/support/CachingDocumentSource.java index 73cf5260..9b6b7e24 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/CachingDocumentSource.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/CachingDocumentSource.java @@ -39,6 +39,7 @@ public class CachingDocumentSource implements DocumentSource { /** * Constructor with the {@code DocumentSource} to actually load documents. + * @param delegate the delegate document source */ public CachingDocumentSource(DocumentSource delegate) { this.delegate = delegate; @@ -61,14 +62,14 @@ public class CachingDocumentSource implements DocumentSource { * Whether {@link #setCacheEnabled(boolean) caching} is enabled. */ public boolean isCacheEnabled() { - return cacheEnabled; + return this.cacheEnabled; } @Override public Mono getDocument(String name) { - return (isCacheEnabled() ? - this.documentCache.computeIfAbsent(name, k -> this.delegate.getDocument(name).cache()) : + return ((isCacheEnabled()) ? + this.documentCache.computeIfAbsent(name, (k) -> this.delegate.getDocument(name).cache()) : this.delegate.getDocument(name)); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlRequest.java index 2f0a6c0d..d05171fc 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlRequest.java @@ -111,13 +111,13 @@ public class DefaultExecutionGraphQlRequest extends DefaultGraphQlRequest implem .variables(getVariables()) .extensions(getExtensions()) .locale(this.locale) - .executionId(this.executionId != null ? this.executionId : ExecutionId.from(this.id)); + .executionId((this.executionId != null) ? this.executionId : ExecutionId.from(this.id)); ExecutionInput executionInput = inputBuilder.build(); for (BiFunction configurer : this.executionInputConfigurers) { ExecutionInput current = executionInput; - executionInput = executionInput.transform(builder -> configurer.apply(current, builder)); + executionInput = executionInput.transform((builder) -> configurer.apply(current, builder)); } return executionInput; @@ -125,7 +125,7 @@ public class DefaultExecutionGraphQlRequest extends DefaultGraphQlRequest implem @Override public String toString() { - return super.toString() + ", id=" + getId() + (getLocale() != null ? ", Locale=" + getLocale() : ""); + return super.toString() + ", id=" + getId() + ((getLocale() != null) ? ", Locale=" + getLocale() : ""); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java index addb7909..341956f1 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlResponse.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.support; import java.util.Collections; @@ -50,6 +51,8 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp /** * Constructor to create initial instance. + * @param input the execution input for this graphql operation + * @param result the execution result for this graphql operation */ public DefaultExecutionGraphQlResponse(ExecutionInput input, ExecutionResult result) { Assert.notNull(input, "ExecutionInput is required"); @@ -60,6 +63,7 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp /** * Constructor to re-wrap from transport specific subclass. + * @param response the execution response */ protected DefaultExecutionGraphQlResponse(ExecutionGraphQlResponse response) { this(response.getExecutionInput(), response.getExecutionResult()); @@ -94,7 +98,7 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp @Override public Map getExtensions() { - return (this.result.getExtensions() != null ? this.result.getExtensions() : Collections.emptyMap()); + return (this.result.getExtensions() != null) ? this.result.getExtensions() : Collections.emptyMap(); } @Override @@ -132,18 +136,18 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp public String getPath() { return getParsedPath().stream() .reduce("", - (s, o) -> s + (o instanceof Integer ? "[" + o + "]" : (s.isEmpty() ? o : "." + o)), + (s, o) -> s + ((o instanceof Integer) ? "[" + o + "]" : ((s.isEmpty()) ? o : "." + o)), (s, s2) -> null); } @Override public List getParsedPath() { - return (this.delegate.getPath() != null ? this.delegate.getPath() : Collections.emptyList()); + return (this.delegate.getPath() != null) ? this.delegate.getPath() : Collections.emptyList(); } @Override public Map getExtensions() { - return (this.delegate.getExtensions() != null ? this.delegate.getExtensions() : Collections.emptyMap()); + return (this.delegate.getExtensions() != null) ? this.delegate.getExtensions() : Collections.emptyMap(); } @Override @@ -156,8 +160,10 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp /** * Builder to transform the response's {@link ExecutionResult}. + * @param the builder type + * @param the response type */ - public static abstract class Builder, R extends ExecutionGraphQlResponse> { + public abstract static class Builder, R extends ExecutionGraphQlResponse> { private final R original; @@ -209,6 +215,8 @@ public class DefaultExecutionGraphQlResponse extends AbstractGraphQlResponse imp /** * Subclasses to create the specific response instance. + * @param original the original response instance + * @param newResult the new execution result for this response */ protected abstract R build(R original, ExecutionResult newResult); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultGraphQlRequest.java b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultGraphQlRequest.java index 9d238616..e118463a 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultGraphQlRequest.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/DefaultGraphQlRequest.java @@ -76,8 +76,8 @@ public class DefaultGraphQlRequest implements GraphQlRequest { Assert.notNull(document, "'document' is required"); this.document = document; this.operationName = operationName; - this.variables = (variables != null ? variables : Collections.emptyMap()); - this.extensions = (extensions != null ? extensions : Collections.emptyMap()); + this.variables = (variables != null) ? variables : Collections.emptyMap(); + this.extensions = (extensions != null) ? extensions : Collections.emptyMap(); } @@ -121,7 +121,7 @@ public class DefaultGraphQlRequest implements GraphQlRequest { @Override public boolean equals(Object o) { - if (! (o instanceof DefaultGraphQlRequest)) { + if (!(o instanceof DefaultGraphQlRequest)) { return false; } DefaultGraphQlRequest other = (DefaultGraphQlRequest) o; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/DocumentSource.java b/spring-graphql/src/main/java/org/springframework/graphql/support/DocumentSource.java index a4e203dc..ef9cafd5 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/DocumentSource.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/DocumentSource.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.support; import reactor.core.publisher.Mono; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java b/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java index 72bd93b7..c86ea59d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/ResourceDocumentSource.java @@ -63,6 +63,8 @@ public class ResourceDocumentSource implements DocumentSource { /** * Constructor with given locations and extensions. + * @param locations the resource locations + * @param extensions the file extensions for document sources */ public ResourceDocumentSource(List locations, List extensions) { this.locations = Collections.unmodifiableList(new ArrayList<>(locations)); @@ -90,7 +92,7 @@ public class ResourceDocumentSource implements DocumentSource { @Override public Mono getDocument(String name) { return Flux.fromIterable(this.locations) - .flatMapIterable(location -> getCandidateResources(name, location)) + .flatMapIterable((location) -> getCandidateResources(name, location)) .filter(Resource::exists) .next() .map(this::resourceToString) @@ -104,7 +106,7 @@ public class ResourceDocumentSource implements DocumentSource { private List getCandidateResources(String name, Resource location) { return this.extensions.stream() - .map(ext -> { + .map((ext) -> { try { return location.createRelative(name + ext); } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/Author.java b/spring-graphql/src/test/java/org/springframework/graphql/Author.java index 21b0745b..41250fcd 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/Author.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/Author.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; public class Author { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/BookCriteria.java b/spring-graphql/src/test/java/org/springframework/graphql/BookCriteria.java index 2390bb8a..826d9d23 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/BookCriteria.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/BookCriteria.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; public class BookCriteria { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/BookSource.java b/spring-graphql/src/test/java/org/springframework/graphql/BookSource.java index 21cf53e5..5fba423b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/BookSource.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/BookSource.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; import java.util.ArrayList; @@ -35,7 +36,6 @@ public class BookSource { public static final Resource paginationSchema = new ClassPathResource("books/pagination-schema.graphqls"); - private static final Map booksMap = new HashMap<>(); private static final Map booksWithoutAuthorsMap; @@ -63,6 +63,10 @@ public class BookSource { .collect(Collectors.toMap(Book::getId, Function.identity())); } + private BookSource() { + + } + public static List books() { return new ArrayList<>(booksMap.values()); @@ -95,22 +99,22 @@ public class BookSource { public static String booksConnectionQuery(@Nullable String arguments) { arguments = StringUtils.hasText(arguments) ? "(" + arguments + ")" : ""; return "{" + - " books" + arguments + " {" + - " edges {" + - " cursor," + - " node {" + - " id" + - " name" + - " }" + - " }" + - " pageInfo {" + - " startCursor," + - " endCursor," + - " hasPreviousPage," + - " hasNextPage" + - " }" + - " }" + - "}"; + " books" + arguments + " {" + + " edges {" + + " cursor," + + " node {" + + " id" + + " name" + + " }" + + " }" + + " pageInfo {" + + " startCursor," + + " endCursor," + + " hasPreviousPage," + + " hasNextPage" + + " }" + + " }" + + "}"; } } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/DefaultExecutionGraphQlRequestTests.java b/spring-graphql/src/test/java/org/springframework/graphql/DefaultExecutionGraphQlRequestTests.java index a8aa1891..5c020e4c 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/DefaultExecutionGraphQlRequestTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/DefaultExecutionGraphQlRequestTests.java @@ -53,4 +53,4 @@ class DefaultExecutionGraphQlRequestTests { assertThat(this.request.getLocale()).isEqualTo(Locale.getDefault()); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/ResponseHelper.java b/spring-graphql/src/test/java/org/springframework/graphql/ResponseHelper.java index eed31b01..0d3fe91b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/ResponseHelper.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/ResponseHelper.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; import java.lang.reflect.Type; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java index c39be5a3..52003fe2 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/DefaultGraphQlClientResponseTests.java @@ -16,7 +16,6 @@ package org.springframework.graphql.client; -import graphql.language.SourceLocation; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -26,6 +25,7 @@ import java.util.Map; import graphql.GraphQLError; import graphql.GraphqlErrorBuilder; import graphql.execution.ResultPath; +import graphql.language.SourceLocation; import org.junit.jupiter.api.Test; import org.testcontainers.shaded.com.fasterxml.jackson.databind.DeserializationFeature; import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java index 2ffe80ad..deeb86da 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.client; import java.util.ArrayList; @@ -84,7 +85,7 @@ public class GraphQlClientTests extends GraphQlClientTestSupport { getGraphQlService().setDataAsJson(document, "{\"me\": {\"name\":\"Luke Skywalker\"}}"); Map map = graphQlClient().document(document) - .retrieve("").toEntity(new ParameterizedTypeReference>() {}) + .retrieve("").toEntity(new ParameterizedTypeReference>() { }) .block(TIMEOUT); assertThat(map).containsEntry("me", MovieCharacter.create("Luke Skywalker")); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/MockGraphQlWebSocketServer.java b/spring-graphql/src/test/java/org/springframework/graphql/client/MockGraphQlWebSocketServer.java index 26b8159c..341b1926 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/MockGraphQlWebSocketServer.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/MockGraphQlWebSocketServer.java @@ -46,7 +46,7 @@ import org.springframework.web.reactive.socket.WebSocketSession; */ public final class MockGraphQlWebSocketServer implements WebSocketHandler { - private final static Log logger = LogFactory.getLog(MockGraphQlWebSocketServer.class); + private static final Log logger = LogFactory.getLog(MockGraphQlWebSocketServer.class); @Nullable diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/WebSocketGraphQlTransportTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/WebSocketGraphQlTransportTests.java index 2b99674f..a28e5f90 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/WebSocketGraphQlTransportTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/WebSocketGraphQlTransportTests.java @@ -34,9 +34,9 @@ import reactor.test.StepVerifier; import org.springframework.graphql.GraphQlRequest; import org.springframework.graphql.GraphQlResponse; import org.springframework.graphql.ResponseError; -import org.springframework.graphql.support.DefaultGraphQlRequest; import org.springframework.graphql.server.support.GraphQlWebSocketMessage; import org.springframework.graphql.server.support.GraphQlWebSocketMessageType; +import org.springframework.graphql.support.DefaultGraphQlRequest; import org.springframework.http.HttpHeaders; import org.springframework.http.codec.ClientCodecConfigurer; import org.springframework.web.reactive.socket.CloseStatus; @@ -46,8 +46,8 @@ import org.springframework.web.reactive.socket.client.WebSocketClient; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Tests for {@link WebSocketGraphQlTransport} using {@link TestWebSocketClient} @@ -57,7 +57,7 @@ import static org.mockito.Mockito.when; */ public class WebSocketGraphQlTransportTests { - private final static Duration TIMEOUT = Duration.ofSeconds(5); + private static final Duration TIMEOUT = Duration.ofSeconds(5); private static final CodecDelegate CODEC_DELEGATE = new CodecDelegate(ClientCodecConfigurer.create()); @@ -65,7 +65,7 @@ public class WebSocketGraphQlTransportTests { private final MockGraphQlWebSocketServer mockServer = new MockGraphQlWebSocketServer(); private final TestWebSocketClient webSocketClient = new TestWebSocketClient(this.mockServer); - + private final WebSocketGraphQlTransport transport = createTransport(this.webSocketClient); private final GraphQlResponse response1 = new ResponseMapGraphQlResponse( @@ -283,8 +283,8 @@ public class WebSocketGraphQlTransportTests { IOException ex = new IOException("Connect failure"); WebSocketClient client = mock(WebSocketClient.class); - when(client.execute(any(URI.class), any(HttpHeaders.class), any(WebSocketHandler.class))) - .thenReturn(Mono.error(ex)); + given(client.execute(any(URI.class), any(HttpHeaders.class), any(WebSocketHandler.class))) + .willReturn(Mono.error(ex)); StepVerifier.create(createTransport(client).start()) .expectErrorMessage(ex.getMessage()) @@ -324,7 +324,7 @@ public class WebSocketGraphQlTransportTests { private static WebSocketGraphQlTransport createTransport(WebSocketClient client) { return new WebSocketGraphQlTransport( URI.create("/"), HttpHeaders.EMPTY, client, ClientCodecConfigurer.create(), - new WebSocketGraphQlClientInterceptor() {}); + new WebSocketGraphQlClientInterceptor() { }); } private void assertActualClientMessages(GraphQlWebSocketMessage... expectedMessages) { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java index 74bb3841..680802e6 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/GraphQlArgumentBinderTests.java @@ -662,8 +662,12 @@ class GraphQlArgumentBinderTests { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Item item = (Item) o; return name.equals(item.name); } @@ -709,4 +713,4 @@ class GraphQlArgumentBinderTests { record ConstructorEnumInput>(List enums) { } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurerTests.java index f215e668..ccd9db81 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerConfigurerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.List; @@ -47,9 +48,9 @@ public class AnnotatedControllerConfigurerTests { List resolvers = configurer.getArgumentResolvers().getResolvers(); int size = resolvers.size(); - assertThat(resolvers).element(size -1).isInstanceOf(SourceMethodArgumentResolver.class); - assertThat(resolvers).element(size -2).isSameAs(customResolver2); - assertThat(resolvers).element(size -3).isSameAs(customResolver1); + assertThat(resolvers).element(size - 1).isInstanceOf(SourceMethodArgumentResolver.class); + assertThat(resolvers).element(size - 2).isSameAs(customResolver2); + assertThat(resolvers).element(size - 3).isSameAs(customResolver1); } @Test diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolverTests.java index 76160f3d..c0845378 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerExceptionResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.Arrays; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolverTests.java index 10483d77..1293fcab 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentMethodArgumentResolverTests.java @@ -216,4 +216,4 @@ class ArgumentMethodArgumentResolverTests extends ArgumentResolverTestSupport { } } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentResolverTestSupport.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentResolverTestSupport.java index 61328865..05ac73d9 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentResolverTestSupport.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentResolverTestSupport.java @@ -32,14 +32,14 @@ import org.springframework.core.annotation.SynthesizingMethodParameter; import org.springframework.util.ClassUtils; /** - * Base class to test resolving {@link @Argument} and {@link @Arguments} + * Base class to test resolving {@code @Argument} and {@code @Arguments} * annotated method parameters. * * @author Rossen Stoyanchev */ class ArgumentResolverTestSupport { - private static final TypeReference> MAP_TYPE_REFERENCE = new TypeReference<>() {}; + private static final TypeReference> MAP_TYPE_REFERENCE = new TypeReference<>() { }; private final ObjectMapper mapper = new ObjectMapper(); @@ -61,4 +61,4 @@ class ArgumentResolverTestSupport { return DataFetchingEnvironmentImpl.newDataFetchingEnvironment().arguments(arguments).build(); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolverTests.java index a231425d..66ef2ed2 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ArgumentsMethodArgumentResolverTests.java @@ -130,4 +130,4 @@ class ArgumentsMethodArgumentResolverTests extends ArgumentResolverTestSupport { } } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolverTests.java index ce8fd0ba..0aac0ad8 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/AuthenticationPrincipalArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.annotation.Retention; @@ -56,20 +57,20 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; */ class AuthenticationPrincipalArgumentResolverTests { - private final static Class STRING_CLASS = String.class; + private static final Class STRING_CLASS = String.class; - private final static Class USER_DETAILS_CLASS = UserDetails.class; + private static final Class USER_DETAILS_CLASS = UserDetails.class; - private final static Class MONO_USER_DETAILS_CLASS = + private static final Class MONO_USER_DETAILS_CLASS = ResolvableType.forClassWithGenerics(Mono.class, UserDetails.class).getRawClass(); - private final static Class MONO_STRING_CLASS = + private static final Class MONO_STRING_CLASS = ResolvableType.forClassWithGenerics(Mono.class, String.class).getRawClass(); - private final static Class PUBLISHER_USER_DETAILS_CLASS = + private static final Class PUBLISHER_USER_DETAILS_CLASS = ResolvableType.forClassWithGenerics(Publisher.class, UserDetails.class).getRawClass(); - private final static Class TESTPUBLISHER_USER_DETAILS_CLASS = + private static final Class TESTPUBLISHER_USER_DETAILS_CLASS = ResolvableType.forClassWithGenerics(TestPublisher.class, UserDetails.class).getRawClass(); @@ -82,7 +83,6 @@ class AuthenticationPrincipalArgumentResolverTests { SecurityContextHolder.clearContext(); } - @Test void supportsParameterWhenNoAnnotation() { MethodParameter parameter = firstParameter(UserController.class, "noParameter", USER_DETAILS_CLASS); @@ -417,4 +417,4 @@ class AuthenticationPrincipalArgumentResolverTests { public @interface CurrentUser { } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java index 93e3f4da..abb925d7 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingDetectionTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.ArrayList; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java index 2fbaa344..45282685 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingInvocationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java index fa6dd7c2..cf47ded8 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingPrincipalMethodArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.security.Principal; @@ -33,7 +34,6 @@ import reactor.util.context.Context; import org.springframework.graphql.ExecutionGraphQlResponse; import org.springframework.graphql.ResponseHelper; -import org.springframework.graphql.TestExecutionRequest; import org.springframework.graphql.data.method.annotation.BatchMapping; import org.springframework.lang.Nullable; import org.springframework.security.authentication.TestingAuthenticationToken; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingTestSupport.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingTestSupport.java index 9506ad3a..38e02c2b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingTestSupport.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/BatchMappingTestSupport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.ArrayList; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolverTests.java index c56efcd0..4426245b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ContextValueMethodArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethodTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethodTests.java index d4e06b7d..7a78bf85 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethodTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetcherHandlerMethodTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentArgumentResolverTests.java index 17117b7c..c4dc8d6b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataFetchingEnvironmentArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java index 0a90c8c4..c0a0d74f 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/DataLoaderArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolverTests.java index eca93e3f..8b2a3298 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/LocalContextValueMethodArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolverTests.java index 1554509f..f375808b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/ProjectedPayloadMethodArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessorTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessorTests.java index 0bff594c..198619a7 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessorTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingBeanFactoryInitializationAotProcessorTests.java @@ -37,9 +37,6 @@ import graphql.schema.DataFetchingFieldSelectionSet; import org.dataloader.DataLoader; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.graphql.data.method.annotation.*; -import org.springframework.validation.BindException; -import org.springframework.web.bind.annotation.ControllerAdvice; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -62,7 +59,17 @@ import org.springframework.data.web.ProjectedPayload; import org.springframework.graphql.Author; import org.springframework.graphql.Book; import org.springframework.graphql.data.ArgumentValue; +import org.springframework.graphql.data.method.annotation.Argument; +import org.springframework.graphql.data.method.annotation.BatchMapping; +import org.springframework.graphql.data.method.annotation.ContextValue; +import org.springframework.graphql.data.method.annotation.GraphQlExceptionHandler; +import org.springframework.graphql.data.method.annotation.LocalContextValue; +import org.springframework.graphql.data.method.annotation.MutationMapping; +import org.springframework.graphql.data.method.annotation.QueryMapping; +import org.springframework.graphql.data.method.annotation.SchemaMapping; import org.springframework.stereotype.Controller; +import org.springframework.validation.BindException; +import org.springframework.web.bind.annotation.ControllerAdvice; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -502,7 +509,7 @@ class SchemaMappingBeanFactoryInitializationAotProcessorTests { } } } - catch (IntrospectionException e) { + catch (IntrospectionException ex) { // ignoring type } return predicate; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingDetectionTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingDetectionTests.java index 50f3df1e..a7f68427 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingDetectionTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingDetectionTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.Map; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java index 8ec4b3a9..9f5116fe 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingInvocationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.Collections; @@ -285,7 +286,7 @@ public class SchemaMappingInvocationTests { private TestExecutionGraphQlService graphQlService() { - return graphQlService((configurer, setup) -> {}); + return graphQlService((configurer, setup) -> { }); } private TestExecutionGraphQlService graphQlService(BiConsumer consumer) { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java index 07581069..de8fd528 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPaginationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java index 3104e78f..49e4e949 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/method/annotation/support/SchemaMappingPrincipalMethodArgumentResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.method.annotation.support; import java.lang.reflect.Method; @@ -26,8 +27,6 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.graphql.execution.DataFetcherExceptionResolver; -import org.springframework.graphql.execution.ErrorType; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -41,6 +40,8 @@ import org.springframework.graphql.ResponseHelper; import org.springframework.graphql.TestExecutionGraphQlService; import org.springframework.graphql.data.method.annotation.QueryMapping; import org.springframework.graphql.data.method.annotation.SubscriptionMapping; +import org.springframework.graphql.execution.DataFetcherExceptionResolver; +import org.springframework.graphql.execution.ErrorType; import org.springframework.lang.Nullable; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.Authentication; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/Book.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/Book.java index 3a7c1c15..378ff5ff 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/Book.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/Book.java @@ -21,7 +21,8 @@ import org.springframework.graphql.Author; public class Book { - @Id Long id; + @Id + Long id; String name; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/QBook.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/QBook.java index 84248332..1f6bbbbc 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/QBook.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/QBook.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,21 +27,21 @@ import com.querydsl.core.types.dsl.StringPath; * Generated by Querydsl. */ public class QBook extends EntityPathBase { - private static final long serialVersionUID = 1773522017L; - public static final QBook book = new QBook("book"); - public final StringPath author = this.createString("author"); - public final NumberPath id = this.createNumber("id", Long.class); - public final StringPath name = this.createString("name"); + private static final long serialVersionUID = 1773522017L; + public static final QBook book = new QBook("book"); + public final StringPath author = this.createString("author"); + public final NumberPath id = this.createNumber("id", Long.class); + public final StringPath name = this.createString("name"); - public QBook(String variable) { - super(Book.class, PathMetadataFactory.forVariable(variable)); - } + public QBook(String variable) { + super(Book.class, PathMetadataFactory.forVariable(variable)); + } - public QBook(Path path) { - super(path.getType(), path.getMetadata()); - } + public QBook(Path path) { + super(path.getType(), path.getMetadata()); + } - public QBook(PathMetadata metadata) { - super(Book.class, metadata); - } + public QBook(PathMetadata metadata) { + super(Book.class, metadata); + } } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/QuerydslDataFetcherTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/QuerydslDataFetcherTests.java index 0eb54c67..ea8179a2 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/QuerydslDataFetcherTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/QuerydslDataFetcherTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -60,10 +60,10 @@ import org.springframework.http.HttpHeaders; import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; /** * Unit tests for {@link QuerydslDataFetcher}. @@ -229,7 +229,7 @@ class QuerydslDataFetcherTests { void shouldFavorExplicitWiring() { MockRepository mockRepository = mock(MockRepository.class); Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams")); - when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book)); + given(mockRepository.findBy(any(), any())).willReturn(Optional.of(book)); // 1) Automatic registration only WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler(); @@ -286,7 +286,7 @@ class QuerydslDataFetcherTests { void shouldReactivelyFetchSingleItems() { ReactiveMockRepository mockRepository = mock(ReactiveMockRepository.class); Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams")); - when(mockRepository.findBy(any(), any())).thenReturn(Mono.just(book)); + given(mockRepository.findBy(any(), any())).willReturn(Mono.just(book)); Consumer tester = setup -> { WebGraphQlRequest request = request("{ bookById(id: 1) {name}}"); @@ -308,7 +308,7 @@ class QuerydslDataFetcherTests { ReactiveMockRepository mockRepository = mock(ReactiveMockRepository.class); Book book1 = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams")); Book book2 = new Book(53L, "Breaking Bad", new Author(0L, "", "Heisenberg")); - when(mockRepository.findBy(any(), any())).thenReturn(Flux.just(book1, book2)); + given(mockRepository.findBy(any(), any())).willReturn(Flux.just(book1, book2)); Consumer tester = setup -> { WebGraphQlRequest request = request("{ books {name}}"); @@ -400,7 +400,7 @@ class QuerydslDataFetcherTests { QuerydslBinderCustomizer { @Override - default void customize(QuerydslBindings bindings, QBook book){ + default void customize(QuerydslBindings bindings, QBook book) { bindings.bind(book.name).firstOptional((path, value) -> value.map(path::startsWith)); } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/Author.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/Author.java index 38c338fa..2854c04b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/Author.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/Author.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.query.jpa; import jakarta.persistence.Entity; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/ProjectingBookJpaRepository.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/ProjectingBookJpaRepository.java index 598935b2..e3c43f33 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/ProjectingBookJpaRepository.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/ProjectingBookJpaRepository.java @@ -20,13 +20,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.graphql.data.GraphQlRepository; import org.springframework.graphql.data.query.QueryByExampleDataFetcher.Builder; import org.springframework.graphql.data.query.QueryByExampleDataFetcher.QueryByExampleBuilderCustomizer; -import org.springframework.graphql.data.query.jpa.QueryByExampleDataFetcherJpaTests.BookDto; @GraphQlRepository public interface ProjectingBookJpaRepository extends JpaRepository, QueryByExampleBuilderCustomizer { @Override - default Builder customize(Builder builder){ + default Builder customize(Builder builder) { return builder.projectAs(BookProjection.class); } } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java index 796677f2..723eaa14 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -62,8 +62,8 @@ import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Integration tests for {@link QueryByExampleDataFetcher} with JPA repository. @@ -171,7 +171,7 @@ class QueryByExampleDataFetcherJpaTests { void shouldFavorExplicitWiring() { BookJpaRepository mockRepository = mock(BookJpaRepository.class); Book book = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams")); - when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book)); + given(mockRepository.findBy(any(), any())).willReturn(Optional.of(book)); // 1) Automatic registration only WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/Author.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/Author.java index afa15c16..e6612e1f 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/Author.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/Author.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.data.query.mongo; import org.springframework.data.annotation.Id; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java index b4b21c9d..1fc64ae5 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -59,9 +59,9 @@ import org.springframework.lang.Nullable; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Integration tests for {@link QueryByExampleDataFetcher} with MongoDB repository. @@ -168,7 +168,7 @@ class QueryByExampleDataFetcherMongoDbTests { void shouldFavorExplicitWiring() { BookMongoRepository mockRepository = mock(BookMongoRepository.class); Book book = new Book("42", "Hitchhiker's Guide to the Galaxy", new Author("0", "Douglas", "Adams")); - when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book)); + given(mockRepository.findBy(any(), any())).willReturn(Optional.of(book)); // 1) Automatic registration only WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java index 312d8c26..ac42113a 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/Author.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/Author.java index 201a7646..a2c192fd 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/Author.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/Author.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookNeo4jRepository.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookNeo4jRepository.java index f2658cba..52886fcd 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookNeo4jRepository.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookNeo4jRepository.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookReactiveNeo4jRepository.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookReactiveNeo4jRepository.java index 090803bc..13baea16 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookReactiveNeo4jRepository.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/BookReactiveNeo4jRepository.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherNeo4jTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherNeo4jTests.java index 40dc3722..359f6cf8 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherNeo4jTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherNeo4jTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -61,9 +61,9 @@ import org.springframework.lang.Nullable; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Integration tests for {@link QueryByExampleDataFetcher} with Neo4j repository. @@ -170,7 +170,7 @@ class QueryByExampleDataFetcherNeo4jTests { void shouldFavorExplicitWiring() { BookNeo4jRepository mockRepository = mock(BookNeo4jRepository.class); Book book = new Book("42", "Hitchhiker's Guide to the Galaxy", new Author("0", "Douglas", "Adams")); - when(mockRepository.findBy(any(), any())).thenReturn(Optional.of(book)); + given(mockRepository.findBy(any(), any())).willReturn(Optional.of(book)); // 1) Automatic registration only WebGraphQlHandler handler = graphQlSetup(mockRepository).toWebGraphQlHandler(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherReactiveNeo4jDbTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherReactiveNeo4jDbTests.java index 5c2f6957..4a562ecb 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherReactiveNeo4jDbTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/neo4j/QueryByExampleDataFetcherReactiveNeo4jDbTests.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java index fd0f6b9e..47eca06f 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/BatchLoadingTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/ClassNameTypeResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/ClassNameTypeResolverTests.java index c2d2f5b8..a45df168 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/ClassNameTypeResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/ClassNameTypeResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.Arrays; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java index 17f232ab..2181a47f 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/CompositeSubscriptionExceptionResolverTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.time.Duration; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurerTests.java index 0473ba87..c1ac2c45 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/ConnectionTypeDefinitionConfigurerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java index 08e2d414..bc2b0011 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistryTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.Map; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilderTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilderTests.java index 58339a52..a1204b27 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilderTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/DefaultSchemaResourceGraphQlSourceBuilderTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.execution; import java.util.List; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java index d9590881..0c086e54 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/ExceptionResolversExceptionHandlerTests.java @@ -26,7 +26,6 @@ import io.micrometer.context.ContextRegistry; import io.micrometer.context.ContextSnapshot; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; -import reactor.util.context.Context; import org.springframework.graphql.GraphQlSetup; import org.springframework.graphql.ResponseHelper; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/execution/SchemaMappingInspectorTests.java b/spring-graphql/src/test/java/org/springframework/graphql/execution/SchemaMappingInspectorTests.java index da89da64..35a02eb0 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/execution/SchemaMappingInspectorTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/execution/SchemaMappingInspectorTests.java @@ -91,12 +91,11 @@ class SchemaMappingInspectorTests { type Query { allBooks: [Book] } - type Book { id: ID name: String missing: Boolean - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Book", "missing"); @@ -108,7 +107,6 @@ class SchemaMappingInspectorTests { type Query { optionalBook: Book } - type Book { id: ID name: String @@ -125,27 +123,23 @@ class SchemaMappingInspectorTests { type Query { paginatedBooks: BookConnection } - type BookConnection { edges: [BookEdge]! pageInfo: PageInfo! } - type BookEdge { cursor: String! # ... } - type PageInfo { startCursor: String # ... } - type Book { id: ID name: String missing: Boolean - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Book", "missing"); @@ -157,8 +151,8 @@ class SchemaMappingInspectorTests { type Query { } extend type Query { - greeting: String - } + greeting: String + } """; SchemaReport report = inspectSchema(schema, EmptyController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Query", "greeting"); @@ -179,11 +173,10 @@ class SchemaMappingInspectorTests { type Mutation { createBook: Book } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Mutation", "createBook"); @@ -198,11 +191,10 @@ class SchemaMappingInspectorTests { type Mutation { createBook: Book } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class, BookController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(0); @@ -217,12 +209,12 @@ class SchemaMappingInspectorTests { type Mutation { } extend type Mutation { - createBook: Book - } - type Book { + createBook: Book + } + type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Mutation", "createBook"); @@ -243,11 +235,10 @@ class SchemaMappingInspectorTests { type Subscription { bookSearch(author: String) : [Book!]! } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Subscription", "bookSearch"); @@ -262,11 +253,10 @@ class SchemaMappingInspectorTests { type Subscription { bookSearch(author: String) : [Book!]! } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class, BookController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(0); @@ -281,12 +271,12 @@ class SchemaMappingInspectorTests { type Subscription { } extend type Subscription { - bookSearch(author: String) : [Book!]! - } - type Book { + bookSearch(author: String) : [Book!]! + } + type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, GreetingController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Subscription", "bookSearch"); @@ -304,11 +294,10 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(0); @@ -320,12 +309,11 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String fetcher: String - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(0); @@ -337,13 +325,11 @@ class SchemaMappingInspectorTests { type Query { books: [Book] } - type Book { id: ID name: String author: Author - } - + } type Author { id: ID firstName: String @@ -360,12 +346,11 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String missing: Boolean - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Book", "missing"); @@ -388,13 +373,11 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String author: Author - } - + } type Author { id: ID firstName: String @@ -411,13 +394,11 @@ class SchemaMappingInspectorTests { type Query { teamById(id: ID): Team } - type Team { name: String members: [TeamMember] - } - - type TeamMember { + } + type TeamMember { name: String team: Team missing: String @@ -433,14 +414,13 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String - } - extend type Book { + } + extend type Book { missing: Boolean - } + } """; SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(1).containsUnmappedFields("Book", "missing"); @@ -452,16 +432,13 @@ class SchemaMappingInspectorTests { type Query { fooBar: FooBar } - union FooBar = Foo | Bar - type Foo { name: String - } - + } type Bar { name: String - } + } """; SchemaReport report = inspectSchema(schema, UnionController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(1).containsSkippedTypes("FooBar"); @@ -473,16 +450,15 @@ class SchemaMappingInspectorTests { type Query { bookById(id: ID): Book } - type Book { id: ID name: String - } + } """; GraphQLSchema schema = SchemaGenerator.createdMockedSchema(schemaContent); RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring() - .type("Query", builder -> builder.dataFetcher("bookById", environment -> null)) + .type("Query", (builder) -> builder.dataFetcher("bookById", (environment) -> null)) .build(); SchemaReport report = SchemaMappingInspector.inspect(schema, wiring); @@ -495,11 +471,10 @@ class SchemaMappingInspectorTests { type Query { bookObject(id: ID): Book } - type Book { id: ID name: String - } + } """; SchemaReport report = inspectSchema(schemaContent, BookController.class); assertThatReport(report).hasUnmappedFieldCount(0).hasSkippedTypeCount(1).containsSkippedTypes("Book"); @@ -515,7 +490,7 @@ class SchemaMappingInspectorTests { GraphQLSchema schema = SchemaGenerator.createdMockedSchema(schemaContent); RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring() - .type("Query", builder -> builder.dataFetcher("greeting", environment -> null)) + .type("Query", (builder) -> builder.dataFetcher("greeting", (environment) -> null)) .build(); SchemaReport report = SchemaMappingInspector.inspect(schema, wiring); @@ -530,7 +505,7 @@ class SchemaMappingInspectorTests { @Test void reportUnmappedField() { - String schema = """ + String schema = """ type Query { allBooks: [Book] } @@ -545,19 +520,19 @@ class SchemaMappingInspectorTests { name: String missing: Boolean author: Author - } + } type Author { id: ID } """; - SchemaReport report = inspectSchema(schema, BookController.class); + SchemaReport report = inspectSchema(schema, BookController.class); assertThatReport(report).hasUnmappedFieldCount(1).hasSkippedTypeCount(0); - assertThat(report.toString()) - .contains("GraphQL schema inspection:", "Unmapped fields: {Book=[missing]}", "Unmapped registrations:", - "{Book.fetcher=BookController#fetcher[1 args]", " Query.paginatedBooks=BookController#paginatedBooks[0 args]", - "Query.bookObject=BookController#bookObject[1 args]", "Query.bookById=BookController#bookById[1 args]", - "Skipped types: []"); - } + assertThat(report.toString()) + .contains("GraphQL schema inspection:", "Unmapped fields: {Book=[missing]}", "Unmapped registrations:", + "{Book.fetcher=BookController#fetcher[1 args]", " Query.paginatedBooks=BookController#paginatedBooks[0 args]", + "Query.bookObject=BookController#bookObject[1 args]", "Query.bookById=BookController#bookById[1 args]", + "Skipped types: []"); + } } @@ -791,4 +766,4 @@ class SchemaMappingInspectorTests { } } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConventionTests.java b/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConventionTests.java index cdd3f735..6e0f7ca9 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConventionTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultDataFetcherObservationConventionTests.java @@ -100,4 +100,4 @@ class DefaultDataFetcherObservationConventionTests { consumer.accept(builder); return builder.build(); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultExecutionRequestObservationConventionTests.java b/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultExecutionRequestObservationConventionTests.java index d4eca661..e31d8e99 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultExecutionRequestObservationConventionTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/observation/DefaultExecutionRequestObservationConventionTests.java @@ -57,7 +57,7 @@ class DefaultExecutionRequestObservationConventionTests { void hasContextualName() { ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }") .operationName("mutation").build(); - ExecutionRequestObservationContext context = createObservationContext(input, builder -> {}); + ExecutionRequestObservationContext context = createObservationContext(input, builder -> { }); assertThat(this.convention.getContextualName(context)).isEqualTo("graphql mutation"); } @@ -106,4 +106,4 @@ class DefaultExecutionRequestObservationConventionTests { return context; } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/observation/GraphQlObservationInstrumentationTests.java b/spring-graphql/src/test/java/org/springframework/graphql/observation/GraphQlObservationInstrumentationTests.java index 8d6ad88a..767cd354 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/observation/GraphQlObservationInstrumentationTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/observation/GraphQlObservationInstrumentationTests.java @@ -16,6 +16,10 @@ package org.springframework.graphql.observation; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.stream.Stream; + import graphql.GraphQLContext; import graphql.GraphqlErrorBuilder; import graphql.execution.DataFetcherResult; @@ -31,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import reactor.core.publisher.Mono; import org.springframework.graphql.Author; import org.springframework.graphql.Book; @@ -42,11 +47,6 @@ import org.springframework.graphql.ResponseHelper; import org.springframework.graphql.TestExecutionRequest; import org.springframework.graphql.execution.DataFetcherExceptionResolver; import org.springframework.graphql.execution.ErrorType; -import reactor.core.publisher.Mono; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; @@ -294,7 +294,6 @@ class GraphQlObservationInstrumentationTests { @Test void shouldNotOverrideExistingLocalContext() { - String document = """ { bookById(id: 1) { @@ -317,7 +316,7 @@ class GraphQlObservationInstrumentationTests { return BookSource.getAuthor(101L).getFirstName(); }; - ExecutionGraphQlRequest request = TestExecutionRequest.forDocument(document); + ExecutionGraphQlRequest request = TestExecutionRequest.forDocument(document); Mono responseMono = graphQlSetup .queryFetcher("bookById", bookDataFetcher) .dataFetcher("Book", "author", authorDataFetcher) diff --git a/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphQlHttpHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphQlHttpHandlerTests.java index 8240a206..30d8cbf8 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphQlHttpHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphQlHttpHandlerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server.webflux; import java.util.Collections; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphiQlHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphiQlHandlerTests.java index 63b533dd..c571e016 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphiQlHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/server/webflux/GraphiQlHandlerTests.java @@ -142,4 +142,4 @@ class GraphiQlHandlerTests { } -} \ No newline at end of file +} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandlerTests.java index e98c4964..da8d7cf7 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlHttpHandlerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server.webmvc; import java.io.IOException; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphiQlHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphiQlHandlerTests.java index 6ea1e37e..7960846d 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphiQlHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphiQlHandlerTests.java @@ -25,7 +25,6 @@ import java.util.Map; import jakarta.servlet.ServletException; import jakarta.servlet.http.MappingMatch; - import org.junit.jupiter.api.Test; import org.springframework.core.io.ByteArrayResource; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/support/DefaultGraphQlRequestTests.java b/spring-graphql/src/test/java/org/springframework/graphql/support/DefaultGraphQlRequestTests.java index d922149a..5672a4dc 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/support/DefaultGraphQlRequestTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/support/DefaultGraphQlRequestTests.java @@ -52,4 +52,4 @@ class DefaultGraphQlRequestTests { .containsEntry("extensions", extensions); } -} \ No newline at end of file +} diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlServiceSetup.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlServiceSetup.java index 6081d94e..9183373b 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlServiceSetup.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlServiceSetup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; import org.springframework.graphql.execution.DataLoaderRegistrar; diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java index e6761c26..9d0c8928 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql; import java.nio.charset.StandardCharsets; @@ -54,7 +55,7 @@ import org.springframework.graphql.server.webflux.GraphQlHttpHandler; * @author Rossen Stoyanchev */ @SuppressWarnings("unused") -public class GraphQlSetup implements GraphQlServiceSetup { +public final class GraphQlSetup implements GraphQlServiceSetup { private final GraphQlSource.SchemaResourceBuilder graphQlSourceBuilder; @@ -81,8 +82,8 @@ public class GraphQlSetup implements GraphQlServiceSetup { } public GraphQlSetup dataFetcher(String type, String field, DataFetcher dataFetcher) { - return runtimeWiring(wiringBuilder -> - wiringBuilder.type(type, typeBuilder -> typeBuilder.dataFetcher(field, dataFetcher))); + return runtimeWiring((wiringBuilder) -> + wiringBuilder.type(type, (typeBuilder) -> typeBuilder.dataFetcher(field, dataFetcher))); } public GraphQlSetup typeDefinitionConfigurer(TypeDefinitionConfigurer configurer) { @@ -161,7 +162,7 @@ public class GraphQlSetup implements GraphQlServiceSetup { } public TestExecutionGraphQlService toGraphQlService() { - GraphQlSource source = graphQlSourceBuilder.build(); + GraphQlSource source = this.graphQlSourceBuilder.build(); DefaultExecutionGraphQlService service = new DefaultExecutionGraphQlService(source); this.dataLoaderRegistrars.forEach(service::addDataLoaderRegistrar); return new TestExecutionGraphQlService(service); diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionGraphQlService.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionGraphQlService.java index cad66b78..f4e18895 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionGraphQlService.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionGraphQlService.java @@ -22,6 +22,7 @@ import reactor.core.publisher.Mono; * Wrap an {@link ExecutionGraphQlService} to expose an addition convenience * method that takes a String document, and essentially hides the call to * {@link TestExecutionRequest#forDocument(String)}. + * @author Rossen Stoyanchev */ public class TestExecutionGraphQlService implements ExecutionGraphQlService { diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionRequest.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionRequest.java index 7eaf455a..032e22c6 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionRequest.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/TestExecutionRequest.java @@ -27,7 +27,7 @@ import org.springframework.graphql.support.DefaultExecutionGraphQlRequest; * * @author Rossen Stoyanchev */ -public class TestExecutionRequest extends DefaultExecutionGraphQlRequest { +public final class TestExecutionRequest extends DefaultExecutionGraphQlRequest { private static final AtomicLong idIndex = new AtomicLong(); diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketClient.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketClient.java index 41669b90..40ab0442 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketClient.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketClient.java @@ -52,11 +52,12 @@ public final class TestWebSocketClient implements WebSocketClient { /** * Return the connection at the specified index from a list of connections * based on order of execution. + * @param index the index of the connection to return */ public TestWebSocketConnection getConnection(int index) { Assert.isTrue(index < this.connections.size(), "No connection at index=" + index + ", total=" + this.connections.size()); - return connections.get(index); + return this.connections.get(index); } /** diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketConnection.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketConnection.java index 7efbe021..d8abd4c3 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketConnection.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/client/TestWebSocketConnection.java @@ -144,7 +144,7 @@ public final class TestWebSocketConnection { private Mono invokeHandler(WebSocketHandler handler, TestWebSocketSession session, boolean isClient) { return handler.handle(session) .then(Mono.defer(() -> session.close(CloseStatus.NORMAL))) - .onErrorResume(ex -> { + .onErrorResume((ex) -> { logger.error("Unhandled " + (isClient ? "client" : "server") + " error: " + ex.getMessage()); return session.close(CloseStatus.PROTOCOL_ERROR).then(Mono.error(ex)); }); @@ -153,6 +153,7 @@ public final class TestWebSocketConnection { /** * Close the connection from the client side. + * @param status the status to use when closing the session */ public Mono closeClientSession(CloseStatus status) { return this.clientSession.close(status); @@ -160,6 +161,7 @@ public final class TestWebSocketConnection { /** * Close the connection from the server side. + * @param status the status to use when closing the session */ public Mono closeServerSession(CloseStatus status) { return this.serverSession.close(status); @@ -218,7 +220,7 @@ public final class TestWebSocketConnection { } - public List getSentMessages() { + List getSentMessages() { return new ArrayList<>(this.sentMessages); } @@ -226,7 +228,7 @@ public final class TestWebSocketConnection { public Mono send(Publisher messages) { return Flux.from(messages) .doOnNext(this::saveMessage) - .doOnNext(message -> { + .doOnNext((message) -> { Sinks.EmitResult result = this.sendSink.tryEmitNext(message); Assert.state(result.isSuccess(), this + " failed to send: " + message + ", with " + result); }) @@ -253,6 +255,7 @@ public final class TestWebSocketConnection { return this.closeStatusSink.asMono(); } + @Override public Mono close(CloseStatus status) { if (logger.isDebugEnabled()) { logger.debug("Closing " + this + " with " + status); @@ -267,7 +270,7 @@ public final class TestWebSocketConnection { } else { this.closeStatusSink.tryEmitEmpty(); - }; + } } @Override diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/execution/MockExecutionGraphQlService.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/execution/MockExecutionGraphQlService.java index e8e11ee9..be7d61c1 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/execution/MockExecutionGraphQlService.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/execution/MockExecutionGraphQlService.java @@ -68,6 +68,7 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set the default response to fall back on as a "data"-only response. + * @param dataJson the JSON data response */ public void setDefaultResponse(String dataJson) { ExecutionInput input = ExecutionInput.newExecutionInput().query("").build(); @@ -77,6 +78,8 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set a "data"-only response for the given document. + * @param document the graphql document + * @param dataJson the JSON data for the given document */ public void setDataAsJson(String document, String dataJson) { setResponse(document, decode(dataJson)); @@ -84,6 +87,8 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set an "errors" response for the given document. + * @param document the graphql document + * @param errors the errors for the given document */ public void setErrors(String document, GraphQLError... errors) { setResponse(document, null, errors); @@ -91,6 +96,8 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set an "errors" response for the given document. + * @param document the graphql document + * @param errorBuilderConsumer a consumer that builds errors for the given document */ public void setError(String document, Consumer> errorBuilderConsumer) { GraphqlErrorBuilder errorBuilder = GraphqlErrorBuilder.newError(); @@ -100,6 +107,9 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set a "data" and "errors" response for the given document. + * @param document the graphql document + * @param dataJson the JSON data for the given document + * @param errors the errors for the given document */ public void setDataAsJsonAndErrors(String document, String dataJson, GraphQLError... errors) { setResponse(document, decode(dataJson), errors); @@ -107,6 +117,9 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set a "data" and "errors" response for the given document. + * @param document the graphql document + * @param data the map to be used as data for the response + * @param errors the errors to be used for the response */ private void setResponse(String document, @Nullable Map data, GraphQLError... errors) { ExecutionResultImpl.Builder builder = new ExecutionResultImpl.Builder(); @@ -121,6 +134,8 @@ public class MockExecutionGraphQlService implements ExecutionGraphQlService { /** * Set a response for the given document. + * @param document the graphql document + * @param result the execution result for the given document */ @SuppressWarnings("unused") public void setResponse(String document, ExecutionResult result) { diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/server/WebGraphQlSetup.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/server/WebGraphQlSetup.java index 8073683a..dfb7028e 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/server/WebGraphQlSetup.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/server/WebGraphQlSetup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.graphql.server; import org.springframework.graphql.server.webflux.GraphQlHttpHandler;

KeyValue
query{@link #getDocument() document}