Ejemplo n.º 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
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
        }
Ejemplo n.º 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
        }