public async Task <object> ResolveInternal(ResolveFieldContext context)
        {
            var key = _keySelector((TSource)context.Source);

            var tableKey = context.Document;
            Task <ILookup <TKey, TReturn> > task = null;

            if (!_resultsTable.TryGetValue(tableKey, out task))
            {
                var currentBatch = BatchStack.Peek();
                context.Source = BatchStack.Peek().OfType <TSource>().Select(_keySelector).Distinct();

                task = _resolver(new ResolveFieldContext <IEnumerable <TKey> >(context));
                _resultsTable.Add(tableKey, task);

                var newBatch = await task.ConfigureAwait(false);

                return(BatchStack.Push(newBatch.SelectMany(x => x.ToList()), newBatch[key]));
            }

            return((await task.ConfigureAwait(false))[key]);
        }
Example #2
0
 public Task <IEnumerable <TReturn> > Resolve(ResolveFieldContext context)
 {
     return(_resolve(context).ContinueWith(t => BatchStack.Push(t.Result), TaskContinuationOptions.ExecuteSynchronously));
 }