-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootBatchResolver.cs
31 lines (27 loc) · 921 Bytes
/
RootBatchResolver.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GraphQL.Resolvers;
using GraphQL.Types;
namespace GraphQL.BatchResolver
{
/// <summary>
/// Adds support for resolving collections in a batch.
/// </summary>
public class RootBatchResolver<TReturn> : IFieldResolver
{
private readonly Func<ResolveFieldContext, Task<IEnumerable<TReturn>>> _resolve;
public RootBatchResolver(Func<ResolveFieldContext, Task<IEnumerable<TReturn>>> resolve)
{
_resolve = resolve;
}
public Task<IEnumerable<TReturn>> Resolve(ResolveFieldContext context)
{
return _resolve(context).ContinueWith(t => BatchStack.Push(t.Result), TaskContinuationOptions.ExecuteSynchronously);
}
object IFieldResolver.Resolve(ResolveFieldContext context)
{
return Resolve(context);
}
}
}