Skip to content

Commit 16656d6

Browse files
committed
Polishing Javadoc and in security sample
1 parent cc61c4b commit 16656d6

File tree

8 files changed

+36
-35
lines changed

8 files changed

+36
-35
lines changed

samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SalaryService.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.math.BigDecimal;
44

5-
import reactor.core.publisher.Mono;
6-
75
import org.springframework.security.access.annotation.Secured;
86
import org.springframework.security.access.prepost.PreAuthorize;
97
import org.springframework.stereotype.Component;

samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SecurityDataFetcherExceptionResolver.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.spring.sample.graphql;
22

3+
import java.util.Collections;
4+
import java.util.List;
5+
36
import graphql.GraphQLError;
47
import graphql.GraphqlErrorBuilder;
58
import graphql.schema.DataFetchingEnvironment;
9+
610
import org.springframework.graphql.execution.ErrorType;
711
import org.springframework.graphql.execution.SyncDataFetcherExceptionResolver;
812
import org.springframework.security.access.AccessDeniedException;
@@ -15,9 +19,6 @@
1519
import org.springframework.stereotype.Component;
1620
import org.springframework.util.Assert;
1721

18-
import java.util.Arrays;
19-
import java.util.List;
20-
2122
@Component
2223
public class SecurityDataFetcherExceptionResolver implements SyncDataFetcherExceptionResolver {
2324

@@ -45,15 +46,15 @@ public void setAuthenticationTrustResolver(AuthenticationTrustResolver authentic
4546
}
4647

4748
private List<GraphQLError> unauthorized(DataFetchingEnvironment environment) {
48-
return Arrays.asList(
49+
return Collections.singletonList(
4950
GraphqlErrorBuilder.newError(environment)
5051
.errorType(ErrorType.UNAUTHORIZED)
5152
.message("Unauthorized")
5253
.build());
5354
}
5455

5556
private List<GraphQLError> forbidden(DataFetchingEnvironment environment) {
56-
return Arrays.asList(
57+
return Collections.singletonList(
5758
GraphqlErrorBuilder.newError(environment)
5859
.errorType(ErrorType.FORBIDDEN)
5960
.message("Forbidden")

samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/RequestAttributesAccessor.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package io.spring.sample.graphql.greeting;
1717

18-
import java.util.Collections;
1918
import java.util.Map;
2019

2120
import org.springframework.graphql.execution.ThreadLocalAccessor;
@@ -30,29 +29,23 @@
3029
@Component
3130
public class RequestAttributesAccessor implements ThreadLocalAccessor {
3231

33-
private static final String ATTRIBUTES_KEY = RequestAttributesAccessor.class.getName() + ".requestAttributes";
32+
private static final String KEY = RequestAttributesAccessor.class.getName();
3433

3534
@Override
3635
public void extractValues(Map<String, Object> container) {
37-
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
38-
if (attributes != null) {
39-
container.put(ATTRIBUTES_KEY, attributes);
40-
}
36+
container.put(KEY, RequestContextHolder.getRequestAttributes());
4137
}
4238

4339
@Override
4440
public void restoreValues(Map<String, Object> values) {
45-
RequestAttributes attributes = (RequestAttributes) values.get(ATTRIBUTES_KEY);
46-
if (attributes != null) {
47-
RequestContextHolder.setRequestAttributes(attributes);
41+
if (values.containsKey(KEY)) {
42+
RequestContextHolder.setRequestAttributes((RequestAttributes) values.get(KEY));
4843
}
4944
}
5045

5146
@Override
5247
public void resetValues(Map<String, Object> values) {
53-
if (values.get(ATTRIBUTES_KEY) != null) {
54-
RequestContextHolder.resetRequestAttributes();
55-
}
48+
RequestContextHolder.resetRequestAttributes();
5649
}
5750

5851
}

spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131

3232
/**
3333
* Common representation for GraphQL request input. This can be converted to
34-
* {@link ExecutionInput} via {@link #toExecutionInput()} and the {@code ExecutionInput}
35-
* further customized via {@link #configureExecutionInput(BiFunction)}.
34+
* {@link ExecutionInput} via {@link #toExecutionInput()} and the
35+
* {@code ExecutionInput} further customized via
36+
* {@link #configureExecutionInput(BiFunction)}.
3637
*
3738
* @author Rossen Stoyanchev
3839
* @since 1.0.0

spring-graphql/src/main/java/org/springframework/graphql/data/QuerydslDataFetcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
* @see ReactiveQuerydslPredicateExecutor
9494
* @see Predicate
9595
* @see QuerydslBinderCustomizer
96+
* @see <a href="https://docs.spring.io/spring-data/commons/docs/current/reference/html/#core.extensions.querydsl">
97+
* Spring Data Querydsl extension</a>
9698
*/
9799
public abstract class QuerydslDataFetcher<T> {
98100

spring-graphql/src/main/java/org/springframework/graphql/data/package-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616

1717
/**
18-
* Support for integrating Spring Data data fetchers.
18+
* Spring Data support for GraphQL, including built-in Querydsl
19+
* {@link graphql.schema.DataFetcher} implementations.
1920
*/
2021
@NonNullApi
2122
@NonNullFields

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
import reactor.core.publisher.Mono;
2424

2525
/**
26-
* Contract to resolve exceptions raised by {@link graphql.schema.DataFetcher}'s to
27-
* {@code GraphQLError}'s to add to the GraphQL response. Implementations are typically
28-
* declared as beans in Spring configuration and invoked in order until one emits a List.
26+
* Contract for resolving exceptions from {@link graphql.schema.DataFetcher}'s
27+
* to {@code GraphQLError}'s to be added to the GraphQL response, possibly also
28+
* using Spring's {@link graphql.ErrorType} for the error category.
29+
*
30+
* <p>Implementations are typically declared as beans in Spring configuration
31+
* and invoked in order until one emits a List.
2932
*
3033
* @author Rossen Stoyanchev
3134
* @since 1.0.0
@@ -35,17 +38,19 @@ public interface DataFetcherExceptionResolver {
3538

3639
/**
3740
* Resolve the given exception and return the error(s) to add to the response.
38-
* <p>
39-
* Implementations can use
40-
* {@link graphql.GraphqlErrorBuilder#newError(DataFetchingEnvironment)} to create an
41-
* error with the coordinates of the target field, and use {@link ErrorType} to
42-
* specify a category for the error.
41+
*
42+
* <p>Implementations can use
43+
* {@link graphql.GraphqlErrorBuilder#newError(DataFetchingEnvironment)} to
44+
* create an error with the coordinates of the target field, and use
45+
* {@link ErrorType} to specify a category for the error.
46+
*
4347
* @param exception the exception to resolve
4448
* @param environment the environment for the invoked {@code DataFetcher}
45-
* @return a {@code Mono} with errors to add to the GraphQL response; if the
46-
* {@code Mono} completes with an empty List, the exception is resolved without any
47-
* errors added to the response; if the {@code Mono} completes empty, without emitting
48-
* a List, the exception remains unresolved and gives other resolvers a chance.
49+
* @return a {@code Mono} with errors to add to the GraphQL response;
50+
* if the {@code Mono} completes with an empty List, the exception is resolved
51+
* without any errors added to the response; if the {@code Mono} completes
52+
* empty, without emitting a List, the exception remains unresolved and gives
53+
* other resolvers a chance.
4954
*/
5055
Mono<List<GraphQLError>> resolveException(Throwable exception, DataFetchingEnvironment environment);
5156

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747
class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder {
4848

49-
private List<Resource> schemaResources = new ArrayList<>();
49+
private final List<Resource> schemaResources = new ArrayList<>();
5050

5151
private RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().build();
5252

0 commit comments

Comments
 (0)