Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added In-Memory Subscription Support (#2083)
- Loading branch information
1 parent
a298447
commit 0e5e995
Showing
93 changed files
with
1,538 additions
and
2,721 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/HotChocolate/Core/benchmark/StarWars/OnReviewMessage.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/HotChocolate/Core/src/Abstractions/Execution/IQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
public interface IQueryResult | ||
: IExecutionResult | ||
, IDisposable | ||
{ | ||
IReadOnlyDictionary<string, object?>? Data { get; } | ||
|
||
IReadOnlyDictionary<string, object?> ToDictionary(); | ||
} | ||
} |
12 changes: 3 additions & 9 deletions
12
src/HotChocolate/Core/src/Abstractions/Execution/IReadOnlyQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
// todo : deprecate this interface and use IQueryResult | ||
public interface IReadOnlyQueryResult | ||
: IExecutionResult | ||
, IDisposable | ||
: IQueryResult | ||
{ | ||
IReadOnlyDictionary<string, object?>? Data { get; } | ||
|
||
IReadOnlyDictionary<string, object?> ToDictionary(); | ||
} | ||
} |
16 changes: 14 additions & 2 deletions
16
src/HotChocolate/Core/src/Abstractions/Execution/IResponseStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
public interface IResponseStream : IAsyncEnumerable<IReadOnlyQueryResult> | ||
/// <summary> | ||
/// The response stream represents a stream of <see cref="IQueryResult" /> that are produced | ||
/// by the execution engine. | ||
/// </summary> | ||
public interface IResponseStream | ||
: IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// Reads the subscription results from the execution engine. | ||
/// </summary> | ||
IAsyncEnumerable<IQueryResult> ReadResultsAsync(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/HotChocolate/Core/src/Abstractions/Execution/ISourceStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
/// <summary> | ||
/// The source stream represents a stream of events from a pub/sub system. | ||
/// </summary> | ||
public interface ISourceStream | ||
: IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// Reads the subscription result from the pub/sub system. | ||
/// </summary> | ||
IAsyncEnumerable<object> ReadEventsAsync(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/HotChocolate/Core/src/Abstractions/Execution/ISourceStream~1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
/// <summary> | ||
/// The source stream represents a stream of events from a pub/sub system. | ||
/// </summary> | ||
public interface ISourceStream<TMessage> | ||
: ISourceStream | ||
{ | ||
/// <summary> | ||
/// Reads the subscription result from the pub/sub system. | ||
/// </summary> | ||
new IAsyncEnumerable<TMessage> ReadEventsAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/HotChocolate/Core/src/Abstractions/Execution/SubscriptionResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
public sealed class SubscriptionResult | ||
: ISubscriptionResult | ||
{ | ||
private readonly Func<IAsyncEnumerable<IQueryResult>>? _resultStreamFactory; | ||
private readonly IReadOnlyList<IError>? _errors; | ||
private readonly IReadOnlyDictionary<string, object?>? _extensions; | ||
private readonly IReadOnlyDictionary<string, object?>? _contextData; | ||
private readonly IAsyncDisposable? _subscription; | ||
private bool _isRead = false; | ||
private bool _disposed = false; | ||
|
||
public SubscriptionResult( | ||
Func<IAsyncEnumerable<IQueryResult>>? resultStreamFactory, | ||
IReadOnlyList<IError>? errors, | ||
IReadOnlyDictionary<string, object?>? extensions = null, | ||
IReadOnlyDictionary<string, object?>? contextData = null, | ||
IAsyncDisposable? subscription = null) | ||
{ | ||
if (resultStreamFactory is null && errors is null) | ||
{ | ||
throw new ArgumentException("Either provide a result stream factory or errors."); | ||
} | ||
|
||
_resultStreamFactory = resultStreamFactory; | ||
_errors = errors; | ||
_extensions = extensions; | ||
_contextData = contextData; | ||
_subscription = subscription; | ||
} | ||
|
||
public IReadOnlyList<IError>? Errors => _errors; | ||
|
||
public IReadOnlyDictionary<string, object?>? Extensions => _extensions; | ||
|
||
public IReadOnlyDictionary<string, object?>? ContextData => _contextData; | ||
|
||
public IAsyncEnumerable<IQueryResult> ReadResultsAsync() | ||
{ | ||
if (_resultStreamFactory is null) | ||
{ | ||
// todo : throw helper | ||
throw new InvalidOperationException( | ||
"This result has errors and cannot read from the response stream."); | ||
} | ||
|
||
if (_isRead) | ||
{ | ||
// todo : throw helper | ||
throw new InvalidOperationException( | ||
"You can only read a response stream once."); | ||
} | ||
|
||
if (_disposed) | ||
{ | ||
throw new ObjectDisposedException(nameof(SubscriptionResult)); | ||
} | ||
|
||
_isRead = true; | ||
return _resultStreamFactory(); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
if (!_disposed) | ||
{ | ||
if (_subscription is { }) | ||
{ | ||
await _subscription.DisposeAsync().ConfigureAwait(false); | ||
} | ||
_disposed = true; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.