Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
oliemansm committed Sep 20, 2021
2 parents 773c305 + 7115b67 commit 290237e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ PROJECT_LICENSE=MIT
PROJECT_LICENSE_URL=https://github.com/graphql-java-kickstart/spring-boot-graphql/blob/master/LICENSE.md
PROJECT_DEV_ID=apottere
PROJECT_DEV_NAME=Andrew Potter
LIB_GRAPHQL_JAVA_VER=17.2
LIB_GRAPHQL_JAVA_VER=17.3
LIB_JACKSON_VER=2.12.5
LIB_SLF4J_VER=1.7.32
LIB_LOMBOK_VER=1.18.20
SOURCE_COMPATIBILITY=1.8
TARGET_COMPATIBILITY=1.8
GRADLE_WRAPPER_VER=7.0
6 changes: 3 additions & 3 deletions graphql-java-servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ dependencies {
testImplementation 'io.github.graphql-java:graphql-java-annotations:8.3'

// Unit testing
testImplementation "org.codehaus.groovy:groovy-all:3.0.8"
testImplementation "org.codehaus.groovy:groovy-all:3.0.9"
testImplementation "org.spockframework:spock-core:2.0-groovy-3.0"
testRuntimeOnly "cglib:cglib-nodep:3.3.0"
testRuntimeOnly "org.objenesis:objenesis:3.2"
testImplementation "org.slf4j:slf4j-simple:$LIB_SLF4J_VER"
testImplementation 'org.springframework:spring-test:5.3.9'
testRuntimeOnly 'org.springframework:spring-web:5.3.9'
testImplementation 'org.springframework:spring-test:5.3.10'
testRuntimeOnly 'org.springframework:spring-web:5.3.10'
testImplementation 'com.google.guava:guava:30.1.1-jre'
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ private CompletableFuture<Void> handle(
return futureResult
.thenApplyQueryResult()
.thenAccept(
it -> writeResultResponse(futureResult.getInvocationInput(), it, request, response))
it -> {
listenerHandler.beforeFlush();
writeResultResponse(futureResult.getInvocationInput(), it, request, response);
})
.thenAccept(it -> listenerHandler.onSuccess())
.exceptionally(
t ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ void runCallbacks(Consumer<RequestCallback> action) {
});
}

void beforeFlush() {
runCallbacks(it -> it.beforeFlush(request, response));
}

void onSuccess() {
runCallbacks(it -> it.onSuccess(request, response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,50 @@
/** @author Andrew Potter */
public interface GraphQLServletListener {

/**
* Called this method when the request started processing.
* @param request http request
* @param response http response
* @return request callback or {@literal null}
*/
default RequestCallback onRequest(HttpServletRequest request, HttpServletResponse response) {
return null;
}

/**
* The callback which used to add additional listeners for GraphQL request execution.
*/
interface RequestCallback {

/**
* Called right before the response will be written and flushed. Can be used for applying some
* changes to the response object, like adding response headers.
* @param request http request
* @param response http response
*/
default void beforeFlush(HttpServletRequest request, HttpServletResponse response) {}

/**
* Called when GraphQL invoked successfully and the response was written already.
* @param request http request
* @param response http response
*/
default void onSuccess(HttpServletRequest request, HttpServletResponse response) {}

/**
* Called when GraphQL was failed and the response was written already.
* @param request http request
* @param response http response
*/
default void onError(
HttpServletRequest request, HttpServletResponse response, Throwable throwable) {}

/**
* Called finally once on both success and failed GraphQL invocation. The response is also
* already written.
* @param request http request
* @param response http response
*/
default void onFinally(HttpServletRequest request, HttpServletResponse response) {}
}
}

0 comments on commit 290237e

Please sign in to comment.