Exemplo n.º 1
0
        public async Task <IEnumerable <Owner> > GetOwnersByAddress(string address, IResolverContext context)
        {
            IDataLoader <string, Owner[]> ownerDataLoader =
                context.GroupDataLoader <string, Owner>(
                    "ownersByAddress",
                    _ownerRepository.GetOwnersByAddress);

            return(await ownerDataLoader.LoadAsync(context.Argument <string>("address")));
        }
Exemplo n.º 2
0
        public async Task <Comment[]> Comments([Parent] Post post, IResolverContext context)
        {
            var dataLoader = context.GroupDataLoader <int, Comment>("postComments", async keys =>
            {
                var db       = CreateDataContext();
                var comments = await db.Comments.Where(c => keys.Contains(c.PostId)).ToListAsync();
                return(comments.ToLookup(c => c.PostId));
            });

            return(await dataLoader.LoadAsync(post.Id, CancellationToken.None));
        }
Exemplo n.º 3
0
        public async Task <Tag[]> Tags([Parent] Post post, IResolverContext context)
        {
            var dataLoader = context.GroupDataLoader <int, Tag>("postTags", async keys =>
            {
                var db = CreateDataContext();
                var q  = from pt in db.PostTags
                         join t in db.Tags on pt.TagId equals t.Id
                         where keys.Contains(pt.PostId)
                         select new { pt.PostId, Tag = t };

                var children = await q.ToListAsync();
                return(children.ToLookup(c => c.PostId, c => c.Tag));
            });

            return(await dataLoader.LoadAsync(post.Id, CancellationToken.None));
        }
Exemplo n.º 4
0
        public async Task <Post[]> Posts([Parent] Tag tag, IResolverContext context)
        {
            var dataLoader = context.GroupDataLoader <int, Post>("tagPosts", async keys =>
            {
                var db = CreateDataContext();
                var q  = from pt in db.PostTags
                         join p in db.Posts on pt.PostId equals p.Id
                         where keys.Contains(pt.TagId)
                         select new { pt.TagId, Post = p };

                var children = await q.ToListAsync();
                return(children.ToLookup(c => c.TagId, c => c.Post));
            });

            return(await dataLoader.LoadAsync(tag.Id, CancellationToken.None));
        }