1use graphql_parser::query::*;
2use std::fmt;
3
4#[derive(Debug)]
6pub enum GraphQLError {
7 OperationNotFound,
9
10 FragmentNotFound,
12
13 InfiniteFragmentRecursionError(String),
15
16 Parse(ParseError),
18
19 MultipleOperation,
21
22 AnonymousOperation,
24}
25
26impl fmt::Display for GraphQLError {
27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28 match *self {
29 GraphQLError::Parse(ref e) => e.fmt(f),
30 GraphQLError::OperationNotFound => {
31 write!(f, "The input operation is not found in the document")
32 }
33 GraphQLError::FragmentNotFound => {
34 write!(f, "The query does not contain the fragment which is used")
35 }
36 GraphQLError::InfiniteFragmentRecursionError(ref fragment_name) => {
37 write!(f, "Infinte Fragment Recursion detected {}", fragment_name)
38 }
39 GraphQLError::MultipleOperation => write!(
40 f,
41 "Multiple Operations found in the query. Operation Name is required"
42 ),
43 GraphQLError::AnonymousOperation => write!(
44 f,
45 "Cannot generate id for anonymous query. Use an operation name"
46 ),
47 }
48 }
49}
50
51impl From<ParseError> for GraphQLError {
52 fn from(err: ParseError) -> GraphQLError {
53 GraphQLError::Parse(err)
54 }
55}