diff --git a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryService.java b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryService.java index 76da5e34..75b1a14f 100644 --- a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryService.java +++ b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryService.java @@ -2,8 +2,6 @@ package io.spring.sample.graphql; import java.math.BigDecimal; -import reactor.core.publisher.Mono; - import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Component; diff --git a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java index de44818f..1c357a48 100644 --- a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java +++ b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java @@ -1,8 +1,12 @@ package io.spring.sample.graphql; +import java.util.Collections; +import java.util.List; + import graphql.GraphQLError; import graphql.GraphqlErrorBuilder; import graphql.schema.DataFetchingEnvironment; + import org.springframework.graphql.execution.ErrorType; import org.springframework.graphql.execution.SyncDataFetcherExceptionResolver; import org.springframework.security.access.AccessDeniedException; @@ -15,9 +19,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import java.util.Arrays; -import java.util.List; - @Component public class SecurityDataFetcherExceptionResolver implements SyncDataFetcherExceptionResolver { @@ -45,7 +46,7 @@ public class SecurityDataFetcherExceptionResolver implements SyncDataFetcherExce } private List unauthorized(DataFetchingEnvironment environment) { - return Arrays.asList( + return Collections.singletonList( GraphqlErrorBuilder.newError(environment) .errorType(ErrorType.UNAUTHORIZED) .message("Unauthorized") @@ -53,7 +54,7 @@ public class SecurityDataFetcherExceptionResolver implements SyncDataFetcherExce } private List forbidden(DataFetchingEnvironment environment) { - return Arrays.asList( + return Collections.singletonList( GraphqlErrorBuilder.newError(environment) .errorType(ErrorType.FORBIDDEN) .message("Forbidden") diff --git a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/RequestAttributesAccessor.java b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/RequestAttributesAccessor.java index 52dd3516..d2e9f353 100644 --- a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/RequestAttributesAccessor.java +++ b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/RequestAttributesAccessor.java @@ -15,7 +15,6 @@ */ package io.spring.sample.graphql.greeting; -import java.util.Collections; import java.util.Map; import org.springframework.graphql.execution.ThreadLocalAccessor; @@ -30,29 +29,23 @@ import org.springframework.web.context.request.RequestContextHolder; @Component public class RequestAttributesAccessor implements ThreadLocalAccessor { - private static final String ATTRIBUTES_KEY = RequestAttributesAccessor.class.getName() + ".requestAttributes"; + private static final String KEY = RequestAttributesAccessor.class.getName(); @Override public void extractValues(Map container) { - RequestAttributes attributes = RequestContextHolder.getRequestAttributes(); - if (attributes != null) { - container.put(ATTRIBUTES_KEY, attributes); - } + container.put(KEY, RequestContextHolder.getRequestAttributes()); } @Override public void restoreValues(Map values) { - RequestAttributes attributes = (RequestAttributes) values.get(ATTRIBUTES_KEY); - if (attributes != null) { - RequestContextHolder.setRequestAttributes(attributes); + if (values.containsKey(KEY)) { + RequestContextHolder.setRequestAttributes((RequestAttributes) values.get(KEY)); } } @Override public void resetValues(Map values) { - if (values.get(ATTRIBUTES_KEY) != null) { - RequestContextHolder.resetRequestAttributes(); - } + RequestContextHolder.resetRequestAttributes(); } } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java b/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java index 922fb8de..6e08d18e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java @@ -31,8 +31,9 @@ import org.springframework.util.CollectionUtils; /** * Common representation for GraphQL request input. This can be converted to - * {@link ExecutionInput} via {@link #toExecutionInput()} and the {@code ExecutionInput} - * further customized via {@link #configureExecutionInput(BiFunction)}. + * {@link ExecutionInput} via {@link #toExecutionInput()} and the + * {@code ExecutionInput} further customized via + * {@link #configureExecutionInput(BiFunction)}. * * @author Rossen Stoyanchev * @since 1.0.0 diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/QuerydslDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/QuerydslDataFetcher.java index 60a72df2..599cdd22 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/QuerydslDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/QuerydslDataFetcher.java @@ -93,6 +93,8 @@ import org.springframework.util.MultiValueMap; * @see ReactiveQuerydslPredicateExecutor * @see Predicate * @see QuerydslBinderCustomizer + * @see + * Spring Data Querydsl extension */ public abstract class QuerydslDataFetcher { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/package-info.java b/spring-graphql/src/main/java/org/springframework/graphql/data/package-info.java index bcf08822..b2897197 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/package-info.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/package-info.java @@ -15,7 +15,8 @@ */ /** - * Support for integrating Spring Data data fetchers. + * Spring Data support for GraphQL, including built-in Querydsl + * {@link graphql.schema.DataFetcher} implementations. */ @NonNullApi @NonNullFields diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolver.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolver.java index 9837390e..a80af1bd 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolver.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DataFetcherExceptionResolver.java @@ -23,9 +23,12 @@ import graphql.schema.DataFetchingEnvironment; import reactor.core.publisher.Mono; /** - * Contract to resolve exceptions raised by {@link graphql.schema.DataFetcher}'s to - * {@code GraphQLError}'s to add to the GraphQL response. Implementations are typically - * declared as beans in Spring configuration and invoked in order until one emits a List. + * Contract for resolving exceptions from {@link graphql.schema.DataFetcher}'s + * to {@code GraphQLError}'s to be added to the GraphQL response, possibly also + * using Spring's {@link graphql.ErrorType} for the error category. + * + *

Implementations are typically declared as beans in Spring configuration + * and invoked in order until one emits a List. * * @author Rossen Stoyanchev * @since 1.0.0 @@ -35,17 +38,19 @@ public interface DataFetcherExceptionResolver { /** * Resolve the given exception and return the error(s) to add to the response. - *

- * Implementations can use - * {@link graphql.GraphqlErrorBuilder#newError(DataFetchingEnvironment)} to create an - * error with the coordinates of the target field, and use {@link ErrorType} to - * specify a category for the error. + * + *

Implementations can use + * {@link graphql.GraphqlErrorBuilder#newError(DataFetchingEnvironment)} to + * create an error with the coordinates of the target field, and use + * {@link ErrorType} to specify a category for the error. + * * @param exception the exception to resolve * @param environment the environment for the invoked {@code DataFetcher} - * @return a {@code Mono} with errors to add to the GraphQL response; if the - * {@code Mono} completes with an empty List, the exception is resolved without any - * errors added to the response; if the {@code Mono} completes empty, without emitting - * a List, the exception remains unresolved and gives other resolvers a chance. + * @return a {@code Mono} with errors to add to the GraphQL response; + * if the {@code Mono} completes with an empty List, the exception is resolved + * without any errors added to the response; if the {@code Mono} completes + * empty, without emitting a List, the exception remains unresolved and gives + * other resolvers a chance. */ Mono> resolveException(Throwable exception, DataFetchingEnvironment environment); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java index 9bfec344..462b21ff 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultGraphQlSourceBuilder.java @@ -46,7 +46,7 @@ import org.springframework.util.Assert; */ class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder { - private List schemaResources = new ArrayList<>(); + private final List schemaResources = new ArrayList<>(); private RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().build();