Skip to content

Commit 290237e

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # gradle.properties
2 parents 773c305 + 7115b67 commit 290237e

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ PROJECT_LICENSE=MIT
77
PROJECT_LICENSE_URL=https://github.com/graphql-java-kickstart/spring-boot-graphql/blob/master/LICENSE.md
88
PROJECT_DEV_ID=apottere
99
PROJECT_DEV_NAME=Andrew Potter
10-
LIB_GRAPHQL_JAVA_VER=17.2
10+
LIB_GRAPHQL_JAVA_VER=17.3
1111
LIB_JACKSON_VER=2.12.5
1212
LIB_SLF4J_VER=1.7.32
1313
LIB_LOMBOK_VER=1.18.20
1414
SOURCE_COMPATIBILITY=1.8
1515
TARGET_COMPATIBILITY=1.8
16+
GRADLE_WRAPPER_VER=7.0

graphql-java-servlet/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ dependencies {
3131
testImplementation 'io.github.graphql-java:graphql-java-annotations:8.3'
3232

3333
// Unit testing
34-
testImplementation "org.codehaus.groovy:groovy-all:3.0.8"
34+
testImplementation "org.codehaus.groovy:groovy-all:3.0.9"
3535
testImplementation "org.spockframework:spock-core:2.0-groovy-3.0"
3636
testRuntimeOnly "cglib:cglib-nodep:3.3.0"
3737
testRuntimeOnly "org.objenesis:objenesis:3.2"
3838
testImplementation "org.slf4j:slf4j-simple:$LIB_SLF4J_VER"
39-
testImplementation 'org.springframework:spring-test:5.3.9'
40-
testRuntimeOnly 'org.springframework:spring-web:5.3.9'
39+
testImplementation 'org.springframework:spring-test:5.3.10'
40+
testRuntimeOnly 'org.springframework:spring-web:5.3.10'
4141
testImplementation 'com.google.guava:guava:30.1.1-jre'
4242
}

graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestInvokerImpl.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ private CompletableFuture<Void> handle(
9191
return futureResult
9292
.thenApplyQueryResult()
9393
.thenAccept(
94-
it -> writeResultResponse(futureResult.getInvocationInput(), it, request, response))
94+
it -> {
95+
listenerHandler.beforeFlush();
96+
writeResultResponse(futureResult.getInvocationInput(), it, request, response);
97+
})
9598
.thenAccept(it -> listenerHandler.onSuccess())
9699
.exceptionally(
97100
t ->

graphql-java-servlet/src/main/java/graphql/kickstart/servlet/ListenerHandler.java

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ void runCallbacks(Consumer<RequestCallback> action) {
6060
});
6161
}
6262

63+
void beforeFlush() {
64+
runCallbacks(it -> it.beforeFlush(request, response));
65+
}
66+
6367
void onSuccess() {
6468
runCallbacks(it -> it.onSuccess(request, response));
6569
}

graphql-java-servlet/src/main/java/graphql/kickstart/servlet/core/GraphQLServletListener.java

+33
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,50 @@
66
/** @author Andrew Potter */
77
public interface GraphQLServletListener {
88

9+
/**
10+
* Called this method when the request started processing.
11+
* @param request http request
12+
* @param response http response
13+
* @return request callback or {@literal null}
14+
*/
915
default RequestCallback onRequest(HttpServletRequest request, HttpServletResponse response) {
1016
return null;
1117
}
1218

19+
/**
20+
* The callback which used to add additional listeners for GraphQL request execution.
21+
*/
1322
interface RequestCallback {
1423

24+
/**
25+
* Called right before the response will be written and flushed. Can be used for applying some
26+
* changes to the response object, like adding response headers.
27+
* @param request http request
28+
* @param response http response
29+
*/
30+
default void beforeFlush(HttpServletRequest request, HttpServletResponse response) {}
31+
32+
/**
33+
* Called when GraphQL invoked successfully and the response was written already.
34+
* @param request http request
35+
* @param response http response
36+
*/
1537
default void onSuccess(HttpServletRequest request, HttpServletResponse response) {}
1638

39+
/**
40+
* Called when GraphQL was failed and the response was written already.
41+
* @param request http request
42+
* @param response http response
43+
*/
1744
default void onError(
1845
HttpServletRequest request, HttpServletResponse response, Throwable throwable) {}
1946

47+
/**
48+
* Called finally once on both success and failed GraphQL invocation. The response is also
49+
* already written.
50+
* @param request http request
51+
* @param response http response
52+
*/
2053
default void onFinally(HttpServletRequest request, HttpServletResponse response) {}
2154
}
2255
}

0 commit comments

Comments
 (0)