Add empty "data:" field for SSE complete event
Prior to this commit, the "event:complete" event would have no "data:" field when completing the stream of data. This can cause problems with browsers, as the `EventSource` callback might not get called without it. This commit ensures that an empty data field is present in all cases. Fixes gh-940
This commit is contained in:
@@ -54,7 +54,7 @@ public class GraphQlSseHandler {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQlSseHandler.class);
|
||||
|
||||
private static final Mono<ServerSentEvent<Map<String, Object>>> COMPLETE_EVENT = Mono.just(ServerSentEvent.<Map<String, Object>>builder().event("complete").build());
|
||||
private static final Mono<ServerSentEvent<Map<String, Object>>> COMPLETE_EVENT = Mono.just(ServerSentEvent.<Map<String, Object>>builder(Collections.emptyMap()).event("complete").build());
|
||||
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class GraphQlSseHandler extends AbstractGraphQlHttpHandler {
|
||||
@Override
|
||||
protected void hookOnComplete() {
|
||||
try {
|
||||
this.sseBuilder.event("complete").send();
|
||||
this.sseBuilder.event("complete").data("");
|
||||
} catch (IOException exc) {
|
||||
throw new RuntimeException(exc);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ class GraphQlSseHandlerTests {
|
||||
data:{"errors":[{"message":"SSE transport only supports Subscription operations","locations":[],"extensions":{"classification":"OperationNotSupported"}}]}
|
||||
|
||||
event:complete
|
||||
data:{}
|
||||
|
||||
""");
|
||||
}
|
||||
@@ -96,7 +97,8 @@ class GraphQlSseHandlerTests {
|
||||
data:{"data":{"bookSearch":{"id":"5","name":"Animal Farm"}}}
|
||||
|
||||
event:complete
|
||||
|
||||
data:{}
|
||||
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -118,6 +120,7 @@ class GraphQlSseHandlerTests {
|
||||
data:{"errors":[{"message":"Subscription error","locations":[],"extensions":{"classification":"INTERNAL_ERROR"}}]}
|
||||
|
||||
event:complete
|
||||
data:{}
|
||||
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class GraphQlSseHandlerTests {
|
||||
data:{"errors":[{"message":"SSE transport only supports Subscription operations","locations":[],"extensions":{"classification":"OperationNotSupported"}}]}
|
||||
|
||||
event:complete
|
||||
data:
|
||||
|
||||
""");
|
||||
}
|
||||
@@ -95,7 +96,8 @@ class GraphQlSseHandlerTests {
|
||||
data:{"data":{"bookSearch":{"id":"5","name":"Animal Farm"}}}
|
||||
|
||||
event:complete
|
||||
|
||||
data:
|
||||
|
||||
""");
|
||||
}
|
||||
|
||||
@@ -121,7 +123,8 @@ class GraphQlSseHandlerTests {
|
||||
data:{"errors":[{"message":"Subscription error","locations":[],"extensions":{"classification":"INTERNAL_ERROR"}}]}
|
||||
|
||||
event:complete
|
||||
|
||||
data:
|
||||
|
||||
""");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user