|
16 | 16 |
|
17 | 17 | package org.springframework.graphql.client;
|
18 | 18 |
|
| 19 | +import graphql.language.SourceLocation; |
| 20 | +import java.io.IOException; |
19 | 21 | import java.util.Arrays;
|
20 | 22 | import java.util.Collections;
|
21 | 23 | import java.util.List;
|
22 | 24 | import java.util.Map;
|
23 |
| -import java.util.stream.Collectors; |
24 | 25 |
|
25 | 26 | import graphql.GraphQLError;
|
26 | 27 | import graphql.GraphqlErrorBuilder;
|
27 | 28 | import graphql.execution.ResultPath;
|
28 | 29 | import org.junit.jupiter.api.Test;
|
| 30 | +import org.testcontainers.shaded.com.fasterxml.jackson.databind.DeserializationFeature; |
29 | 31 | import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
|
30 | 32 |
|
31 | 33 | import org.springframework.graphql.ResponseError;
|
@@ -136,27 +138,54 @@ void fieldErrors() {
|
136 | 138 | assertThat(errors.get(2).getPath()).isEqualTo("me.friends[0].name");
|
137 | 139 | }
|
138 | 140 |
|
139 |
| - private GraphQLError createError(@Nullable String errorPath, String message) { |
| 141 | + @Test |
| 142 | + void errorWithBigIntegerNumbers() throws IOException { |
| 143 | + |
| 144 | + String path = "me.friends"; |
| 145 | + |
| 146 | + GraphQLError error0 = createError("/me", "fail-me", new SourceLocation(100, 100)); |
| 147 | + |
| 148 | + ObjectMapper objectMapper = new ObjectMapper().enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS); |
| 149 | + String error0string = objectMapper.writeValueAsString(error0); |
| 150 | + Map<?, ?> error0Map = objectMapper.readValue(error0string, Map.class); |
| 151 | + |
| 152 | + List<?> list = List.of(error0Map); |
| 153 | + |
| 154 | + ClientGraphQlResponse response = createResponse(Collections.singletonMap("errors", list)); |
| 155 | + ClientResponseField field = response.field(path); |
| 156 | + |
| 157 | + List<ResponseError> errors = field.getErrors(); |
| 158 | + |
| 159 | + assertThat(errors).hasSize(1); |
| 160 | + assertThat(errors.get(0).getPath()).isEqualTo("me"); |
| 161 | + assertThat(errors.get(0).getLocations().get(0).getLine()).isEqualTo(100); |
| 162 | + assertThat(errors.get(0).getLocations().get(0).getColumn()).isEqualTo(100); |
| 163 | + } |
| 164 | + |
| 165 | + private GraphQLError createError(@Nullable String errorPath, String message, SourceLocation... locations) { |
140 | 166 | GraphqlErrorBuilder<?> builder = GraphqlErrorBuilder.newError().message(message);
|
141 | 167 | if (errorPath != null) {
|
142 | 168 | builder = builder.path(ResultPath.parse(errorPath));
|
143 | 169 | }
|
| 170 | + if (locations.length > 0) { |
| 171 | + builder = builder.locations(List.of(locations)); |
| 172 | + } |
144 | 173 | return builder.build();
|
145 | 174 | }
|
146 | 175 |
|
147 | 176 | private ClientResponseField getFieldOnDataResponse(String path, String dataJson) throws Exception {
|
148 | 177 | Map<?, ?> dataMap = mapper.readValue(dataJson, Map.class);
|
149 |
| - ClientGraphQlResponse response = creatResponse(Collections.singletonMap("data", dataMap)); |
| 178 | + ClientGraphQlResponse response = createResponse(Collections.singletonMap("data", dataMap)); |
150 | 179 | return response.field(path);
|
151 | 180 | }
|
152 | 181 |
|
153 | 182 | private ClientResponseField getFieldOnErrorResponse(String path, GraphQLError... errors) {
|
154 | 183 | List<?> list = Arrays.stream(errors).map(GraphQLError::toSpecification).toList();
|
155 |
| - ClientGraphQlResponse response = creatResponse(Collections.singletonMap("errors", list)); |
| 184 | + ClientGraphQlResponse response = createResponse(Collections.singletonMap("errors", list)); |
156 | 185 | return response.field(path);
|
157 | 186 | }
|
158 | 187 |
|
159 |
| - private ClientGraphQlResponse creatResponse(Map<String, Object> responseMap) { |
| 188 | + private ClientGraphQlResponse createResponse(Map<String, Object> responseMap) { |
160 | 189 | return new DefaultClientGraphQlResponse(
|
161 | 190 | new DefaultClientGraphQlRequest("{test}", null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()),
|
162 | 191 | new ResponseMapGraphQlResponse(responseMap),
|
|
0 commit comments