Skip to content

Commit 2dafd5d

Browse files
committed
Merge branch '1.0.x'
2 parents be9a215 + 6004937 commit 2dafd5d

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQlTester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ interface Errors {
445445
Errors expect(Predicate<ResponseError> errorPredicate);
446446

447447
/**
448-
* Verify there are either no errors or that there no unexpected errors that have
448+
* Verify there are either no errors or that there are no unexpected errors that have
449449
* not been {@link #filter(Predicate) filtered out}.
450450
* @return a spec to switch to a data path
451451
*/

spring-graphql/src/main/java/org/springframework/graphql/client/DefaultGraphQlClient.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,16 @@ protected RetrieveSpecSupport(String path) {
186186
}
187187

188188
/**
189-
* Return the field if valid, or {@code null} if {@code null} without errors.
190-
* @throws FieldAccessException for invalid response or failed field
189+
* Return the field or {@code null}, but only if the response is valid
190+
* and there are no field errors, or raise {@link FieldAccessException}
191+
* otherwise.
192+
* @throws FieldAccessException in case of an invalid response or any
193+
* field error at, above or below the field path
191194
*/
192195
@Nullable
193196
protected ClientResponseField getValidField(ClientGraphQlResponse response) {
194197
ClientResponseField field = response.field(this.path);
195-
if (!response.isValid() || field.getError() != null) {
198+
if (!response.isValid() || !field.getErrors().isEmpty()) {
196199
throw new FieldAccessException(
197200
((DefaultClientGraphQlResponse) response).getRequest(), response, field);
198201
}

spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ interface RequestSpec {
191191
* client.document("..").execute().map(response -> response.toEntity(..))
192192
* </pre>
193193
* @return a spec with decoding options
194-
* @throws FieldAccessException if the target field has any errors,
195-
* including nested errors.
194+
* @throws FieldAccessException if the field has any field errors,
195+
* including errors at, above or below the field path.
196196
*/
197197
RetrieveSpec retrieve(String path);
198198

spring-graphql/src/main/java/org/springframework/graphql/support/AbstractGraphQlResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private static Object initFieldValue(List<Object> path, GraphQlResponse response
133133
}
134134

135135
/**
136-
* Return field errors whose path starts with the given field path.
136+
* Return errors whose path is at, above, or below the given path.
137137
* @param path the field path to match
138138
* @return errors whose path starts with the dataPath
139139
*/
@@ -144,7 +144,7 @@ private static List<ResponseError> initFieldErrors(String path, GraphQlResponse
144144
return response.getErrors().stream()
145145
.filter(error -> {
146146
String errorPath = error.getPath();
147-
return !errorPath.isEmpty() && (errorPath.startsWith(path) || path.startsWith(errorPath));
147+
return (!errorPath.isEmpty() && (errorPath.startsWith(path) || path.startsWith(errorPath)));
148148
})
149149
.collect(Collectors.toList());
150150
}

spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,23 @@ void retrieveInvalidResponse() {
130130
}
131131

132132
@Test
133-
void retrievePartialResponse() {
133+
void retrieveFieldErrorAt() {
134+
String document = "fieldErrorResponse";
135+
getGraphQlService().setDataAsJsonAndErrors(document, "{\"me\": null}", errorForPath("/me"));
136+
testRetrieveFieldAccessException(document, "me");
137+
}
134138

139+
@Test // gh-499
140+
void retrieveFieldErrorBelow() {
135141
String document = "fieldErrorResponse";
136142
getGraphQlService().setDataAsJsonAndErrors(document, "{\"me\": {\"name\":null}}", errorForPath("/me/name"));
143+
testRetrieveFieldAccessException(document, "me");
144+
}
137145

138-
MovieCharacter character = graphQlClient().document(document).retrieve("me").toEntity(MovieCharacter.class).block();
139-
assertThat(character).isNotNull().extracting(MovieCharacter::getName).isNull();
140-
146+
@Test
147+
void retrieveFieldErrorAbove() {
148+
String document = "fieldErrorResponse";
149+
getGraphQlService().setDataAsJsonAndErrors(document, "{\"me\": null}", errorForPath("/me"));
141150
testRetrieveFieldAccessException(document, "me.name");
142151
}
143152

0 commit comments

Comments
 (0)