コード例 #1
0
        FieldType BuildQueryField <TSource, TReturn>(
            string name,
            Func <ResolveFieldContext <TSource>, IQueryable <TReturn> > resolve,
            IEnumerable <QueryArgument> arguments,
            Type graphType)
            where TReturn : class
        {
            Guard.AgainstNullWhiteSpace(nameof(name), name);
            Guard.AgainstNull(nameof(resolve), resolve);
            graphType = GraphTypeFinder.FindGraphType <TReturn>(graphType);
            var listGraphType = MakeListGraphType(graphType);

            return(new FieldType
            {
                Name = name,
                Type = listGraphType,
                Arguments = ArgumentAppender.GetQueryArguments(arguments),
                Resolver = new AsyncFieldResolver <TSource, IEnumerable <TReturn> >(
                    async context =>
                {
                    var returnTypes = resolve(context);
                    var withIncludes = includeAppender.AddIncludes(returnTypes, context);
                    var withArguments = withIncludes.ApplyGraphQlArguments(context);
                    var list = await withArguments.ToListAsync(context.CancellationToken);
                    return await filters.ApplyFilter(list, context.UserContext);
                })
            });
        }
コード例 #2
0
 public IQueryable <TItem> AddIncludes <TItem>(IQueryable <TItem> query, IResolveFieldContext context)
     where TItem : class
 {
     return(includeAppender.AddIncludes(query, context));
 }