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.

Issues parsing variables after GQL upgrade to v5

See original GitHub issue

Summary

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:closed
  • Created a year ago
  • Comments:21 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
sungam3rcommented, Apr 27, 2022

@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.

0reactions
sungam3rcommented, May 2, 2022

I’m not sure when we deprecated ObjectDictionaryConverter but we could probably write migration notes for that as well, assuming we removed it in v5.

I don’t know what to write exactly since I don’t remember. Write something if you feel that it’s necessary.

Read more comments on GitHub >

github_iconTop 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 >

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