You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a directive, if one sets validations for the arguments, unexpected things happen.
For example...
moduleDirectivesclassFeature < GraphQL::Schema::Directivedescription"Directs the executor to run this only based on the state of a server-side feature flag."argument:if,String,required: false,validates: {format: /\d+/,},description: "Include the element if the feature flag is enabled."argument:unless,String,required: false,validates: {format: /\d+/,},description: "Include the element if the feature flag is disabled."# validates required: { one_of: %i[if unless] } # Doesn't work at all
...
end
With an argument definition like this we would expect a validation failure when invoked like @feature(if: "flag") because the validation checks for numbers instead of strings (this is a contrived validation, BTW).
What actually happens is that the include? method is called with a GraphQL::ExecutionError as the second argument (which should be a GraphQL::Execution::Interpreter::Arguments of the directive).
I also observe that it is not possible to add a validates requires: { one_of: %i[if unless] } for a directive, that just fails.
Hey, sorry for the trouble with this. Directive arguments have definitely not gotten a lot of attention 😅 . I agree it should work the way you describe here. I'll take a look soon and follow up here!
Describe the bug
When defining a directive, if one sets validations for the arguments, unexpected things happen.
For example...
With an argument definition like this we would expect a validation failure when invoked like
@feature(if: "flag")
because the validation checks for numbers instead of strings (this is a contrived validation, BTW).What actually happens is that the
include?
method is called with aGraphQL::ExecutionError
as the second argument (which should be aGraphQL::Execution::Interpreter::Arguments
of the directive).I also observe that it is not possible to add a
validates requires: { one_of: %i[if unless] }
for a directive, that just fails.Versions
Rails 7.2.2.1
Expected behavior
validates ...
should work as documented for directive arguments as well.The text was updated successfully, but these errors were encountered: