Skip to content

Print warning when custom validators are detected #5290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/graphql/schema/member/has_validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module HasValidators
# @param validation_config [Hash{Symbol => Hash}]
# @return [void]
def validates(validation_config)
validation_config.each do |validator_name, _options|
if validator_name.is_a?(Class) || !GraphQL::Schema::Validator.all_validators.key?(validator_name)
GraphQL::Schema::Validator::CustomValidatorWarning.warn_for(validator_name)
end
end

new_validators = GraphQL::Schema::Validator.from_config(self, validation_config)
@own_validators ||= []
@own_validators.concat(new_validators)
Expand Down
1 change: 1 addition & 0 deletions lib/graphql/schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,4 @@ def self.validate!(validators, object, context, value, as: nil)
GraphQL::Schema::Validator.install(:allow_blank, GraphQL::Schema::Validator::AllowBlankValidator)
require "graphql/schema/validator/all_validator"
GraphQL::Schema::Validator.install(:all, GraphQL::Schema::Validator::AllValidator)
require "graphql/schema/validator/custom_validator_warning"
22 changes: 22 additions & 0 deletions lib/graphql/schema/validator/custom_validator_warning.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module GraphQL
class Schema
class Validator
module CustomValidatorWarning
def self.warn_for(validator_name)
border = "*" * 30
timestamp = "[#{Time.now.strftime('%Y-%m-%dT%H:%M:%S.%6N')} ##{Process.pid}]"
warn <<~WARN
#{border}
WARNING: GraphQL Custom validator registered: #{validator_name}
Note that custom validators with I/O operations may fail unexpectedly due to GraphQL's default validate_timeout setting. Long-running I/O operations may not be killed halfway through, resulting in unpredictable behavior. See https://graphql-ruby.org/queries/timeout.html#validation-and-analysis for more information.
#{caller(3,1).first}
#{timestamp}
#{border}
WARN
end
end
end
end
end
Loading