ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.09k stars 722 forks source link

Parsing error while passing directive value from argument #5924

Open mo-ah-dawood opened 1 year ago

mo-ah-dawood commented 1 year ago

Is there an existing issue for this?

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

Steps to reproduce

Relevant log output

No response

Additional Context?

No response

Version

13.0.5

hognevevle commented 6 months ago

Is there another known workaround here, as removing the middleware pretty much removes the purpose of the directive in my case :)

nikcio commented 2 months ago

Hi,

I am also encountering this issue I've tried making a test showcasing the problem in case this could help troubleshoot the issue: https://github.com/ChilliCream/graphql-platform/compare/main...nikcio:graphql-platform:directive-type-returns-error-on-query-paramenter

nikcio commented 2 months ago

I've tried looking into this some more and found that the error stems from the variable not being the actual value when we're trying to parse the directive to be used in the middleware:

HotChocolate.Execution.Processing.OperationCompiler.BuildDirectivePipeline(....) Line 246 graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.ArgumentValues.cs(246)

directiveType.Parse(directiveNode)

As far as I can tell we need to resolve the actual value from somewhere but I couldn't figure out where it's available and where would be the correct place to put the logic for this.

(The test for the call stack is what can be found in the previous comment)

Call stack to error

HotChocolate.Types.dll!HotChocolate.Types.ScalarType<string, HotChocolate.Language.StringValueNode>.CreateParseLiteralError(HotChocolate.Language.IValueNode valueSyntax) Line 160
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\Scalars\ScalarType~2.cs(160)
HotChocolate.Types.dll!HotChocolate.Types.ScalarType<string, HotChocolate.Language.StringValueNode>.ParseLiteral(HotChocolate.Language.IValueNode valueSyntax) Line 105
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\Scalars\ScalarType~2.cs(105)
HotChocolate.Types.dll!HotChocolate.Types.InputParser.ParseLeaf(HotChocolate.Language.IValueNode resultValue, HotChocolate.Types.ILeafType type, HotChocolate.Path path, HotChocolate.Types.IInputFieldInfo field) Line 321
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\InputParser.cs(321)
HotChocolate.Types.dll!HotChocolate.Types.InputParser.ParseLiteralInternal(HotChocolate.Language.IValueNode value, HotChocolate.Types.IType type, HotChocolate.Path path, int stack, bool defaults, HotChocolate.Types.IInputFieldInfo field) Line 115
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\InputParser.cs(115)
HotChocolate.Types.dll!HotChocolate.Types.InputParser.ParseDirective(HotChocolate.Language.DirectiveNode node, HotChocolate.Types.DirectiveType type, HotChocolate.Path path, int stack, bool defaults) Line 403
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\InputParser.cs(403)
HotChocolate.Types.dll!HotChocolate.Types.InputParser.ParseDirective(HotChocolate.Language.DirectiveNode node, HotChocolate.Types.DirectiveType type, HotChocolate.Path path) Line 355
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\InputParser.cs(355)
HotChocolate.Types.dll!HotChocolate.Types.DirectiveType.Parse(HotChocolate.Language.DirectiveNode directiveNode) Line 130
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Types\Types\DirectiveType.cs(130)
HotChocolate.Execution.dll!HotChocolate.Execution.Processing.OperationCompiler.BuildDirectivePipeline(HotChocolate.ISchema schema, HotChocolate.Language.FieldNode selection, System.Collections.Generic.HashSet<string> processed, System.Collections.Generic.List<HotChocolate.Resolvers.FieldMiddleware> pipelineComponents) Line 246
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.ArgumentValues.cs(246)
HotChocolate.Execution.dll!HotChocolate.Execution.Processing.OperationCompiler.CreateFieldPipeline(HotChocolate.ISchema schema, HotChocolate.Types.IObjectField field, HotChocolate.Language.FieldNode selection, System.Collections.Generic.HashSet<string> processed, System.Collections.Generic.List<HotChocolate.Resolvers.FieldMiddleware> pipelineComponents) Line 188
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.ArgumentValues.cs(188)
HotChocolate.Execution.dll!HotChocolate.Execution.Processing.OperationCompiler.CompleteResolvers(HotChocolate.ISchema schema) Line 280
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.cs(280)
HotChocolate.Execution.dll!HotChocolate.Execution.Processing.OperationCompiler.CreateOperation(string operationId, HotChocolate.Language.OperationDefinitionNode operationDefinition, HotChocolate.Types.ObjectType operationType, HotChocolate.Language.DocumentNode document, HotChocolate.ISchema schema) Line 180
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.cs(180)
HotChocolate.Execution.dll!HotChocolate.Execution.Processing.OperationCompiler.Compile(string operationId, HotChocolate.Language.OperationDefinitionNode operationDefinition, HotChocolate.Types.ObjectType operationType, HotChocolate.Language.DocumentNode document, HotChocolate.ISchema schema, System.Collections.Generic.IReadOnlyList<HotChocolate.Execution.Processing.IOperationCompilerOptimizer> optimizers, bool enableNullBubbling) Line 137
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Processing\OperationCompiler.cs(137)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationResolverMiddleware.CompileOperation(HotChocolate.Execution.IRequestContext context, string operationId, HotChocolate.Language.OperationDefinitionNode operationDefinition, HotChocolate.Types.ObjectType operationType) Line 87
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationResolverMiddleware.cs(87)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationResolverMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 64
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationResolverMiddleware.cs(64)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationResolverMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 178
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationResolverMiddleware.cs(178)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationComplexityMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 54
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationComplexityMiddleware.cs(54)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationComplexityMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 168
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationComplexityMiddleware.cs(168)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationCacheMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 51
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationCacheMiddleware.cs(51)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.OperationCacheMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 71
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\OperationCacheMiddleware.cs(71)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentValidationMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 86
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentValidationMiddleware.cs(86)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentValidationMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 97
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentValidationMiddleware.cs(97)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentParserMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 86
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentParserMiddleware.cs(86)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentParserMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 107
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentParserMiddleware.cs(107)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentCacheMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 76
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentCacheMiddleware.cs(76)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.DocumentCacheMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 95
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\DocumentCacheMiddleware.cs(95)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.TimeoutMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 34
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\TimeoutMiddleware.cs(34)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.TimeoutMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 95
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\TimeoutMiddleware.cs(95)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.ExceptionMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 24
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\ExceptionMiddleware.cs(24)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.ExceptionMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 49
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\ExceptionMiddleware.cs(49)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.InstrumentationMiddleware.InvokeAsync(HotChocolate.Execution.IRequestContext context) Line 26
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\InstrumentationMiddleware.cs(26)
HotChocolate.Execution.dll!HotChocolate.Execution.Pipeline.InstrumentationMiddleware.Create.AnonymousMethod__1(HotChocolate.Execution.IRequestContext context) Line 40
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Pipeline\InstrumentationMiddleware.cs(40)
HotChocolate.Execution.dll!HotChocolate.Execution.RequestExecutor.ExecuteAsync(HotChocolate.Execution.IQueryRequest request, bool scopeDataLoader, System.Threading.CancellationToken cancellationToken) Line 119
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\RequestExecutor.cs(119)
HotChocolate.Execution.dll!HotChocolate.Execution.RequestExecutor.ExecuteAsync(HotChocolate.Execution.IQueryRequest request, System.Threading.CancellationToken cancellationToken) Line 75
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\RequestExecutor.cs(75)
HotChocolate.Execution.dll!HotChocolate.Execution.ExecutionRequestExecutorExtensions.ExecuteAsync(HotChocolate.Execution.IRequestExecutor executor, string query, System.Collections.Generic.Dictionary<string, object> variableValues) Line 111
    at F:\Github\graphql-platform\src\HotChocolate\Core\src\Execution\Extensions\ExecutionRequestExecutorExtensions.cs(111)
HotChocolate.Types.Tests.dll!HotChocolate.Types.DirectiveTypeTests.Use_DoesTakeArguments() Line 394
    at F:\Github\graphql-platform\src\HotChocolate\Core\test\Types.Tests\Types\DirectiveTypeTests.cs(394)