-
-
Notifications
You must be signed in to change notification settings - Fork 723
/
DeferredFragment.cs
83 lines (71 loc) · 2.41 KB
/
DeferredFragment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections.Immutable;
using System.Threading.Tasks;
using static HotChocolate.Execution.Processing.Tasks.ResolverTaskFactory;
namespace HotChocolate.Execution.Processing;
/// <summary>
/// Represents a deprioritized fragment of the query that will be executed after
/// the main execution has finished.
/// </summary>
internal sealed class DeferredFragment : IDeferredExecutionTask
{
/// <summary>
/// Initializes a new instance of <see cref="DeferredFragment"/>.
/// </summary>
public DeferredFragment(
IFragment fragment,
string? label,
Path path,
object? parent,
IImmutableDictionary<string, object?> scopedContextData)
{
Fragment = fragment;
Label = label;
Path = path;
Parent = parent;
ScopedContextData = scopedContextData;
}
/// <summary>
/// Gets the deferred fragment.
/// </summary>
public IFragment Fragment { get; }
/// <summary>
/// If this argument label has a value other than null, it will be passed
/// on to the result of this defer directive. This label is intended to
/// give client applications a way to identify to which fragment a deferred
/// result belongs to.
/// </summary>
public string? Label { get; }
/// <summary>
/// Gets the result path into which this deferred fragment shall be patched.
/// </summary>
public Path Path { get; }
/// <summary>
/// Gets the parent / source value.
/// </summary>
public object? Parent { get; }
/// <summary>
/// Gets the preserved scoped context from the parent resolver.
/// </summary>
public IImmutableDictionary<string, object?> ScopedContextData { get; }
/// <inheritdoc/>
public IDeferredExecutionTask? Next { get; set; }
/// <inheritdoc/>
public IDeferredExecutionTask? Previous { get; set; }
/// <inheritdoc/>
public async Task<IQueryResult?> ExecuteAsync(IOperationContext operationContext)
{
var parentResult = EnqueueResolverTasks(
operationContext,
Fragment.SelectionSet,
Parent,
Path,
ScopedContextData);
await operationContext.Scheduler.ExecuteAsync().ConfigureAwait(false);
return operationContext
.TrySetNext(true)
.SetLabel(Label)
.SetPath(Path)
.SetData(parentResult)
.BuildResult();
}
}