public Expression HandleLeave(
            SelectionVisitorContext context,
            IFieldSelection selection,
            Expression expression)
        {
            var argumentName = context.SelectionContext.FilterArgumentName;

            if (context.TryGetValueNode(argumentName, out IValueNode? filter) &&
                selection.Field.Arguments[argumentName].Type is InputObjectType iot &&
                iot is IFilterInputType fit)
            {
                var visitorContext = new QueryableFilterVisitorContext(
                    iot, fit.EntityType, context.Conversion, false);

                QueryableFilterVisitor.Default.Visit(filter, visitorContext);

                return(Expression.Call(
                           typeof(Enumerable),
                           "Where",
                           new[] { fit.EntityType },
                           expression,
                           visitorContext.CreateFilter()));
            }

            return(expression);
        }
Exemple #2
0
        public Expression HandleLeave(
            SelectionVisitorContext context,
            IFieldSelection selection,
            Expression expression)
        {
            if (context.TryGetValueNode(ArgumentName, out IValueNode sortArgument) &&
                selection.Field.Arguments[ArgumentName].Type is InputObjectType iot &&
                iot is ISortInputType fit)
            {
                var visitor = new QueryableSortVisitor(iot, fit.EntityType);

                sortArgument.Accept(visitor);
                return(visitor.Compile(expression));
            }

            return(expression);
        }
        public Expression HandleLeave(
            SelectionVisitorContext context,
            IFieldSelection selection,
            Expression expression)
        {
            var argumentName = context.SelectionContext.SortingArgumentName;

            if (context.TryGetValueNode(argumentName, out IValueNode? sortArgument) &&
                selection.Field.Arguments[argumentName].Type is InputObjectType iot &&
                iot is ISortInputType fit)
            {
                var visitorContext = new QueryableSortVisitorContext(
                    iot, fit.EntityType, false);
                QueryableSortVisitor.Default.Visit(sortArgument, visitorContext);

                return(visitorContext.Compile(expression));
            }

            return(expression);
        }
Exemple #4
0
        public Expression HandleLeave(
            SelectionVisitorContext context,
            IFieldSelection selection,
            Expression expression)
        {
            IFilterConvention convention   = context.SelectionContext.FilterConvention;
            NameString        argumentName = convention.GetArgumentName();

            if (context.TryGetValueNode(argumentName, out IValueNode? filter) &&
                selection.Field.Arguments[argumentName].Type is InputObjectType iot &&
                iot is IFilterInputType fit &&
                convention.TryGetVisitorDefinition(
                    out FilterExpressionVisitorDefinition? defintion))
            {
                var visitorContext = new QueryableFilterVisitorContext(
                    iot,
                    fit.EntityType,
                    defintion,
                    context.Conversion,
                    false);

                QueryableFilterVisitor.Default.Visit(filter, visitorContext);

                if (visitorContext.TryCreateLambda(
                        out LambdaExpression? filterExpression))
                {
                    return(Expression.Call(
                               typeof(Enumerable),
                               nameof(Enumerable.Where),
                               new[] { fit.EntityType },
                               expression,
                               filterExpression));
                }
                else
                {
                    context.ReportErrors(visitorContext.Errors);
                }
            }

            return(expression);
        }
        public Expression HandleLeave(
            SelectionVisitorContext context,
            IFieldSelection selection,
            Expression expression)
        {
            if (context.TryGetValueNode("where", out IValueNode filter) &&
                selection.Field.Arguments["where"].Type is InputObjectType iot &&
                iot is IFilterInputType fit)
            {
                var visitor = new QueryableFilterVisitor(
                    iot, fit.EntityType, context.Conversion);

                filter.Accept(visitor);

                return(Expression.Call(
                           typeof(Enumerable),
                           "Where",
                           new[] { fit.EntityType },
                           expression,
                           visitor.CreateFilter()));
            }

            return(expression);
        }