tgstation-server 6.19.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DataLoaderExtensions.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using GreenDonut;
6using GreenDonut.Data;
7
9
11{
16 {
26 public static async ValueTask<TResult?> LoadAuthorityResponse<TResult>(
27 this IDataLoader<long, AuthorityResponse<TResult>> dataLoader,
28 QueryContext<TResult>? queryContext,
29 long id,
30 CancellationToken cancellationToken)
31 where TResult : class
32 {
33 ArgumentNullException.ThrowIfNull(dataLoader);
34
35 var wrappedQueryContext = queryContext?.AuthorityResponseWrap();
36
37 var branchedDataLoader = dataLoader
38 .With(wrappedQueryContext);
39
40 var authorityResponse = await branchedDataLoader
41 .LoadAsync(id, cancellationToken);
42
43 if (authorityResponse == null)
44 return null;
45
46 GraphQLAuthorityInvoker<IAuthority>.ThrowGraphQLErrorIfNecessary(authorityResponse, false);
47 return authorityResponse.Result;
48 }
49 }
50}
Extension methods for IDataLoader<TKey, TValue>.
static async ValueTask< TResult?> LoadAuthorityResponse< TResult >(this IDataLoader< long, AuthorityResponse< TResult > > dataLoader, QueryContext< TResult >? queryContext, long id, CancellationToken cancellationToken)
Convert a request for a single TResult into a data-loader invocation for the matching AuthorityRespo...