pub struct ValidationError { /* private fields */ }Expand description
A validation error is a Serializable object that contains the path where the validation error
of a certain kind ocurred, and an optional and arbitrary piece of meta-information.
Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub fn unexpected_runtime_error(message: String) -> Self
pub fn unexpected_runtime_error(message: String) -> Self
Creates an ValidationErrorKind::UnexpectedRuntimeError kind of error when something unexpected
happen at runtime after a query was properly validated by the parser against the schema.
Sourcepub fn empty_selection(
selection_path: Vec<&str>,
output_type_description: OutputTypeDescription,
) -> Self
pub fn empty_selection( selection_path: Vec<&str>, output_type_description: OutputTypeDescription, ) -> Self
Creates an ValidationErrorKind::EmptySelection kind of error, which happens when the
selection of fields is empty for a query.
Example json query:
{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: {} } }
Sourcepub fn invalid_argument_type(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
argument_description: ArgumentDescription<'_>,
inferred_argument_type: String,
) -> Self
pub fn invalid_argument_type( selection_path: Vec<&str>, argument_path: Vec<&str>, argument_description: ArgumentDescription<'_>, inferred_argument_type: String, ) -> Self
Creates an ValidationErrorKind::InvalidArgumentType kind of error, which happens when the
argument is of a type that is incompatible with its definition.
Say the schema type for user.id is Int
The example json query will fail, as it’s trying to pass a string instead.
{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “id”: “a22b8732-be32-4a30-9b38-78843aaa48f8” } }, “selection”: { “$scalars”: true } } }
Sourcepub fn invalid_argument_value(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
value: String,
expected_argument_type: &str,
underlying_err: Option<Box<dyn Error>>,
) -> Self
pub fn invalid_argument_value( selection_path: Vec<&str>, argument_path: Vec<&str>, value: String, expected_argument_type: &str, underlying_err: Option<Box<dyn Error>>, ) -> Self
Creates an ValidationErrorKind::InvalidArgumentValue kind of error, which happens when the
argument is of the correct type, but its value is invalid, said a negative number on a type
that is integer but which values should be non-negative. Or a uuid which type is correctly
a string, but its format is not the appropriate.
Say the schema type for user.id is Int
The example json query will fail, as it’s trying to pass a string instead.
{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “dob”: “invalid date” } }, “selection”: { “$scalars”: true } } }
Sourcepub fn some_fields_missing(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
min_field_count: Option<usize>,
max_field_count: Option<usize>,
required_fields: Option<Vec<Cow<'_, str>>>,
provided_field_count: usize,
input_type_description: &InputTypeDescription,
) -> Self
pub fn some_fields_missing( selection_path: Vec<&str>, argument_path: Vec<&str>, min_field_count: Option<usize>, max_field_count: Option<usize>, required_fields: Option<Vec<Cow<'_, str>>>, provided_field_count: usize, input_type_description: &InputTypeDescription, ) -> Self
Creates an ValidationErrorKind::SomeFieldsMissing kind of error, which happens when
there are some fields missing from a query
Sourcepub fn too_many_fields_given(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
min_field_count: Option<usize>,
max_field_count: Option<usize>,
required_fields: Option<Vec<Cow<'_, str>>>,
provided_field_count: usize,
input_type_description: &InputTypeDescription,
) -> Self
pub fn too_many_fields_given( selection_path: Vec<&str>, argument_path: Vec<&str>, min_field_count: Option<usize>, max_field_count: Option<usize>, required_fields: Option<Vec<Cow<'_, str>>>, provided_field_count: usize, input_type_description: &InputTypeDescription, ) -> Self
Creates an ValidationErrorKind::SomeFieldsMissing kind of error, which happens when
there are more fields given than the ones a type accept
Sourcepub fn required_argument_missing(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
input_type_descriptions: &[InputTypeDescription],
) -> Self
pub fn required_argument_missing( selection_path: Vec<&str>, argument_path: Vec<&str>, input_type_descriptions: &[InputTypeDescription], ) -> Self
Creates an ValidationErrorKind::RequiredArgumentMissing kind of error, which happens
when there is a missing argument for a field missing, like the where field below.
Example json query:
{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: {} } }
Sourcepub fn conditionally_required_argument_missing(
selection_path: &[&str],
argument_path: &[&str],
dependent_argument_path: &[&str],
input_type_descriptions: &[InputTypeDescription],
) -> Self
pub fn conditionally_required_argument_missing( selection_path: &[&str], argument_path: &[&str], dependent_argument_path: &[&str], input_type_descriptions: &[InputTypeDescription], ) -> Self
Creates a ValidationErrorKind::RequiredArgumentMissing kind of error
for a conditionally required argument which needs to be present in the
current query because another argument which depends on it was provided.
Example json query (take requires orderBy in views):
{
"action": "findMany",
"modelName": "UserView",
"query": {
"arguments": {
"take": "1"
},
"selection": {
"$scalars": true
}
}
}Sourcepub fn unknown_argument(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
valid_argument_descriptions: Vec<ArgumentDescription<'_>>,
) -> Self
pub fn unknown_argument( selection_path: Vec<&str>, argument_path: Vec<&str>, valid_argument_descriptions: Vec<ArgumentDescription<'_>>, ) -> Self
Creates an ValidationErrorKind::UnknownArgument kind of error, which happens when the
arguments for a query are not congruent with those expressed in the schema
Example json query:
{
“action”: “findMany”,
“modelName”: “User”,
“query”: {
“arguments”: {
“foo”: “123”
},
“selection”: {
“$scalars”: true
}
}
}
Todo: add the given type to the meta
Sourcepub fn unknown_input_field(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
input_type_description: InputTypeDescription,
) -> Self
pub fn unknown_input_field( selection_path: Vec<&str>, argument_path: Vec<&str>, input_type_description: InputTypeDescription, ) -> Self
Creates a ValidationErrorKind::UnknownInputField kind of error, which happens when the
argument value for a query contains a field that does not exist in the schema for the
input type.
TODO: how is this conceptually different from an unknown argument? This used to be a FieldNotFoundError (see old code), but the same FieldNotFoundError was used to denote what’s now an UnknownSelectionField.
Example json query:
{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “foo”: 2 } }, “selection”: { “$scalars”: true } } }
Sourcepub fn unknown_selection_field(
selection_path: Vec<&str>,
output_type_description: OutputTypeDescription,
) -> Self
pub fn unknown_selection_field( selection_path: Vec<&str>, output_type_description: OutputTypeDescription, ) -> Self
Creates an ValidationErrorKind::UnknownSelectionField kind of error, which happens when
the selection of fields for a query contains a field that does not exist in the schema for the
enclosing type
Example json query:
{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: { “notAField”: true } }
Sourcepub fn selection_set_on_scalar(
field_name: String,
selection_path: Vec<&str>,
) -> Self
pub fn selection_set_on_scalar( field_name: String, selection_path: Vec<&str>, ) -> Self
Creates an ValidationErrorKind::SelectionSetOnScalar kind of error, which happens when there
is a nested selection block on a scalar field
Example json query:
{ “action”: “findMany”, “modelName”: “User”, “query”: { “selection”: { “email”: { “selection”: { “id”: true } } } } }
Sourcepub fn union(errors: Vec<ValidationError>) -> Self
pub fn union(errors: Vec<ValidationError>) -> Self
Creates an error that is the union of different validation errors
Sourcepub fn value_too_large(
selection_path: Vec<&str>,
argument_path: Vec<&str>,
value: String,
) -> Self
pub fn value_too_large( selection_path: Vec<&str>, argument_path: Vec<&str>, value: String, ) -> Self
Creates an ValidationErrorKind::ValueTooLarge kind of error, which happens when the value
for a float or integer coming from the JS client is larger than what can fit in an i64
(2^64 - 1 = 18446744073709550000)
Example json query
{ “action”: “findMany”, “modelName”: “User”, “query”: { “arguments”: { “where”: { “id”: 18446744073709550000 // too large } }, “selection”: { “$scalars”: true } } }
Trait Implementations§
Source§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl Display for ValidationError
impl Display for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<ValidationError> for Error
impl From<ValidationError> for Error
Source§fn from(err: ValidationError) -> Self
fn from(err: ValidationError) -> Self
Source§impl From<ValidationError> for KnownError
impl From<ValidationError> for KnownError
Source§fn from(err: ValidationError) -> Self
fn from(err: ValidationError) -> Self
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin for ValidationError
impl UnsafeUnpin for ValidationError
impl UnwindSafe for ValidationError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more