Skip to content

Commit 78f7df2

Browse files
committed
Consistently check errors in GraphQlTester
Closes gh-891
1 parent b37a06b commit 78f7df2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -296,6 +296,7 @@ public Path path(String path) {
296296

297297
@Override
298298
public Path path(String path, Consumer<Path> pathConsumer) {
299+
this.delegate.verifyErrors();
299300
return DefaultPath.forNestedPath(null, path, this.delegate, pathConsumer);
300301
}
301302

spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -292,6 +292,21 @@ void errorsCheckedOnTraverse() {
292292
assertThat(getActualRequestDocument()).contains(document);
293293
}
294294

295+
@Test // gh-891
296+
void errorsCheckedOnTraverseWithConsumer() {
297+
298+
String document = "{me {name, friends}}";
299+
getGraphQlService().setError(document, builder -> builder.message("Invalid query"));
300+
301+
assertThatThrownBy(() ->
302+
graphQlTester().document(document)
303+
.execute()
304+
.path("me", it -> it.path("name").hasValue()))
305+
.hasMessageContaining("Response has 1 unexpected error(s)");
306+
307+
assertThat(getActualRequestDocument()).contains(document);
308+
}
309+
295310
@Test
296311
void errorsPartiallyFiltered() {
297312

0 commit comments

Comments
 (0)