At the moment, I'm throwing RuntimeException's to return GraphQL validation errors. It works surprisingly well, with the exception that it throws horrible errors with large stack traces in my logs.
Here you can see I'm checking the submitted new user registration mutation to be sure the passwords match one another and the email address isn't already in use.
What is the correct way to do this in GraphQL SPQR Spring Boot Starter.
@GraphQLMutation (name="register")
public User register(@GraphQLArgument(name="firstname") String firstname, @GraphQLArgument(name="lastname") String lastname, @GraphQLArgument(name="email") String email, @GraphQLArgument(name="msisdn") String msisdn, @GraphQLArgument(name="password") String password, @GraphQLArgument (name="confirmPassword") String confirmPassword) {
if (userRepo.findByEmail(email) != null) {
throw new RuntimeException("User already exists");
}
if (!password.equals(confirmPassword)) {
throw new RuntimeException("Passwords do not match");
}
User newUser = new User();
//...
return userRepo.save(newUser);
}