示例#1
0
        // 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
        }
示例#2
0
        // 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]);
        }
示例#3
0
        // 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);
        }
示例#4
0
        // 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
        }
示例#5
0
        // 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
        }