Fix the test code and add docs.

This commit is contained in:
Sunli 2020-09-01 09:10:12 +08:00
parent 945cd72869
commit d04b5b675f
5 changed files with 32 additions and 15 deletions

View File

@ -53,7 +53,6 @@ chrono-tz = { version = "0.5.1", optional = true }
[dev-dependencies]
async-std = { version = "1.5.0", features = ["attributes"] }
serde = "1.0.104"
[workspace]
members = [

View File

@ -174,7 +174,10 @@ pub enum QueryError {
/// Parsing of an input value failed.
#[error("Failed to parse input value: {reason}")]
ParseInputValue { reason: String },
ParseInputValue {
/// The reason for the failure to resolve.
reason: String,
},
/// A field was not found on an object type.
#[error("Cannot query field \"{field_name}\" on type \"{object}\".")]
@ -287,9 +290,11 @@ pub enum QueryError {
extended_error: Option<serde_json::Value>,
},
/// Entity not found.
#[error("Entity not found")]
EntityNotFound,
/// "__typename" must be an existing string.
#[error("\"__typename\" must be an existing string")]
TypeNameNotExists,
}
@ -324,12 +329,15 @@ pub enum ParseRequestError {
#[error("Invalid multipart data")]
InvalidMultipart(multer::Error),
/// Missing "operators" part for multipart request.
#[error("Missing \"operators\" part")]
MissingOperatorsPart,
/// Missing "map" part for multipart request.
#[error("Missing \"map\" part")]
MissingMapPart,
/// It's not an upload operation
#[error("It's not an upload operation")]
NotUpload,
@ -342,10 +350,13 @@ pub enum ParseRequestError {
PayloadTooLarge,
}
#[allow(missing_docs)]
/// Verification error.
#[derive(Debug, PartialEq)]
pub struct RuleError {
/// Location of this error in query string.
pub locations: Vec<Pos>,
/// A description of this error.
pub message: String,
}
@ -361,11 +372,18 @@ pub enum Error {
Query {
/// The position at which the processing failed.
pos: Pos,
/// Node path.
path: Option<serde_json::Value>,
/// The query error.
err: QueryError,
},
/// The query statement verification failed.
#[error("Rule error")]
Rule { errors: Vec<RuleError> },
Rule {
/// List of errors.
errors: Vec<RuleError>,
},
}

View File

@ -33,11 +33,11 @@ pub async fn test_enum_type() {
}
let schema = Schema::new(Root { value: MyEnum::A }, EmptyMutation, EmptySubscription);
let query = r#"{{
let query = r#"{
value
testArg(input: A)
testInput(input: {{value: B}}) }}
"#
testInput(input: {value: B})
}"#
.to_owned();
assert_eq!(
schema.execute(&query).await.unwrap().data,

View File

@ -67,11 +67,11 @@ pub async fn test_input_object_default_value() {
}
let schema = Schema::new(Root, EmptyMutation, EmptySubscription);
let query = r#"{{
a(input:{{e:777}}) {{
let query = r#"{
a(input:{e:777}) {
a b c d e
}}
}}"#
}
}"#
.to_owned();
assert_eq!(
schema.execute(&query).await.unwrap().data,

View File

@ -47,16 +47,16 @@ pub async fn test_optional_type() {
EmptyMutation,
EmptySubscription,
);
let query = r#"{{
let query = r#"{
value1
value1Ref
value2
value2Ref
testArg1: testArg(input: 10)
testArg2: testArg
testInput1: testInput(input: {{value: 10}})
testInput2: testInput(input: {{}})
}}"#
testInput1: testInput(input: {value: 10})
testInput2: testInput(input: {})
}"#
.to_owned();
assert_eq!(
schema.execute(&query).await.unwrap().data,