Skip to content

Parsing error while passing directive value from argument #5924

@mu-dawood

Description

@mu-dawood

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions