Issues parsing variables after GQL upgrade to v5
See original GitHub issueSummary
I recently upgraded from v 4.6.0 to v 5.1.1 and ran into an issue where it’s not able to parse variables. Could you please tell me what I’ve forgotten or gotten wrong,
Old code
opts.Inputs = request?.Variables.ToInputs();
New code
opts.Variables = request?.Variables.ToInputs();
Relevant information
GQL request e.g.
query ($productID: String!) {
productData(productId: $productID) {
productId
title
Variables
{
"productID": "12345",
}
Errors,
errors": [
{
"message": "GraphQL.Validation.InvalidVariableError: Variable '$productID' is invalid. Unable to convert '4851605' to 'String'\n ---> System.InvalidOperationException: Unable to convert '12345' to the scalar type 'String'\n at GraphQL.Types.ScalarGraphType.ThrowValueConversionError(Object value) in /_/src/GraphQL/Types/Scalars/ScalarGraphType.cs:line 235\n at GraphQL.Types.StringGraphType.ParseValue(Object value) in /_/src/GraphQL/Types/Scalars/StringGraphType.cs:line 27\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValueScalar|49_1(ScalarGraphType scalarGraphType, GraphQLVariableDefinition variableDef, VariableName variableName, Object value) in /_/src/GraphQL/Validation/ValidationContext.cs:line 249\n --- End of inner exception stack trace ---\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValueScalar|49_1(ScalarGraphType scalarGraphType, GraphQLVariableDefinition variableDef, VariableName variableName, Object value) in /_/src/GraphQL/Validation/ValidationContext.cs:line 253\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValue|49_0(IGraphType type, GraphQLVariableDefinition variableDef, VariableName variableName, Object value, IVariableVisitor visitor) in /_/src/GraphQL/Validation/ValidationContext.cs:line 234\n at GraphQL.Validation.ValidationContext.<GetVariableValue>g__ParseValue|49_0(IGraphType type, GraphQLVariableDefinition variableDef, VariableName variableName, Object value, IVariableVisitor visitor) in /_/src/GraphQL/Validation/ValidationContext.cs:line 224\n at GraphQL.Validation.
Validation Rule
opts.ValidationRules = DocumentValidator.CoreRules.Concat(new[] { new InputValidationRule() });
Where InputValidationRules.cs is,
public class InputValidationRule : IValidationRule
{
public ValueTask<INodeVisitor> ValidateAsync(ValidationContext context)
{
return ValueTask.FromResult<INodeVisitor>(new NoopNodeVisitor());
}
private class NoopNodeVisitor : INodeVisitor
{
public void Enter(ASTNode node, ValidationContext context) { /* Noop */ }
public void Leave(ASTNode node, ValidationContext context) { /* Noop */ }
}
}
I think the issue is either related to the way I’ve set the Variables or the InputValidationRule and I would be grateful to understand what to fix. Thank you!
Issue Analytics
- State:
- Created a year ago
- Comments:21 (13 by maintainers)
Top Results From Across the Web
Parse variables · Issue #131 · apollographql/graphql-tag
Does anyone know about how to use gql (using graphgql-tag) with variables and options. The documentation is here which I have been following....
Read more >Mutations in Apollo Client
Here, we use the variables option to provide the values of any GraphQL variables that our mutation requires (specifically, the type of the...
Read more >GraphQL Requiring Multiple Variables Not Working ...
I have yet to make this happen proper with more than one variable. enter image description here. When calling the query, it looks...
Read more >Parsing
The Grok syntax provides an easier way to parse logs than pure regular expressions. The Grok Parser enables you to extract attributes from...
Read more >Deprecations and removals by version | GitLab
In preparation for this, the following legacy DAST variables are being deprecated and scheduled for removal in GitLab 16.0: DAST_HTML_REPORT , DAST_XML_REPORT , ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Shane32 Let’s change error message:
$"Unable to convert '{value}' to '{scalarGraphType.Name}'"
->$"Unable to convert '{value}' of type {value.GetType().Name} to scalar '{scalarGraphType.Name}'"
Of course value may be null.
I don’t know what to write exactly since I don’t remember. Write something if you feel that it’s necessary.