|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.util.Map;
|
20 | 20 |
|
| 21 | +import graphql.ErrorType; |
21 | 22 | import org.dataloader.DataLoaderRegistry;
|
22 | 23 | import org.junit.jupiter.api.Test;
|
23 | 24 | import reactor.core.publisher.Flux;
|
|
28 | 29 | import org.springframework.graphql.ExecutionGraphQlResponse;
|
29 | 30 | import org.springframework.graphql.GraphQlSetup;
|
30 | 31 | import org.springframework.graphql.TestExecutionRequest;
|
| 32 | +import org.springframework.graphql.support.DefaultExecutionGraphQlRequest; |
31 | 33 |
|
32 | 34 | import static org.assertj.core.api.Assertions.assertThat;
|
33 | 35 |
|
34 | 36 | /**
|
35 | 37 | * Unit tests for {@link DefaultExecutionGraphQlService}.
|
36 | 38 | *
|
37 | 39 | * @author Rossen Stoyanchev
|
38 |
| - * @since 1.2.4 |
39 | 40 | */
|
40 | 41 | public class DefaultExecutionGraphQlServiceTests {
|
41 | 42 |
|
@@ -64,4 +65,18 @@ void customDataLoaderRegistry() {
|
64 | 65 | assertThat(dataLoaderRegistry.getDataLoaders()).hasSize(1);
|
65 | 66 | }
|
66 | 67 |
|
| 68 | + @Test |
| 69 | + void shouldHandleGraphQlErrors() { |
| 70 | + GraphQlSource graphQlSource = GraphQlSetup.schemaContent("type Query { greeting: String }") |
| 71 | + .queryFetcher("greeting", (env) -> "hi") |
| 72 | + .toGraphQlSource(); |
| 73 | + DefaultExecutionGraphQlService graphQlService = new DefaultExecutionGraphQlService(graphQlSource); |
| 74 | + |
| 75 | + ExecutionGraphQlRequest request = new DefaultExecutionGraphQlRequest("{ greeting }", "unknown", |
| 76 | + null, null, "uniqueId", null); |
| 77 | + ExecutionGraphQlResponse response = graphQlService.execute(request).block(); |
| 78 | + assertThat(response.getExecutionResult().getErrors()).singleElement() |
| 79 | + .hasFieldOrPropertyWithValue("errorType", ErrorType.ValidationError); |
| 80 | + } |
| 81 | + |
67 | 82 | }
|
0 commit comments