Turn off auto-formatting where it reduces readability

This commit is contained in:
Rossen Stoyanchev
2021-06-15 14:01:52 +01:00
parent a5f56ca3cb
commit 43f9e34c81
27 changed files with 534 additions and 283 deletions

View File

@@ -5,7 +5,6 @@ import java.util.Map;
import graphql.schema.idl.RuntimeWiring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.boot.RuntimeWiringCustomizer;
import org.springframework.stereotype.Component;

View File

@@ -1,9 +1,13 @@
package io.spring.sample.graphql;
import graphql.ErrorClassification;
import java.util.Arrays;
import java.util.List;
import graphql.GraphQLError;
import graphql.GraphqlErrorBuilder;
import graphql.schema.DataFetchingEnvironment;
import reactor.core.publisher.Mono;
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
import org.springframework.graphql.execution.ErrorType;
import org.springframework.security.access.AccessDeniedException;
@@ -13,19 +17,18 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import java.util.Arrays;
import java.util.List;
// @formatter:off
@Component
public class SecurityDataFetcherExceptionResolver implements DataFetcherExceptionResolver {
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
@Override
public Mono<List<GraphQLError>> resolveException(Throwable exception, DataFetchingEnvironment environment) {
if (exception instanceof AuthenticationException) {
// TOTO: should this be empty ?
}
if (exception instanceof AccessDeniedException) {
return ReactiveSecurityContextHolder.getContext()
@@ -38,10 +41,19 @@ public class SecurityDataFetcherExceptionResolver implements DataFetcherExceptio
}
private Mono<List<GraphQLError>> unauthorized(DataFetchingEnvironment environment) {
return Mono.fromCallable(() -> Arrays.asList(GraphqlErrorBuilder.newError(environment).errorType(ErrorType.UNAUTHORIZED).message("Unauthorized").build()));
return Mono.fromCallable(() -> Arrays.asList(
GraphqlErrorBuilder.newError(environment)
.errorType(ErrorType.UNAUTHORIZED)
.message("Unauthorized")
.build()));
}
private Mono<List<GraphQLError>> forbidden(DataFetchingEnvironment environment) {
return Mono.fromCallable(() -> Arrays.asList(GraphqlErrorBuilder.newError(environment).errorType(ErrorType.FORBIDDEN).message("Forbidden").build()));
return Mono.fromCallable(() -> Arrays.asList(
GraphqlErrorBuilder.newError(environment)
.errorType(ErrorType.FORBIDDEN)
.message("Forbidden")
.build()));
}
}

View File

@@ -1,7 +1,10 @@
package io.spring.sample.graphql;
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
@@ -10,7 +13,7 @@ import org.springframework.security.test.web.reactive.server.SecurityMockServerC
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
import java.util.Collections;
// @formatter:off
@SpringBootTest()
class SampleApplicationTests {