コード例 #1
0
        private static async Task <object> ResolveProductsConnectionAsync(IMediator mediator, IResolveConnectionContext <object> context)
        {
            var first         = context.First;
            var skip          = Convert.ToInt32(context.After ?? 0.ToString());
            var includeFields = context.SubFields.Values.GetAllNodesPaths();

            //TODO: Need to be able get entire query from context and read all arguments to the query properties
            var query = context.GetCatalogQuery <SearchProductQuery>();

            query.IncludeFields = includeFields;

            var productIds = context.GetArgument <List <string> >("productIds");

            if (productIds.IsNullOrEmpty())
            {
                query.Skip       = skip;
                query.Take       = first ?? context.PageSize ?? 10;
                query.Query      = context.GetArgument <string>("query");
                query.Filter     = context.GetArgument <string>("filter");
                query.Facet      = context.GetArgument <string>("facet");
                query.Fuzzy      = context.GetArgument <bool>("fuzzy");
                query.FuzzyLevel = context.GetArgument <int?>("fuzzyLevel");
                query.Sort       = context.GetArgument <string>("sort");
            }
            else
            {
                query.ObjectIds = productIds.ToArray();
                query.Take      = productIds.Count;
            }

            var response = await mediator.Send(query);

            var currencyCode = context.GetArgumentOrValue <string>("currencyCode");

            if (string.IsNullOrWhiteSpace(currencyCode))
            {
                context.SetCurrency(response.Currency);
            }

            var result = new ProductsConnection <ExpProduct>(response.Results, skip, Convert.ToInt32(context.After ?? 0.ToString()), response.TotalCount)
            {
                Facets = response.Facets
            };

            return(result);
        }