Beispiel #1
0
        public async Task <IReadOnlyList <Book> > GetBooks(IResolverContext context)
        {
            _requestCount = 0;
            var ids = Enumerable.Range(0, 100).ToImmutableList();

            await Task.Delay(1);

            var books = await context.BatchDataLoader(
                async (IReadOnlyList <int> bookIds, CancellationToken t) => {
                Interlocked.Increment(ref _requestCount);
                if (_requestCount > 1)
                {
                    throw new Exception("Nope!");
                }

                var data = bookIds.Select(
                    x => new Book
                {
                    Title  = "C# in depth",
                    Author = "Jon Skeet",
                    Id     = x
                }
                    );

                IReadOnlyDictionary <int, Book> result = data.ToDictionary(x => x.Id);
                await Task.Delay(1);
                return(result);
            }).LoadAsync(ids, context.RequestAborted);

            return(books.ToList());
        }
Beispiel #2
0
        private static async Task <int> ResolveInventory(this IResolverContext context)
        {
            var dataLoader = context.BatchDataLoader <Guid, int>(
                "availableById",
                context.Service <Cheeze.Inventory.Client.IInventoryClient>().FetchInventory);

            return(await dataLoader.LoadAsync(context.Parent <Cheese>().Id, context.RequestAborted));
        }
Beispiel #3
0
        public async Task <Industry> GetIndustry([ScopedService] MyContext dbcontext, int id,
                                                 IResolverContext context, CancellationToken token)
        {
            return(await context.BatchDataLoader <int, Industry>(async (ids, ct) =>
            {
                var result = await dbcontext.Industries
                             .Where(x => ids.Contains(x.Id))
                             .ToListAsync();

                return result.ToDictionary(x => x.Id);
            })
                   .LoadAsync(id, token));
        }
Beispiel #4
0
        /// <summary>
        /// Loads entities with BatchDataLoader
        /// </summary>
        /// <param name="context"></param>
        /// <param name="dataLoaderKey"></param>
        /// <param name="key"></param>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <returns></returns>
        protected async Task <TValue> LoadByIdAsync <TKey, TValue>(
            IResolverContext context, TKey key)
            where TValue : class, IHasId <TKey>
        {
            var dataLoader = context.BatchDataLoader <TKey, TValue>(typeof(TValue).FullName, async keys =>
            {
                var db = CreateDataContext();
                return(await db.Set <TValue>()
                       .Where(p => keys.Contains(p.Id))
                       .ToDictionaryAsync(p => p.Id));
            });

            return(await dataLoader.LoadAsync(key, CancellationToken.None));
        }
 public static async Task <IEnumerable <Contract> > GetContracts(IResolverContext context, [Parent] Subscriber sub, [Service] SubscriberAdapter data)
 => (await context.BatchDataLoader <int, IEnumerable <int> >("getContractIds", data.GetContractIds).LoadAsync(((Entity)sub).Id))
 .Select(id => new Contract {
     Id = id
 });
 public static async Task <IDictionary <string, string> > GetContactDetails(IResolverContext context, [Parent] Subscriber sub, [Service] SubscriberAdapter data)
 => await context.BatchDataLoader <int, IDictionary <string, string> >("getContactDetails", data.GetContactDetails).LoadAsync(((Entity)sub).Id);
Beispiel #7
0
 public static async Task <long> GetSubscriberId(IResolverContext context, [Parent] Contract contract, [Service] ContractAdapter data)
 => contract.Id != default
         ? await context.BatchDataLoader <int, int>("getSubscriberIdsByIds", data.GetSubscriberIdsByIds).LoadAsync(contract.Id)
         : await context.BatchDataLoader <long, int>("getSubscriberIdsByNums", data.GetSubscriberIdsByNums).LoadAsync(contract.Number);
Beispiel #8
0
 public static async Task <long> GetСontractNumber(IResolverContext context, [Parent] Account account, [Service] AccountAdapter data)
 => account.Id != default
         ? await context.BatchDataLoader <int, long>("getContractNumsByIds", data.GetContractNumsByIds).LoadAsync(account.Id)
         : await context.BatchDataLoader <long, long>("getContractNumsByNums", data.GetContractNumsByNums).LoadAsync(account.Number);
Beispiel #9
0
 public static async Task <decimal> GetBalance(IResolverContext context, [Parent] Account account, [Service] AccountAdapter data)
 => account.Id != default
         ? await context.BatchDataLoader <int, decimal>("getBalancesByIds", data.GetBalancesByIds).LoadAsync(account.Id)
         : await context.BatchDataLoader <long, decimal>("getBalancesByNums", data.GetBalancesByNums).LoadAsync(account.Number);
 public static async Task <long> GetAccountNumber(IResolverContext context, [Parent] SubscriberDevice device, [Service] DeviceAdapter data)
 => device.Id != default
         ? await context.BatchDataLoader <int, long>("getAccountNumbersByIds", data.GetAccountNumbersByIds).LoadAsync(device.Id)
         : await context.BatchDataLoader <long, long>("getAccountNumbersByNums", data.GetAccountNumbersByNums).LoadAsync(device.Number);
 public static async Task <DateTime> GetCreationDate(IResolverContext context, [Parent] SubscriberDevice device, [Service] DeviceAdapter data)
 => device.Id != default
         ? await context.BatchDataLoader <int, DateTime>("getDevicesDatesByIds", data.GetDatesByIds).LoadAsync(device.Id)
         : await context.BatchDataLoader <long, DateTime>("getDevicesDatesByNums", data.GetDatesByNums).LoadAsync(device.Number);
 public static async Task <long> GetNumber(IResolverContext context, [Parent] SubscriberDevice device, [Service] DeviceAdapter data)
 => device.Number = device.Number = device.Number == default
         ? await context.BatchDataLoader <int, long>("getDevicesNumbers", data.GetNumbers).LoadAsync(device.Id)
         : device.Number;
