Describe the bug
When GraphQL::Dataloader is active and a runtime directive has a validator on one of its arguments (e.g. validates: { allow_blank: false }), passing an invalid value causes an unhandled exception that kills the job fiber rather than surfacing as a GraphQL error in the response.
A directive defined like this:
class Directives::Feature < GraphQL::Schema::Directive
argument :if, String, required: false, validates: { allow_blank: false }
def self.include?(_object, arguments, _context)
# ...
end
end
Used in a query like:
query {
someField @feature(if: "")
}
With use GraphQL::Dataloader in the schema, this crashes with:
GraphQL::Schema::Validator::ValidationFailedError: if can't be blank
graphql-2.5.14/lib/graphql/schema/validator.rb:147:in `validate!'
Without use GraphQL::Dataloader, the same query returns a proper GraphQL error response.
Versions
graphql-enterprise (1.5.9)
graphql (>= 2.0.18)
graphql-pro (>= 1.24.0)
graphql-pro (1.29.14)
graphql (>= 1.7.5)
Rails 8.0.4
Expected behavior
directives_include? should rescue GraphQL::ExecutionError from the arguments() call and route it through continue_value or add it to context.errors directly
Additional context
Add any other context about the problem here.
With these details, we can efficiently hunt down the bug!
Describe the bug
When
GraphQL::Dataloaderis active and a runtime directive has a validator on one of its arguments (e.g.validates: { allow_blank: false }), passing an invalid value causes an unhandled exception that kills the job fiber rather than surfacing as a GraphQL error in the response.A directive defined like this:
Used in a query like:
With
use GraphQL::Dataloaderin the schema, this crashes with:Without
use GraphQL::Dataloader, the same query returns a proper GraphQL error response.Versions
Rails 8.0.4
Expected behavior
directives_include?should rescueGraphQL::ExecutionErrorfrom thearguments()call and route it throughcontinue_valueor add it tocontext.errorsdirectlyAdditional context
Add any other context about the problem here.
With these details, we can efficiently hunt down the bug!