interface UserError
Base Interface all user-facing GraphQL errors should implement. This is used to provide a common way to handle errors in the frontend.
A possible scenario would be having a create_user mutation that returns different types of error if the email is already in use, the password is too short, etc.
It could be declared like this:
class UsernameTakenError(ObjectType):
class Meta:
interfaces = (UserError, )
suggestedUsernames = List(String)
class PasswordTooShortError(ObjectType):
class Meta:
interfaces = (UserError, )
class UserCreationError(Union):
class Meta:
types = (UsernameTakenError, PasswordTooShortError)
class CreateUser(Mutation):
user = Field(User)
errors = List(UserCreationError)
And it would be queried like this:
mutation {
createUser(email: foo@bar.com, password: "123") {
user {
id
}
errors {
__typename
... on UserError {
message
}
... on UsernameTakenError {
message
suggestedUsername
}
... on PasswordTooShortError {
message
}
}
}
}
If new errors are added, and they implement the UserError interface, the frontend will be able to handle at least the message field without any changes.
based on: https://productionreadygraphql.com/2020-08-01-guide-to-graphql-errors
Fields
| Field | Type | Description |
|---|---|---|
message | String! |
Referenced By
- AllocationErrorType Type
- MissingAllocationType Type