-
| 
         Hey, I've written a basic implementation of IQueryable and IQueryProvider in order to convert an Expression generated by the UseFiltering infrastructure into a SearchRequest I can send to ElasticSearch. I've written a class based on ExpressionVisitor - and I can pull out the bits of the expression tree I need. I'd like to test my 'CustomExpressionVisitor' - but with my current approach, I'd need to be able to generate some Expressions that are equivalent to those produced by the filtering infrastructure - if we upgrade HotChocolate in the future and the Expression structure changes, I'd like my tests to start failing. So with that in mind, does anyone have any suggestions for how i could use the existing HotChocolate functionality to generate an Expression I can then feed into my CustomExpressionVisitor? I appreciate my approach might be quite naive - I've only been working with HotChocolate for a couple of weeks - so i'm also open to alternative approaches I may have missed :-D  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| 
         I've found some inspiration in FilterConventionTests Using a very similar setup to that suite of tests, I can have my test queries as strings which are then parsed into an      public class ExecutorBuilder
    {
        private readonly IFilterInputType _inputType;
        public ExecutorBuilder(IFilterInputType inputType)
        {
            _inputType = inputType;
        }
        public Expression<Func<T, bool>> Build<T>(IValueNode filter)
        {
            var visitorContext = new QueryableFilterContext(_inputType, true);
            var visitor = new FilterVisitor<QueryableFilterContext, Expression>(
                new QueryableCombinator());
            visitor.Visit(filter, visitorContext);
            if (visitorContext.TryCreateLambda(out Expression<Func<T, bool>>? where))
            {
                return where;
            }
            throw new InvalidOperationException();
        }
    } | 
  
Beta Was this translation helpful? Give feedback.
I've found some inspiration in FilterConventionTests
Using a very similar setup to that suite of tests, I can have my test queries as strings which are then parsed into an
IValueNodeby usingUtf8GraphQLParser.Syntax.ParseValueLiteral(queryText). Then a slightly modified version of theExecutorBuilderclass allows me to return an Expression which I can pass into my CustomExpressionVisitor -