postrust_graphql/error.rs
1//! GraphQL-specific error types.
2
3use thiserror::Error;
4
5/// Errors that can occur during GraphQL operations.
6#[derive(Debug, Error)]
7pub enum GraphQLError {
8 /// The schema could not be built from the database's metadata. A fault in
9 /// the translation, not in the request: no query has been seen yet.
10 #[error("Schema generation failed: {0}")]
11 SchemaGeneration(String),
12
13 /// The built schema was rejected, or a lookup into it failed.
14 #[error("Schema error: {0}")]
15 SchemaError(String),
16
17 /// The query parsed and resolving it failed.
18 #[error("Query execution failed: {0}")]
19 QueryExecution(String),
20
21 /// A `where` argument that does not describe a filter this server can
22 /// express -- an unknown operator, or an operand of the wrong shape.
23 #[error("Invalid filter: {0}")]
24 InvalidFilter(String),
25
26 /// A PostgreSQL type with no GraphQL equivalent to map it onto.
27 #[error("Type mapping error: {0}")]
28 TypeMapping(String),
29
30 /// The field needs an identity and the request carried none.
31 #[error("Authentication required")]
32 AuthenticationRequired,
33
34 /// PostgreSQL refused the query. Its message is carried verbatim.
35 #[error("Database error: {0}")]
36 Database(String),
37}
38
39/// `Result` with this crate's error type as the default failure.
40pub type Result<T> = std::result::Result<T, GraphQLError>;