GraphQL
Most of the time, validation for the GraphQL API does not require extra work:
- GraphQLite translates your models (with
@Typeand@SourceFieldannotations) into strongly typed GraphQL types. - GraphQLite translates your use cases' methods' signatures
(with
@Mutationor@Queryannotations) into strongly typed GraphQL mutations or queries. - GraphQLite resolves the
InvalidModelandInvalidStorableexceptions into valid GraphQL responses (400 HTTP code).
However, you may have some use cases that are GraphQL mutations or queries, and these use cases do not manipulate models
(i.e., no InvalidModel nor InvalidStorable exceptions).
For such scenarios, GraphQLite provides the @Assertion annotation:
src/api/src/UseCase/User/ResetPassword/ResetPassword.php
Here, GraphQLite validates the email argument according to the list of
constraints.
Only caveat is that it does not work if you call your use case in PHP.