// Batching when field is a list public IList <OtherThing> GetOtherThings(IFieldContext context, Thing parent) { var allParents = context.GetAllParentEntities <Thing>(); var batchedResults = allParents.ToDictionary(p => p, p => p.OtherThings); context.SetBatchedResults(batchedResults, new List <OtherThing>()); return(null); // the engine will lookup result for this field in batched results }
// Batching when field is a list public IList <OtherThing> GetOtherThings(IFieldContext context, Thing parent) { var allParents = context.GetAllParentEntities <Thing>(); var batchedResults = allParents.ToDictionary(p => p, p => p.OtherThings); context.SetBatchedResults(batchedResults); return(batchedResults[parent]); }
// Demo of BATCHing functionality (aka DataLoader) - loading field values for ALL parent objects in request public OtherThing GetMainOtherThing(IFieldContext context, Thing parent) { var allParents = context.GetAllParentEntities <Thing>(); var batchedResults = allParents.ToDictionary(p => p, p => p.MainOtherThing); context.SetBatchedResults(batchedResults); return(parent.MainOtherThing); }
// Demo of BATCHing functionality (aka DataLoader) - loading field values for ALL parent objects in request public OtherThing GetMainOtherThing(IFieldContext context, Thing parent) { var allParents = context.GetAllParentEntities <Thing>(); var batchedResults = allParents.ToDictionary(p => p, p => p.MainOtherThing); context.SetBatchedResults(batchedResults, null); // return parent.MainOtherThing; return(null); // the engine will lookup result for this field in batched results }
// batched version of GetStarships public IList <Starship> GetStarshipsBatched(IFieldContext fieldContext, Human human) { // batch execution; we retrieve all pending parents (humans), // get all their starships to a dictionary, and then post it back into context - // the engine will use this dictionary to lookup values and will not call resolver anymore var allParents = fieldContext.GetAllParentEntities <Human>(); var shipsByHuman = allParents.ToDictionary(h => h, h => h.Starships); fieldContext.SetBatchedResults <Human, IList <Starship> >(shipsByHuman, valueForMissingKeys: new List <Starship>()); return(null); // the engine will use batch results dict to lookup the value }