Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using two different DbContexts in a resolver not working anymore #6717

Closed
1 task done
dalen opened this issue Nov 22, 2023 · 2 comments
Closed
1 task done

Using two different DbContexts in a resolver not working anymore #6717

dalen opened this issue Nov 22, 2023 · 2 comments
Labels
Area: Data Issue is related to filtering, sorting, pagination or projections 🌶️ hot chocolate
Milestone

Comments

@dalen
Copy link

dalen commented Nov 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

in version 13.5.1 you could use two different DbContexts on a resolver, like this:

        descriptor
            .Field("events")
            .Type<NonNullType<ListType<NonNullType<EventType>>>>()
            .UseDbContext<CharacterDb>()
            .UseDbContext<WorldDBContext>()
            .Resolve(async (IResolverContext context) =>

In 13.7.0 that is not working anymore.

Steps to reproduce

  1. Use two different DbContexts
  2. Boot server and get error log

Relevant log output

2023-11-22 14:09:26.1646|ERROR|Microsoft.AspNetCore.Server.Kestrel|Connection id "0HMVBCIGH1K7D", Request id "0HMVBCIGH1K7D:00000001": An unhandled exception was thrown by the application.|HotChocolate.SchemaException: For more details look at the `Errors` property.

1. The field `Query.events` declares the data middleware `UseDbContext` more than once. (WebApiServer.Schema.QueryType)

   at HotChocolate.Types.Interceptors.MiddlewareValidationTypeInterceptor.ValidatePipeline(ITypeSystemObject type, FieldCoordinate field, ISyntaxNode syntaxNode, IList`1 middlewareDefinitions)
   at HotChocolate.Types.Interceptors.MiddlewareValidationTypeInterceptor.OnValidateType(ITypeSystemObjectContext validationContext, DefinitionBase definition)
   at HotChocolate.Configuration.AggregateTypeInterceptor.OnValidateType(ITypeSystemObjectContext validationContext, DefinitionBase definition)
   at HotChocolate.Types.TypeSystemObjectBase`1.OnValidateType(ITypeSystemObjectContext context, DefinitionBase definition)
   at HotChocolate.Types.TypeSystemObjectBase`1.CompleteType(ITypeCompletionContext context)
   at HotChocolate.Configuration.TypeInitializer.CompleteType(RegisteredType registeredType)
   at HotChocolate.Configuration.TypeInitializer.<CompleteTypes>b__30_0(RegisteredType type)
   at HotChocolate.Configuration.TypeInitializer.ProcessTypes(TypeDependencyFulfilled fulfilled, Func`2 action)
   at HotChocolate.Configuration.TypeInitializer.CompleteTypes()
   at HotChocolate.Configuration.TypeInitializer.Initialize()
   at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
   at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
   at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
   at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
   at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
   at HotChocolate.AspNetCore.HttpPostMiddlewareBase.HandleRequestAsync(HttpContext context)
   at HotChocolate.AspNetCore.HttpPostMiddlewareBase.InvokeAsync(HttpContext context)
   at Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.<>c__DisplayClass19_0.<<UseCancellation>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
2023-11-22 14:09:26.1646|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished HTTP/1.1 POST http://production-api.waremu.com/graphql/ application/json 209 - 500 0 - 337.1102ms
2023-11-22 14:09:34.8800|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - -
2023-11-22 14:09:34.8800|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - -
2023-11-22 14:09:34.8840|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.8840|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.8840|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - - - 204 - - 3.0525ms
2023-11-22 14:09:34.8840|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - - - 204 - - 3.0581ms
2023-11-22 14:09:34.8888|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - -
2023-11-22 14:09:34.8888|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.8888|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request finished HTTP/1.1 OPTIONS http://production-api.waremu.com/graphql - - - 204 - - 0.6654ms
2023-11-22 14:09:34.9239|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 POST http://production-api.waremu.com/graphql application/json 501
2023-11-22 14:09:34.9239|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.9239|INFO|Microsoft.AspNetCore.Routing.EndpointMiddleware|Executing endpoint 'Hot Chocolate GraphQL Pipeline'
2023-11-22 14:09:34.9305|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 POST http://production-api.waremu.com/graphql application/json 1173
2023-11-22 14:09:34.9312|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.9312|INFO|Microsoft.AspNetCore.Routing.EndpointMiddleware|Executing endpoint 'Hot Chocolate GraphQL Pipeline'
2023-11-22 14:09:34.9352|INFO|Microsoft.AspNetCore.Hosting.Diagnostics|Request starting HTTP/1.1 POST http://production-api.waremu.com/graphql application/json 494
2023-11-22 14:09:34.9352|INFO|Microsoft.AspNetCore.Cors.Infrastructure.CorsService|CORS policy execution successful.
2023-11-22 14:09:34.9352|INFO|Microsoft.AspNetCore.Routing.EndpointMiddleware|Executing endpoint 'Hot Chocolate GraphQL Pipeline'
2023-11-22 14:09:35.1218|INFO|Microsoft.AspNetCore.Routing.EndpointMiddleware|Executed endpoint 'Hot Chocolate GraphQL Pipeline'
2023-11-22 14:09:35.1218|ERROR|Microsoft.AspNetCore.Server.Kestrel|Connection id "0HMVBCIGH1K7H", Request id "0HMVBCIGH1K7H:00000001": An unhandled exception was thrown by the application.|HotChocolate.SchemaException: For more details look at the `Errors` property.

Additional Context?

It seems it broke in this PR #6622

Version

13.7.0

@dalen dalen added the 🐛 bug label Nov 22, 2023
@michaelstaib michaelstaib added 🌶️ hot chocolate Area: Data Issue is related to filtering, sorting, pagination or projections labels Nov 24, 2023
@michaelstaib michaelstaib added this to the HC-13.8.0 milestone Nov 24, 2023
@michaelstaib
Copy link
Member

I have looked at this ... we are validating the pipeline order. In many cases two DBContexts are actually a mistake. You can disable this validation like the following.

.ModifyOptions(o => o.ValidatePipelineOrder = false)

@dalen
Copy link
Author

dalen commented Dec 20, 2023

hmm okay. Ideally I would prefer to keep validating the order of Pagination, Filtering etc though.

Having two different DBContexts can be a sign of a mistake, but I would at most print a notice about that really, not an error. Is that really a mistake people actually make, when they are only using one of them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Data Issue is related to filtering, sorting, pagination or projections 🌶️ hot chocolate
Projects
None yet
Development

No branches or pull requests

2 participants