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

Unhandled exception with Complexity Analyzer when using subscription call #8074

Open
vadeveka opened this issue Feb 27, 2025 · 1 comment
Open

Comments

@vadeveka
Copy link

vadeveka commented Feb 27, 2025

Product

Hot Chocolate

Version

12.22.6,15.0.3,14.4.0-p.10

Link to minimal reproduction

https://github.com/vadeveka/hotchocolateexperiments/tree/main

Steps to reproduce

If a user issues a typical GraphQL query with subscription type, the expectation is that it will fail gracefully with syntax error if subscription types are not configured. When operation or cost analysis is enabled, the analyzer fails unexpectedly .
This is one scenario I have discovered by trial and error where it fails unexpectedly, not sure if there are other usecases that my end-users are trying out and where it will cause same unhandled failure.

POST https://localhost:7290/graphql/
{
"query": "subscription {\n books\n}"
}

With HC 12.22.6

{
	"errors": [
		{
			"message": "Unexpected Execution Error",
			"extensions": {
				"message": "Unable to cast object of type 'System.Collections.Generic.List`1[System.Linq.Expressions.Expression]' to type 'System.Collections.Generic.List`1[HotChocolate.Execution.Pipeline.Complexity.OperationComplexityAnalyzer]'.",
				"stackTrace": "   at HotChocolate.Execution.Pipeline.OperationComplexityMiddleware.CompileAnalyzer(IRequestContext requestContext, DocumentNode document, OperationDefinitionNode operationDefinition)\r\n   at HotChocolate.Execution.Pipeline.OperationComplexityMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.OperationCacheMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentValidationMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentParserMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentCacheMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.TimeoutMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.ExceptionMiddleware.InvokeAsync(IRequestContext context)"
			}
		}
	]
}

With HC 15.0.3

{
	"errors": [
		{
			"message": "Unexpected Execution Error",
			"extensions": {
				"message": "The given key '{\r\n  books\r\n}' was not present in the dictionary.",
				"stackTrace": "   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n   at HotChocolate.CostAnalysis.CostAnalyzer.Analyze(OperationDefinitionNode operation, IDocumentValidatorContext context)\r\n   at HotChocolate.CostAnalysis.CostAnalyzerMiddleware.TryAnalyze(IRequestContext context, RequestCostOptions requestOptions, CostAnalyzerMode mode, DocumentNode document, String operationId, CostMetrics& costMetrics)\r\n   at HotChocolate.CostAnalysis.CostAnalyzerMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentValidationMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentParserMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.DocumentCacheMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.TimeoutMiddleware.InvokeAsync(IRequestContext context)\r\n   at HotChocolate.Execution.Pipeline.ExceptionMiddleware.InvokeAsync(IRequestContext context)"
			}
		}
	]
}

What is expected?

Graceful validation error

What is actually happening?

Unexpected exception in Complexity Analyzer

Relevant log output

Additional context

No response

@vadeveka
Copy link
Author

vadeveka commented Feb 27, 2025

Applicable for v14 too. Noting since PR for HotChocolate upgrade in DAB is targeted with v14
https://github.com/Azure/data-api-builder/pull/2348/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants