Open
Description
openedon Jun 14, 2023
Is there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
When adding more than one schema through multiple calls to AddGraphQLServer()
, subsequent calls to AddDiagnosticEventListener()
seems to register the listener globally. If I register two listeners one for each schema both of the listeners are executed for every request, regardless of which schema/route was used. This results in logging/diagnostics/telemetry performed in the listener being duplicated.
- Shouldn't diagnostic event listeners added using
.AddGraphQLServer().AddDiagnosticEventListener()
be scoped to their respective schema? - How is the
AddDiagnosticEventListener()
method supposed to be used when using multiple schemas?
Steps to reproduce
- Clone the reproduce case defined here: https://github.com/treet/hotchocolate-repro
dotnet run
- Make any GraphQL call to one of the schemas, e.g:
curl http://localhost:5041/schema1/graphql -H 'content-type: application/json' -d'{"query":"query { book { title }}"}'
Expected result: Only one message ExecuteHttpRequest of kind HttpPost
should be logged by the application.
Actual result: Two messages are logged, since both diagnostic events listeners were executed.
Here's the most important portion of the code:
using hotchocolate_repro;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddGraphQLServer("schema1")
.AddQueryType<Query1>()
.AddDiagnosticEventListener<ExampleDiagnosticsEventListener1>();
builder.Services
.AddGraphQLServer("schema2")
.AddQueryType<Query2>()
.AddDiagnosticEventListener<ExampleDiagnosticsEventListener2>();
var app = builder.Build();
app
.UseRouting()
.UseEndpoints(endpoints =>
{
endpoints.MapGraphQL("/schema1", schemaName: "schema1");
endpoints.MapGraphQL("/schema2", schemaName: "schema2");
});
app.Run();
Relevant log output
No response
Additional Context?
No response
Version
13.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment