ChilliCream / ChilliCream/graphql-platform
Parsing error while passing directive value from argument
Nobody has claimed this yet.
- 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.Usemethodquery { categories { nodes { id @defaultCount(value: 10) } } } -
❌ Pass the value using
variablewhile using thedescriptor.Usemethodquery 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.Usemethod and pass the value usingvariable// 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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