public MountainSchema(IDependencyResolver resolver) : base(resolver) { Query = resolver.Resolve <MountainQuery>(); Mutation = resolver.Resolve <MountainMutation>(); Subscription = resolver.Resolve <MountainSubscription>(); RegisterDirective(new LowercaseDirective()); RegisterDirective(new OrderbyDirective()); var builder = new FieldMiddlewareBuilder(); builder.Use <LowercaseFieldsMiddleware>(); builder.ApplyTo(this); builder.Use(next => { return(context => { return next(context).ContinueWith(x => { var c = context; var result = x.Result; result = OrderbyQuery.OrderIfNecessary(context, result); return result; }); }); }); builder.ApplyTo(this); //builder.Use<CustomGraphQlExecutor<MountainSchema>>(); //builder.ApplyTo(this); }
public async Task test() { // create a middleware that increments a variable when every field is resolved var middleware = new FieldMiddlewareBuilder(); int count = 0; middleware.Use(d => context => { Interlocked.Increment(ref count); return(d(context)); }); // prep a test execution using that middleware StarWarsTestBase starWarsTest = null; Func <Task> testExecution = async() => { var result = await starWarsTest.Executer.ExecuteAsync(new ExecutionOptions { Query = "IntrospectionQuery".ReadGraphQLRequest(), Schema = starWarsTest.Schema, }); result.Errors.ShouldBeNull(); }; // run a single execution and record the number of times the resolver executed starWarsTest = new StarWarsTestBase(); starWarsTest.Schema.FieldMiddleware = middleware; await testExecution(); var correctCount = count; // test initializing the schema first, followed by 3 simultaneous executions starWarsTest = new StarWarsTestBase(); starWarsTest.Schema.FieldMiddleware = middleware; await testExecution(); count = 0; var t1 = Task.Run(testExecution); var t2 = Task.Run(testExecution); var t3 = Task.Run(testExecution); await Task.WhenAll(t1, t2, t3); count.ShouldBe(correctCount * 3, "Failed synchronized initialization"); // test three simultaneous executions on an uninitialized schema count = 0; starWarsTest = new StarWarsTestBase(); starWarsTest.Schema.FieldMiddleware = middleware; t1 = Task.Run(testExecution); t2 = Task.Run(testExecution); t3 = Task.Run(testExecution); await Task.WhenAll(t1, t2, t3); count.ShouldBe(correctCount * 3, "Failed multithreaded initialization"); }
public IFieldMiddlewareBuilder Use(Func <ISchema, FieldMiddlewareDelegate, FieldMiddlewareDelegate> middleware) => overriddenBuilder.Use(middleware);
public IFieldMiddlewareBuilder Use(Func <FieldMiddlewareDelegate, FieldMiddlewareDelegate> middleware) { return(overriddenBuilder.Use(middleware)); }