Beispiel #13
0
        public async Task <Client> GetClient([Service] ApplicationDbContext db, IResolverContext context, int id)
        {
            var dataLoader = context.BatchDataLoader <int, Client>(nameof(GetClient), async ids => await db.Clients.Where(c => ids.Contains(c.Id)).ToDictionaryAsync(x => x.Id, x => x));

            return(await dataLoader.LoadAsync(id, context.RequestAborted));
        }
Beispiel #14
0
 public static async Task <int> GetId(IResolverContext context, [Parent] Contract contract, [Service] ContractAdapter data)
 => contract.Id = contract.Id == default
         ? await context.BatchDataLoader <long, int>("getContractsIds", data.GetIds).LoadAsync(contract.Id)
         : contract.Id;
 public static async Task <string> GetPhysicalPersonMiddleName(IResolverContext context, [Parent] Subscriber sub, [Service] SubscriberAdapter data)
 => (await context.BatchDataLoader <int, string>("getFullNames", data.GetFullNames).LoadAsync(((Entity)sub).Id)).Split(' ')[2];
 public static async Task <string> GetLegalPersonForm(IResolverContext context, [Parent] Subscriber sub, [Service] SubscriberAdapter data)
 => await context.BatchDataLoader <int, string>("getForms", data.GetForms).LoadAsync(((Entity)sub).Id);
 public static async Task <int> GetId(IResolverContext context, [Parent] SubscriberDevice device, [Service] DeviceAdapter data)
 => device.Id = device.Id == default
         ? await context.BatchDataLoader <long, int>("getContractsIds", data.GetIds).LoadAsync(device.Id)
         : device.Id;
Beispiel #18
0
 public static async Task <long> GetNumber(IResolverContext context, [Parent] Account account, [Service] AccountAdapter data)
 => account.Number = account.Number == default
         ? await context.BatchDataLoader <int, long>("getAccountsNumbers", data.GetNumbersByIds).LoadAsync(account.Id)
         : account.Number;
        public async Task <PersistedGrant> GetPersistedGrant([Service] ApplicationDbContext db, IResolverContext context, string key)
        {
            var dataLoader = context.BatchDataLoader <string, PersistedGrant>(nameof(GetPersistedGrant), async keys => await db.PersistedGrants.Where(c => keys.Contains(c.Key)).ToDictionaryAsync(x => x.Key, x => x));

            return(await dataLoader.LoadAsync(key, context.RequestAborted));
        }
Beispiel #20
0
 public static async Task <DateTime> GetCreationDate(IResolverContext context, [Parent] Account account, [Service] AccountAdapter data)
 => account.Id != default
         ? await context.BatchDataLoader <int, DateTime>("getAccountsDatesByIds", data.GetDatesByIds).LoadAsync(account.Id)
         : await context.BatchDataLoader <long, DateTime>("GetAccountsDatesByNums", data.GetDatesByNums).LoadAsync(account.Number);
Beispiel #21
0
        /*
         * public Task<Person> GetPerson(string id, IResolverContext context, [Service]IPersonRepository repository)
         * {
         *  return context.BatchDataLoader<string, Person>("personByIdBatch", keys => repository.GetPersonBatchAsync(keys)).LoadAsync(id);
         * }
         */

        public Task <userApp> GetPerson(string id, IResolverContext context)
        {
            return(context.BatchDataLoader <string, userApp>("personByIdBatch", async keys => await _context.UserApp.ToDictionaryAsync(mc => mc.userAppId)).LoadAsync(id));
        }
Beispiel #22
0
 public static async Task <int> GetId(IResolverContext context, [Parent] Account account, [Service] AccountAdapter data)
 => account.Id = account.Id == default
         ? await context.BatchDataLoader <long, int>("getAccountsIds", data.GetIds).LoadAsync(account.Id)
         : account.Id;
 public async Task <TableType> Table(OrderType order, IResolverContext context, [Service] ITableService tableService)
 {
     return(await context.BatchDataLoader <Guid, TableType>("tableById", ids => tableService.GetTablesAsync(ids))
            .LoadAsync(order.TableId, default(CancellationToken)));
 }
Beispiel #24
0
        public async Task <DeviceCode> GetDeviceCode([Service] ApplicationDbContext db, IResolverContext context, string userCode)
        {
            var dataLoader = context.BatchDataLoader <string, DeviceCode>(nameof(GetDeviceCode), async userCodes => await db.DeviceCodes.Where(c => userCodes.Contains(c.UserCode)).ToDictionaryAsync(x => x.UserCode, x => x));

            return(await dataLoader.LoadAsync(userCode, context.RequestAborted));
        }
Beispiel #25
0
 public static async Task <long> GetNumber(IResolverContext context, [Parent] Contract contract, [Service] ContractAdapter data)
 => contract.Number = contract.Number = contract.Number == default
         ? await context.BatchDataLoader <int, long>("getContractsNumbers", data.GetNumbers).LoadAsync(contract.Id)
         : contract.Number;