Skip to content

directives_include? has no rescue for GraphQL::ExecutionError raised during argument coercion, causing fiber crash with GraphQL::Dataloader #5574

@Kev0264

Description

@Kev0264

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions