protected virtual TestServer CreateStarWarsServer( string pattern = "/graphql", Action <IServiceCollection> configureServices = default, Action <GraphQLEndpointConventionBuilder> configureConventions = default) { return(ServerFactory.Create( services => { services .AddRouting() .AddHttpResultSerializer(HttpResultSerialization.JsonArray) .AddGraphQLServer() .AddQueryType <QueryType>() .AddMutationType <MutationType>() .AddSubscriptionType <SubscriptionType>() .AddType <HumanType>() .AddType <DroidType>() .AddType <EpisodeType>() .AddExportDirectiveType() .AddStarWarsRepositories() .AddInMemorySubscriptions(); configureServices?.Invoke(services); }, app => app .UseWebSockets() .UseRouting() .UseEndpoints(endpoints => { GraphQLEndpointConventionBuilder builder = endpoints.MapGraphQL(pattern); configureConventions?.Invoke(builder); }))); }
protected virtual TestServer CreateStarWarsServer( string pattern = "/graphql", Action <GraphQLEndpointConventionBuilder> configureConventions = default) { return(ServerFactory.Create( services => services .AddRouting() .AddHttpResultSerializer(HttpResultSerialization.JsonArray) .AddGraphQLServer() .AddStarWarsTypes() .AddTypeExtension <QueryExtension>() .AddExportDirectiveType() .AddStarWarsRepositories() .AddInMemorySubscriptions() .UseActivePersistedQueryPipeline() .ConfigureSchemaServices(services => services .AddSingleton <PersistedQueryCache>() .AddSingleton <IReadStoredQueries>( c => c.GetService <PersistedQueryCache>()) .AddSingleton <IWriteStoredQueries>( c => c.GetService <PersistedQueryCache>())) .AddGraphQLServer("evict") .AddQueryType(d => d.Name("Query")) .AddTypeExtension <QueryExtension>() .AddGraphQLServer("arguments") .AddQueryType(d => { d .Name("QueryRoot"); d .Field("double_arg") .Argument("d", t => t.Type <FloatType>()) .Type <FloatType>() .Resolve(c => c.ArgumentValue <double?>("d")); d .Field("decimal_arg") .Argument("d", t => t.Type <DecimalType>()) .Type <DecimalType>() .Resolve(c => c.ArgumentValue <decimal?>("d")); }), app => app .UseWebSockets() .UseRouting() .UseEndpoints(endpoints => { GraphQLEndpointConventionBuilder builder = endpoints.MapGraphQL(pattern); configureConventions?.Invoke(builder); endpoints.MapGraphQL("/evict", "evict"); endpoints.MapGraphQL("/arguments", "arguments"); }))); }
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); }); } )); }
/// <summary> /// Specifies the GraphQL server options. /// </summary> /// <param name="builder"> /// The <see cref="GraphQLEndpointConventionBuilder"/>. /// </param> /// <param name="serverOptions"> /// The GraphQL server options. /// </param> /// <returns> /// Returns the <see cref="GraphQLEndpointConventionBuilder"/> so that /// configuration can be chained. /// </returns> public static GraphQLEndpointConventionBuilder WithOptions( this GraphQLEndpointConventionBuilder builder, GraphQLServerOptions serverOptions) => builder.WithMetadata(serverOptions);