Skip to content

Missing optional value in input type throws exception #4354

@svelue

Description

@svelue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In contrast to V11 a mutation fails if an optional input field is not set and the field is mapped to a non nullable property.

Steps to reproduce

  1. Checkout and start https://github.com/svelue/OptionalInputBug
  2. Run mutation{ addBook(book: {title: "123", someNumber: 1}){ title someNumber } } --> it works
  3. Run mutation{ addBook(book: {title: "123"}){ title someNumber } } --> it fails

Relevant log output

+        "Message": "Unexpected Execution Error",
+        "Code": null,
+        "Path": {
+          "Parent": null,
+          "Depth": 0,
+          "Name": "sendData"
+        },
+        "Locations": [
+          {
+            "Line": 2,
+            "Column": 3
+          }
+        ],
+        "Extensions": null,
+        "Exception": {
+          "ClassName": "System.NullReferenceException",
+          "Message": "Object reference not set to an instance of an object.",
+          "Data": null,
+          "InnerException": null,
+          "HelpURL": null,
+          "StackTraceString": "   at lambda_method858(Closure , Object[] )\r\n   at HotChocolate.Types.InputParser.ParseObject(IValueNode resultValue, InputObjectType type, Path path, Int32 stack, Boolean defaults)\r\n   at HotChocolate.Types.InputParser.ParseLiteralInternal(IValueNode value, IType type, Path path, Int32 stack, Boolean defaults, IInputField field)\r\n   at HotChocolate.Types.InputParser.ParseLiteralInternal(IValueNode value, IType type, Path path, Int32 stack, Boolean defaults, IInputField field)\r\n   at HotChocolate.Types.InputParser.ParseList(IValueNode resultValue, ListType type, Path path, Int32 stack, Boolean defaults, IInputField field)\r\n   at HotChocolate.Types.InputParser.ParseLiteralInternal(IValueNode value, IType type, Path path, Int32 stack, Boolean defaults, IInputField field)\r\n   at HotChocolate.Types.InputParser.ParseLiteral(IValueNode value, IInputField field, Type targetType)\r\n   at HotChocolate.Execution.Processing.MiddlewareContext.CoerceArgumentValue[T](ArgumentValue argument)\r\n   at HotChocolate.Execution.Processing.MiddlewareContext.ArgumentValue[T](NameString name)\r\n   at HotChocolate.Execution.Processing.DirectiveContext.ArgumentValue[T](NameString name)\r\n   at lambda_method1081(Closure , IResolverContext )\r\n   at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<<CreateResolverMiddleware>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.AspNetCore.Authorization.AuthorizeMiddleware.InvokeAsync(IDirectiveContext context)\r\n   at HotChocolate.Utilities.MiddlewareCompiler`1.ExpressionHelper.AwaitTaskHelper(Task task)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)",
+          "RemoteStackTraceString": null,
+          "RemoteStackIndex": 0,
+          "ExceptionMethod": null,
+          "HResult": -2147467261,
+          "Source": "Anonymously Hosted DynamicMethods Assembly",
+          "WatsonBuckets": null
+        },

Additional Context?

https://hotchocolategraphql.slack.com/archives/CD9TNKT8T/p1635433560328800

Product

Hot Chocolate

Version

12.0.1

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions