public async Task InvokeAsync(IMiddlewareContext context)
        {
            await _next(context).ConfigureAwait(false);

            IValueNode filter = context.ArgumentLiteral <IValueNode>(_contextData.ArgumentName);

            if (filter is NullValueNode)
            {
                return;
            }

            IQueryable <T>?source = null;

            if (context.Result is IQueryable <T> q)
            {
                source = q;
            }
            else if (context.Result is IEnumerable <T> e)
            {
                source = e.AsQueryable();
            }

            if (source is not null &&
                context.Field.Arguments[_contextData.ArgumentName].Type is InputObjectType iot &&
                iot is IFilterInputType fit)
            {
                var visitorContext = new QueryableFilterVisitorContext(
                    iot, fit.EntityType, _converter, source is EnumerableQuery);
                QueryableFilterVisitor.Default.Visit(filter, visitorContext);

                source = source.Where(visitorContext.CreateFilter <T>());

                context.Result = source;
            }
        }
Example #2
0
        public async Task InvokeAsync(IMiddlewareContext context)
        {
            await _next(context).ConfigureAwait(false);

            IValueNode sortArg = context.ArgumentLiteral <IValueNode>(_contextData.ArgumentName);

            if (sortArg is NullValueNode)
            {
                return;
            }

            IQueryable <T>?source = null;

            if (context.Result is IQueryable <T> q)
            {
                source = q;
            }
            else if (context.Result is IEnumerable <T> e)
            {
                source = e.AsQueryable();
            }

            if (source is not null &&
                context.Field.Arguments[_contextData.ArgumentName].Type is InputObjectType iot &&
                iot is ISortInputType {
                EntityType : not null
            } fit)
            {
                var visitorCtx = new QueryableSortVisitorContext(
                    context.Service <InputParser>(),
                    iot,
                    fit.EntityType,
                    source is EnumerableQuery);

                QueryableSortVisitor.Default.Visit(sortArg, visitorCtx);

                source         = visitorCtx.Sort(source);
                context.Result = source;
            }
        }
        public async Task InvokeAsync(IMiddlewareContext context)
        {
            await _next(context).ConfigureAwait(false);

            IValueNode filter = context.ArgumentLiteral <IValueNode>("where");

            if (filter is null || filter is NullValueNode)
            {
                return;
            }

            IQueryable <T> source = null;

            if (context.Result is IQueryable <T> q)
            {
                source = q;
            }
            else if (context.Result is IEnumerable <T> e)
            {
                source = e.AsQueryable();
            }

            if (source != null &&
                context.Field.Arguments["where"].Type is InputObjectType iot &&
                iot is IFilterInputType fit)
            {
                var visitor = new QueryableFilterVisitor(
                    iot,
                    fit.EntityType,
                    _converter);
                filter.Accept(visitor);

                source         = source.Where(visitor.CreateFilter <T>());
                context.Result = source;
            }
        }