question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type validation doesn't work for string arguments when using variables

See original GitHub issue

There seems to be a problem with the type validation when an argument is of GQL type String and you’re passing the value in from a variable.

To Reproduce I have attached a solution that replicates the issue: HotChocolateTypeValidationBug.zip

Run this solution and then execute the following queries:

This correctly fails, reporting that the stringData argument is invalid.

query {
  test(stringData: false)
}

This incorrectly executes without error.

QUERY:

query Test($stringData: String!){
  test(stringData: $stringData)
}

VARIABLES:

{"stringData":false}

Expected behavior I expect that both versions would produce the error.

Desktop (please complete the following information):

  • OS: Windows
  • Version 10

Additional context Debugging into my query, it appears that the false value is being converted into a string containing “false” then passed to my method.

Interestingly, if I use {"stringData":5}, I get a “5” in the method parameter, but if I use {"stringData":{"test":"string"}}, a NullReferenceException is thrown from within HotChocolate:

at System.Object.GetType()
   at HotChocolate.Execution.VariableValueBuilder.EnsureClrTypeIsCorrect(IHasClrType type, Object value) in C:\\hc\\src\\Core\\Core\\Execution\\Utilities\\VariableValueBuilder.cs:line 169
   at HotChocolate.Execution.VariableValueBuilder.Normalize(VariableDefinitionNode variableDefinition, Variable variable, Object rawValue) in C:\\hc\\src\\Core\\Core\\Execution\\Utilities\\VariableValueBuilder.cs:line 139
   at HotChocolate.Execution.VariableValueBuilder.CoerceVariableValue(VariableDefinitionNode variableDefinition, IReadOnlyDictionary`2 variableValues, Variable variable) in C:\\hc\\src\\Core\\Core\\Execution\\Utilities\\VariableValueBuilder.cs:line 0
   at HotChocolate.Execution.VariableValueBuilder.CreateValues(IReadOnlyDictionary`2 variableValues) in C:\\hc\\src\\Core\\Core\\Execution\\Utilities\\VariableValueBuilder.cs:line 57
   at HotChocolate.Execution.ResolveOperationMiddleware.InvokeAsync(IQueryContext context) in C:\\hc\\src\\Core\\Core\\Execution\\Middleware\\ResolveOperationMiddleware.cs:line 49
   at HotChocolate.Execution.ClassMiddlewareFactory.<>c__DisplayClass2_0`1.<CreateDelegate>b__0(IQueryContext context) in C:\\hc\\src\\Core\\Core\\Execution\\Middleware\\ClassMiddlewareFactory.cs:line 53
   at HotChocolate.Execution.ValidateQueryMiddleware.InvokeAsync(IQueryContext context) in C:\\hc\\src\\Core\\Core\\Execution\\Middleware\\ValidateQueryMiddleware.cs:line 68
   at HotChocolate.Execution.ParseQueryMiddleware.InvokeAsync(IQueryContext context) in C:\\hc\\src\\Core\\Core\\Execution\\Middleware\\ParseQueryMiddleware.cs:line 67
   at HotChocolate.Execution.ExceptionMiddleware.InvokeAsync(IQueryContext context) in C:\\hc\\src\\Core\\Core\\Execution\\Middleware\\ExceptionMiddleware.cs:line 26

I’m using schema-first here. I’m not sure if this problem exists for code-first. I expect it probably does.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
michaelstaibcommented, May 5, 2019

I moved this now to a hotfix release. We have another issue that we want to fix quickly and I think we can do that quickly. Version 9 is still two weeks out.

1reaction
michaelstaibcommented, Jul 8, 2019

We are now starting on bug fixing … this one will be on 9.1.0-preview.25.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type validation doesn't work for string arguments when ...
There seems to be a problem with the type validation when an argument is of GQL type String and you're passing the value...
Read more >
Annotations from javax.validation.constraints not working
In the handler you want to validate, annotate the object you want to validate with @Valid , and then include a BindingResult in...
Read more >
Validate list(object) variables - Terraform
I'm trying to set up a validation based on your suggestion and it doesn't seem to work for list(string) vars. I'm getting the...
Read more >
Arguments accept char, string or "cellstr" (cell array of ...
I can use mustBeA to accept char, string, or cell - but I don't want to accept just any cell variable, it needs...
Read more >
How to bind arguments to handlers in System.CommandLine
Learn how to do model-binding in apps that are built with the System.Commandline library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found