|
6 | 6 | /** @author Andrew Potter */
|
7 | 7 | public interface GraphQLServletListener {
|
8 | 8 |
|
| 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 | + */ |
9 | 15 | default RequestCallback onRequest(HttpServletRequest request, HttpServletResponse response) {
|
10 | 16 | return null;
|
11 | 17 | }
|
12 | 18 |
|
| 19 | + /** |
| 20 | + * The callback which used to add additional listeners for GraphQL request execution. |
| 21 | + */ |
13 | 22 | interface RequestCallback {
|
14 | 23 |
|
| 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 | + */ |
15 | 37 | default void onSuccess(HttpServletRequest request, HttpServletResponse response) {}
|
16 | 38 |
|
| 39 | + /** |
| 40 | + * Called when GraphQL was failed and the response was written already. |
| 41 | + * @param request http request |
| 42 | + * @param response http response |
| 43 | + */ |
17 | 44 | default void onError(
|
18 | 45 | HttpServletRequest request, HttpServletResponse response, Throwable throwable) {}
|
19 | 46 |
|
| 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 | + */ |
20 | 53 | default void onFinally(HttpServletRequest request, HttpServletResponse response) {}
|
21 | 54 | }
|
22 | 55 | }
|
0 commit comments