Skip to content

Commit

Permalink
Tweaked GraphQL-SSE message spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 27, 2022
1 parent aae645e commit d7f5904
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Expand Up @@ -907,14 +907,14 @@ public async Task New_Query_With_Streams_3()
-------------------------->
Status Code: OK
-------------------------->
event:next
event: next
data: {""data"":{},""hasNext"":true}
event:next
event: next
data: {""incremental"":[{""data"":{""__typename"":""Query""}," +
@"""path"":[]}],""hasNext"":false}
event:complete
event: complete
");
}
Expand Down
Expand Up @@ -15,13 +15,13 @@ namespace HotChocolate.Execution.Serialization;
/// </summary>
public sealed class EventStreamResultFormatter : IExecutionResultFormatter
{
private static readonly byte[] EventField
= { (byte)'e', (byte)'v', (byte)'e', (byte)'n', (byte)'t', (byte)':' };
private static readonly byte[] DataField
private static readonly byte[] _eventField
= { (byte)'e', (byte)'v', (byte)'e', (byte)'n', (byte)'t', (byte)':', (byte)' ' };
private static readonly byte[] _dataField
= { (byte)'d', (byte)'a', (byte)'t', (byte)'a', (byte)':', (byte)' ' };
private static readonly byte[] NextEvent
private static readonly byte[] _nextEvent
= { (byte)'n', (byte)'e', (byte)'x', (byte)'t' };
private static readonly byte[] CompleteEvent
private static readonly byte[] _completeEvent
=
{
(byte)'c', (byte)'o', (byte)'m', (byte)'p',
Expand Down Expand Up @@ -116,12 +116,12 @@ await WriteNextMessageAsync(queryResult, outputStream)
private async ValueTask WriteNextMessageAsync(IQueryResult result, Stream outputStream)
{
#if NETCOREAPP3_1_OR_GREATER
await outputStream.WriteAsync(EventField).ConfigureAwait(false);
await outputStream.WriteAsync(NextEvent).ConfigureAwait(false);
await outputStream.WriteAsync(_eventField).ConfigureAwait(false);
await outputStream.WriteAsync(_nextEvent).ConfigureAwait(false);
await outputStream.WriteAsync(_newLine).ConfigureAwait(false);
#else
await outputStream.WriteAsync(EventField, 0, EventField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(NextEvent, 0, NextEvent.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_eventField, 0, _eventField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_nextEvent, 0, _nextEvent.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_newLine, 0, _newLine.Length).ConfigureAwait(false);
#endif

Expand All @@ -141,11 +141,11 @@ await using (var writer = new Utf8JsonWriter(bufferWriter, _options))
}

#if NETCOREAPP3_1_OR_GREATER
await outputStream.WriteAsync(DataField).ConfigureAwait(false);
await outputStream.WriteAsync(_dataField).ConfigureAwait(false);
await outputStream.WriteAsync(buffer).ConfigureAwait(false);
await outputStream.WriteAsync(_newLine).ConfigureAwait(false);
#else
await outputStream.WriteAsync(DataField, 0, DataField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_dataField, 0, _dataField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(bufferWriter.GetInternalBuffer(), read, buffer.Length)
.ConfigureAwait(false);
await outputStream.WriteAsync(_newLine, 0, _newLine.Length).ConfigureAwait(false);
Expand All @@ -158,12 +158,12 @@ await outputStream.WriteAsync(bufferWriter.GetInternalBuffer(), read, buffer.Len
private static async ValueTask WriteCompleteMessage(Stream outputStream)
{
#if NETCOREAPP3_1_OR_GREATER
await outputStream.WriteAsync(EventField).ConfigureAwait(false);
await outputStream.WriteAsync(CompleteEvent).ConfigureAwait(false);
await outputStream.WriteAsync(_eventField).ConfigureAwait(false);
await outputStream.WriteAsync(_completeEvent).ConfigureAwait(false);
await outputStream.WriteAsync(_newLine).ConfigureAwait(false);
#else
await outputStream.WriteAsync(EventField, 0, EventField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(CompleteEvent, 0, CompleteEvent.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_eventField, 0, _eventField.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_completeEvent, 0, _completeEvent.Length).ConfigureAwait(false);
await outputStream.WriteAsync(_newLine, 0, _newLine.Length).ConfigureAwait(false);
#endif
}
Expand Down

0 comments on commit d7f5904

Please sign in to comment.