GraphQL
Most of the time, validation for the GraphQL API does not require extra work:
- GraphQLite translates your models (with
@Type
and@SourceField
annotations) into strongly typed GraphQL types. - GraphQLite translates your use cases' methods' signatures
(with
@Mutation
or@Query
annotations) into strongly typed GraphQL mutations or queries. - GraphQLite resolves the
InvalidModel
andInvalidStorable
exceptions 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.