Skip to content
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

Bring back validator error extensions #1174

Open
cortopy opened this issue Dec 15, 2022 · 3 comments
Open

Bring back validator error extensions #1174

cortopy opened this issue Dec 15, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@cortopy
Copy link

cortopy commented Dec 15, 2022

Description of the feature

I've been digging into past versions and it seems that there used to be trait called InputValueValidator that allowed to return an Error with extensions after this PR #564

This solved this request #385, which is exactly what I'm trying to achieve.

Without Error extensions, it's difficult for frontend clients to know what exactly is wrong, but the current trait of CustomValidator only allows to return a String in the check method.

Could the old behaviour be brought back? I don't see any removal notes from the CHANGELOG either

@cortopy cortopy added the enhancement New feature or request label Dec 15, 2022
@sunli829
Copy link
Collaborator

Fixed in master, here is the example:

InputValueError::custom(format!("expect 100, actual {}", value))

@sunli829
Copy link
Collaborator

Released in v5.0.4

@cortopy
Copy link
Author

cortopy commented Dec 19, 2022

Thanks so much @sunli829 for being this quick!!!

I've tested the new version and it's great but I still can't use custom Graphql errors.

For example:

#[derive(Debug, Error)]
pub enum GraphqlError {
    #[error("InternalServerError")]
    InternalServerError(String),
    #[error("Could not find resource")]
    NotFound,
    #[error("Unauthenticated")]
    Unauthenticated,
    #[error("Invalid user input")]
    BadUserInput(HashMap<String, String>),
}

impl ErrorExtensions for GraphqlError {
    fn extend(&self) -> FieldError {
      ...
    }
}

I can't do this:

let fields = HashMap::new();
let error: InputValueError = GraphqlError::BadUserInput(fields).extend().into()

because async_graphql::Error doesn't implement std::fmt::Display

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants