public GraphQLStarWarsTestServer(GraphQLTestServerFactory serverFactory) { this.Server = CreateTestServer( serverFactory, servicesConfigure: services => { //BBernard //Configure the test server and Load PreProcessedResults Custom Middleware! var graphQLBuilder = services .AddGraphQLServer() .AddQueryType(d => d.Name("Query")) .AddType <HelloWorldResolver>() .AddType <StarWarsCharacterResolver>() .AddType <StarWarsHuman>() .AddType <StarWarsDroid>() .AddTypeExtension <HumanFieldResolvers>() .SetPagingOptions(new PagingOptions() { DefaultPageSize = 5, IncludeTotalCount = true, MaxPageSize = 10 }) .AddPreProcessedResultsExtensions(); return(graphQLBuilder); } ); }
protected TestServer CreateTestServer( GraphQLTestServerFactory serverFactory, Func <IServiceCollection, IRequestExecutorBuilder> servicesConfigure, string pattern = "/graphql", Action <GraphQLEndpointConventionBuilder> configureConventions = default) { return(serverFactory.Create( services => { services .AddRouting() .AddHttpResultSerializer(HttpResultSerialization.JsonArray); //BBernard - Hook for IoC Services Configuration by implementing Test Servers... var graphQLBuilder = servicesConfigure(services); //BBernard //Allow Tests to provide (IoC) custom configuration to the builder // as needed for custom testing via Middleware! graphQLBuilder.UseField(next => context => { //BBernard intercept the ParamsContext initialized by the PreProcessing Results Middleware // and expose it publicly for Test cases to utilize! //NOTE: MANY middleware invocations will execute for various fields so have to track them all // for later access... var paramsContext = context.GetLocalValue <GraphQLParamsContext>(nameof(GraphQLParamsContext)); ParamsContextList.Add(new KeyValuePair <string, IParamsContext>( context.Field.Name, new ParamsContextTestHarness(paramsContext) )); //BBernard - WE MUST ALLOW THE PIPELINE TO CONTINUE! return next.Invoke(context); }); }, app => { app .UseRouting() .UseEndpoints(endpoints => { GraphQLEndpointConventionBuilder builder = endpoints.MapGraphQL(pattern); configureConventions?.Invoke(builder); }); } )); }
public GraphQLHelloWorldTestServer(GraphQLTestServerFactory serverFactory) { this.Server = CreateTestServer( serverFactory, servicesConfigure: services => { //BBernard //Configure the test server and Load PreProcessedResults Custom Middleware! var graphQLBuilder = services .AddGraphQLServer() .AddQueryType(d => d.Name("Query")) .AddType <HelloWorldResolver>() //We ONLY Add Middleware for testing without Advanced support for Sorting, etc... // to help determine if ParamsContext has graceful fallback functionality. .AddMiddlewareForPreProcessedResults(); return(graphQLBuilder); } ); }
public GraphQLTestBase(GraphQLTestServerFactory serverFactory) { ServerFactory = serverFactory; }