122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/graphql/schema/validator.rb', line 122
def self.validate!(validators, object, context, value, as: nil)
all_errors = EMPTY_ARRAY
validators.each do |validator|
validated = as || validator.validated
errors = validator.validate(object, context, value)
if errors &&
(errors.is_a?(Array) && errors != EMPTY_ARRAY) ||
(errors.is_a?(String))
if all_errors.frozen?
all_errors = []
end
interpolation_vars = { validated: validated.graphql_name, value: value.inspect }
if errors.is_a?(String)
all_errors << (errors % interpolation_vars)
else
errors = errors.map { |e| e % interpolation_vars }
all_errors.concat(errors)
end
end
end
if !all_errors.empty?
raise ValidationFailedError.new(errors: all_errors)
end
nil
end
|