-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserContext.cs
28 lines (25 loc) · 950 Bytes
/
UserContext.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
using DataLoader;
using GraphQL.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GraphQL.Benchmarks
{
public class UserContext
{
public StarWarsContext DataContext { get; set; } = new StarWarsContext();
public DataLoaderContext LoadContext { get; set; }
}
public static class UserContextExtensions
{
public static StarWarsContext GetDataContext<T>(this ResolveFieldContext<T> context)
{
return ((UserContext)context.UserContext).DataContext;
}
public static IDataLoader<int, TReturn> GetDataLoader<TSource, TReturn>(this ResolveFieldContext<TSource> context, Func<IEnumerable<int>, Task<ILookup<int, TReturn>>> fetchDelegate)
{
return ((UserContext)context.UserContext).LoadContext.GetLoader(context.FieldDefinition, fetchDelegate);
}
}
}