ChilliCream / ChilliCream/graphql-platform

Parsing error while passing directive value from argument

Open
#5,924 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Type System YouTube
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Is there an existing issue for this?
  • I have searched the existing issues
Product

Hot Chocolate

Describe the bug

I have created a custom directive defaultCount which take value as argument

public class DefaultValue
{
  public int? Value { get; set; }
}
public class DefaultDirectiveType : DirectiveType<DefaultValue>
{
  public const string name = "defaultCount";
  protected override void Configure(IDirectiveTypeDescriptor<DefaultValue> descriptor)
  {
    descriptor.Name(name);
    descriptor.Location(DirectiveLocation.Field);
    descriptor.Use((next, directive) => async (context) =>
             {
               await next.Invoke(context);
             }
     );
  }
}

Now here are my cases of using it

  • ✅ Pass the value directly while using the descriptor.Use method

        query {
             categories {
                 nodes {
                   id @defaultCount(value: 10)
                }
             }
         }
    
  • ❌ Pass the value using variable while using the descriptor.Use method

        query Test($totalCount: Int) {
             categories {
                 nodes {
                   id @defaultCount(value: $totalCount)
                }
             }
         }
    

    The result was

       {
        "errors": [
          {
            "message": "Int cannot parse the given literal of type `VariableNode`.",
            "path": [
              "value"
            ],
            "extensions": {
              "field": "defaultCount.value",
              "fieldType": "Int"
            }
           }
         ]
      }
    
  • ✅ remove descriptor.Use method and pass the value using variable

      // removed this method
       descriptor.Use(...);
    
        query Test($totalCount: Int) {
             categories {
                 nodes {
                   id @defaultCount(value: $totalCount)
                }
             }
         }
    
Steps to reproduce
Relevant log output

No response

Additional Context?

No response

Version

13.0.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the custom DefaultDirectiveType and compare the descriptor.Use case with the same directive without middleware, using the variable-based GraphQL query as the reproducer. Trace how the defaultCount.value argument is parsed in each case; done means a variable value parses successfully when descriptor.Use is present without the reported VariableNode error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.