Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b79e112
commit b6f40a4
Showing
58 changed files
with
2,125 additions
and
1,020 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
14 changes: 14 additions & 0 deletions
14
src/CookieCrumble/src/CookieCrumble/Formatters/QueryPlanSnapshotValueFormatter.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,14 @@ | ||
#if NET6_0_OR_GREATER | ||
using System.Buffers; | ||
using HotChocolate.Fusion.Planning; | ||
|
||
namespace CookieCrumble.Formatters; | ||
|
||
internal sealed class QueryPlanSnapshotValueFormatter : SnapshotValueFormatter<QueryPlan> | ||
{ | ||
protected override void Format(IBufferWriter<byte> snapshot, QueryPlan value) | ||
{ | ||
value.Format(snapshot); | ||
} | ||
} | ||
#endif |
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
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
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
13 changes: 13 additions & 0 deletions
13
src/HotChocolate/Core/src/Execution/Serialization/RawJsonValue.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,13 @@ | ||
using System; | ||
|
||
namespace HotChocolate.Execution.Serialization; | ||
|
||
internal readonly struct RawJsonValue | ||
{ | ||
public RawJsonValue(ReadOnlyMemory<byte> value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public ReadOnlyMemory<byte> Value { get; } | ||
} |
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
114 changes: 114 additions & 0 deletions
114
src/HotChocolate/Fusion/src/Core/Execution/ExecutionState.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,114 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using HotChocolate.Execution.Processing; | ||
|
||
namespace HotChocolate.Fusion.Execution; | ||
|
||
internal sealed class ExecutionState : IExecutionState | ||
{ | ||
private readonly Dictionary<ISelectionSet, List<WorkItem>> _map = new(); | ||
private readonly HashSet<ISelectionSet> _immutable = new(); | ||
|
||
public bool ContainsState(ISelectionSet selectionSet) | ||
{ | ||
var taken = false; | ||
Monitor.Enter(_map, ref taken); | ||
|
||
try | ||
{ | ||
return _map.ContainsKey(selectionSet); | ||
} | ||
finally | ||
{ | ||
if (taken) | ||
{ | ||
Monitor.Exit(_map); | ||
} | ||
} | ||
} | ||
|
||
public bool TryGetState( | ||
ISelectionSet selectionSet, | ||
[NotNullWhen(true)] out IReadOnlyList<WorkItem>? values) | ||
{ | ||
var taken = false; | ||
Monitor.Enter(_map, ref taken); | ||
|
||
try | ||
{ | ||
// We mark a value immutable on first read. | ||
// | ||
// After we accessed the first time the state of a selection set its no longer allowed | ||
// to mutate it. | ||
// | ||
// The query plan should actually be ordered in a way that there are no mutations after | ||
// the state is being read from nodes. | ||
_immutable.Add(selectionSet); | ||
|
||
if (_map.TryGetValue(selectionSet, out var local)) | ||
{ | ||
values = local; | ||
return true; | ||
} | ||
else | ||
{ | ||
values = null; | ||
return false; | ||
} | ||
} | ||
finally | ||
{ | ||
if (taken) | ||
{ | ||
Monitor.Exit(_map); | ||
} | ||
} | ||
} | ||
|
||
public void RegisterState(WorkItem value) | ||
{ | ||
var taken = false; | ||
List<WorkItem>? values; | ||
Monitor.Enter(_map, ref taken); | ||
|
||
try | ||
{ | ||
if (_immutable.Contains(value.SelectionSet)) | ||
{ | ||
throw new InvalidOperationException( | ||
$"The state for the selection set `{value.SelectionSet.Id}` is immutable."); | ||
} | ||
|
||
if (!_map.TryGetValue(value.SelectionSet, out values)) | ||
{ | ||
var temp = new List<WorkItem> { value }; | ||
_map.Add(value.SelectionSet, temp); | ||
} | ||
} | ||
finally | ||
{ | ||
if (taken) | ||
{ | ||
Monitor.Exit(_map); | ||
} | ||
} | ||
|
||
if (values is not null) | ||
{ | ||
taken = false; | ||
Monitor.Enter(values, ref taken); | ||
|
||
try | ||
{ | ||
values.Add(value); | ||
} | ||
finally | ||
{ | ||
if (taken) | ||
{ | ||
Monitor.Exit(values); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.