Skip to content

Commit

Permalink
Fix schema initializer not registered if multiple HostedServices added
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkah committed Jan 2, 2025
1 parent 5b297b1 commit 579ee5c
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 445 deletions.
110 changes: 41 additions & 69 deletions benchmarks/GraphQL.Benchmarks/ExecutionBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Order;
Expand Down Expand Up @@ -29,30 +30,21 @@ public class ExecutionBenchmarks
private ExecutableDocument _subscription;
private Executor _nonValidatingExecutor;

//[Benchmark]
//public async Task Mutation_with_defaults()
//{
//var result = await Executor.ExecuteAsync(new ExecutionOptions
// {
// Document = _mutation,
// Schema = _schema
// });

// AssertResult(result.Errors);
//}

//[Benchmark]
//public async Task Mutation_without_validation()
//{
// var result = await Executor.ExecuteAsync(new ExecutionOptions
// {
// Document = _mutation,
// Schema = _schema,
// Validate = null
// });

// AssertResult(result.Errors);
//}
[Benchmark]
public async Task Mutation_with_defaults()
{
var result = await _executor.Execute(new GraphQLRequest(_mutation));

AssertResult(result.Errors);
}

[Benchmark]
public async Task Mutation_without_validation()
{
var result = await _nonValidatingExecutor.Execute(new GraphQLRequest(_mutation));

AssertResult(result.Errors);
}

[Benchmark]
public async Task Query_with_validation()
Expand Down Expand Up @@ -102,51 +94,31 @@ public void Setup()
});
}

//[Benchmark]
//public async Task Subscribe_with_defaults()
//{
// var cts = new CancellationTokenSource();
// var result = await Executor.SubscribeAsync(new ExecutionOptions
// {
// Document = _subscription,
// Schema = _schema
// }, cts.Token);

// AssertResult(result.Errors);
// cts.Cancel();
//}

//[Benchmark]
//public async Task Subscribe_with_defaults_and_get_value()
//{
// var cts = new CancellationTokenSource();
// var result = await Executor.SubscribeAsync(new ExecutionOptions
// {
// Document = _subscription,
// Schema = _schema
// }, cts.Token);

// AssertResult(result.Errors);

// var value = await result.Source.Reader.ReadAsync(cts.Token);
// AssertResult(value.Errors);
// cts.Cancel();
//}

//[Benchmark]
//public async Task Subscribe_without_validation()
//{
// var cts = new CancellationTokenSource();
// var result = await Executor.SubscribeAsync(new ExecutionOptions
// {
// Document = _subscription,
// Schema = _schema,
// Validate = null
// }, cts.Token);

// AssertResult(result.Errors);
// cts.Cancel();
//}
[Benchmark]
public async Task Subscribe_with_defaults()
{
var cts = new CancellationTokenSource();
var result = await _executor.Subscribe(new GraphQLRequest()
{
Query = _subscription,
}, cts.Token).SingleAsync(cancellationToken: cts.Token);

AssertResult(result.Errors);
cts.Cancel();
}

[Benchmark]
public async Task Subscribe_without_validation()
{
var cts = new CancellationTokenSource();
var result = await _nonValidatingExecutor.Subscribe(new GraphQLRequest()
{
Query = _subscription,
}, cts.Token).SingleAsync(cancellationToken: cts.Token);

AssertResult(result.Errors);
cts.Cancel();
}

private static void AssertResult(IEnumerable<ExecutionError> errors)
{
Expand Down
1 change: 1 addition & 0 deletions benchmarks/GraphQL.Benchmarks/GraphQL.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="GraphQL-Parser" Version="9.5.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.Server/GraphQLApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public GraphQLApplicationBuilder AddWebSockets()

private void AddDefaultTankaGraphQLServerServices()
{
ApplicationServices.TryAddSingleton<IHostedService, SchemaInitializer>();
ApplicationServices.AddHostedService<SchemaInitializer>();
ApplicationServices.TryAddSingleton<SchemaCollection>();
ApplicationServices.TryAddSingleton<GraphQLApplication>();
ApplicationServices.AddDefaultTankaGraphQLServices();
Expand Down

This file was deleted.

This file was deleted.

43 changes: 0 additions & 43 deletions templates/GraphQL.Template.HelloWorld/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions templates/GraphQL.Template.HelloWorld/appsettings.json

This file was deleted.

22 changes: 0 additions & 22 deletions templates/GraphQL.Template/.template.config/template.json

This file was deleted.

15 changes: 0 additions & 15 deletions templates/GraphQL.Template/GraphQL.Template.csproj

This file was deleted.

85 changes: 0 additions & 85 deletions templates/GraphQL.Template/Program.cs

This file was deleted.

Loading

0 comments on commit 579ee5c

Please sign in to comment.