Open gao-artur opened 2 months ago
Sounds like a great idea!
You'd probably have to make a custom scalar to allow this however.
Which also means it's a breaking change unfortunately.
Maybe a ctor option to the directive to use the custom scalar so it's not breaking by default?
I don't think I understand. Why does it require a custom scalar? The ApplyDirective
receives an object
as an argument, so it can be anything. The only change is required in PatternMatchingVisitor
to try cast the applied?.FindArgument("regex")?.Value
to Regex
in addition to string
. Am I missing something?
Schema validation should fail to coerce the argument to StringGraphType (see https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL/Types/Directives/Custom/PatternMatchingDirective.cs ). Unless we don't have schema validation for applied directives' arguments. In which case the schema printing code would crash when printing the schema within the ScalarGraphType.ToAst method since it won't know how to convert a RegEx class to an AST.
With a custom scalar, ParseLiteral can support strings, and ParseValue can support both strings and RegEx instances. The ToAST method can be overridden to provide a string representation of the RegEx instance so schema printing still works.
At least, without trying any code, that's my best guess as to what will happen.
You are right. The visitor works correctly, but schema printing fails. But I don't understand your proposal with a custom scalar...
Currently, the
PatternMatchingVisitor
only supportsstring
argumenthttps://github.com/graphql-dotnet/graphql-dotnet/blob/22052e73d734d3f0b60b52a04897afb12656c55a/src/GraphQL/Utilities/Visitors/Custom/PatternMatchingVisitor.cs#L40-L41
It can be useful also to add support for
Regex
arguments