Update docs
This commit is contained in:
parent
48d45309be
commit
6958202238
|
@ -3,6 +3,7 @@
|
|||
//!
|
||||
//! It uses the [pest](https://crates.io/crates/pest) crate to parse the input and then transforms
|
||||
//! it into Rust types.
|
||||
#![warn(missing_docs)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use crate::types::OperationType;
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Represents a GraphQL type
|
||||
/// Represents a GraphQL type.
|
||||
///
|
||||
/// All GraphQL types implement this trait, such as `Scalar`, `Object`, `Union` ...
|
||||
pub trait Type {
|
||||
|
@ -29,7 +29,7 @@ pub trait Type {
|
|||
fn create_type_info(registry: &mut registry::Registry) -> String;
|
||||
}
|
||||
|
||||
/// Represents a GraphQL input value
|
||||
/// Represents a GraphQL input value.
|
||||
pub trait InputValueType: Type + Sized {
|
||||
/// Parse from `Value`. None represents undefined.
|
||||
fn parse(value: Option<Value>) -> InputValueResult<Self>;
|
||||
|
@ -38,7 +38,7 @@ pub trait InputValueType: Type + Sized {
|
|||
fn to_value(&self) -> Value;
|
||||
}
|
||||
|
||||
/// Represents a GraphQL output value
|
||||
/// Represents a GraphQL output value.
|
||||
#[async_trait::async_trait]
|
||||
pub trait OutputValueType: Type {
|
||||
/// Resolve an output value to `async_graphql::Value`.
|
||||
|
|
|
@ -148,8 +148,6 @@ pub use futures;
|
|||
#[doc(hidden)]
|
||||
pub use indexmap;
|
||||
#[doc(hidden)]
|
||||
pub use serde_json;
|
||||
#[doc(hidden)]
|
||||
pub use static_assertions;
|
||||
#[doc(hidden)]
|
||||
pub use subscription::SubscriptionType;
|
||||
|
@ -177,6 +175,12 @@ pub use response::{BatchResponse, Response};
|
|||
pub use schema::{Schema, SchemaBuilder, SchemaEnv};
|
||||
pub use validation::ValidationMode;
|
||||
|
||||
/// An alias of [async_graphql::Error](struct.Error.html).
|
||||
pub type FieldError = Error;
|
||||
|
||||
/// An alias of [async_graphql::Result](type.Result.html).
|
||||
pub type FieldResult<T> = Result<T>;
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use parser::{Pos, Positioned};
|
||||
pub use types::*;
|
||||
|
|
|
@ -166,12 +166,11 @@ impl From<Vec<Request>> for BatchRequest {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
use crate::*;
|
||||
|
||||
#[test]
|
||||
fn test_request() {
|
||||
let request: Request = serde_json::from_value(json! ({
|
||||
let request: Request = from_value(value! ({
|
||||
"query": "{ a b c }"
|
||||
}))
|
||||
.unwrap();
|
||||
|
@ -182,7 +181,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_request_with_operation_name() {
|
||||
let request: Request = serde_json::from_value(json! ({
|
||||
let request: Request = from_value(value! ({
|
||||
"query": "{ a b c }",
|
||||
"operationName": "a"
|
||||
}))
|
||||
|
@ -194,7 +193,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_request_with_variables() {
|
||||
let request: Request = serde_json::from_value(json! ({
|
||||
let request: Request = from_value(value! ({
|
||||
"query": "{ a b c }",
|
||||
"variables": {
|
||||
"v1": 100,
|
||||
|
@ -204,8 +203,8 @@ mod tests {
|
|||
}))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
request.variables.into_value().into_json().unwrap(),
|
||||
json!({
|
||||
request.variables.into_value(),
|
||||
value!({
|
||||
"v1": 100,
|
||||
"v2": [1, 2, 3],
|
||||
"v3": "str",
|
||||
|
@ -217,7 +216,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_deserialize_request_with_null_variables() {
|
||||
let request: Request = serde_json::from_value(json! ({
|
||||
let request: Request = from_value(value! ({
|
||||
"query": "{ a b c }",
|
||||
"variables": null
|
||||
}))
|
||||
|
@ -228,7 +227,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_batch_request_single() {
|
||||
let request: BatchRequest = serde_json::from_value(json! ({
|
||||
let request: BatchRequest = from_value(value! ({
|
||||
"query": "{ a b c }"
|
||||
}))
|
||||
.unwrap();
|
||||
|
@ -244,7 +243,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_batch_request_batch() {
|
||||
let request: BatchRequest = serde_json::from_value(json!([
|
||||
let request: BatchRequest = from_value(value!([
|
||||
{
|
||||
"query": "{ a b c }"
|
||||
},
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::collections::BTreeMap;
|
|||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
/// A GraphQL container.
|
||||
/// Represents a GraphQL container object.
|
||||
///
|
||||
/// This helper trait allows the type to call `resolve_container` on itself in its
|
||||
/// `OutputValueType::resolve` implementation.
|
||||
|
|
2
src/types/external/floats.rs
vendored
2
src/types/external/floats.rs
vendored
|
@ -46,6 +46,6 @@ impl ScalarType for f64 {
|
|||
}
|
||||
|
||||
fn to_value(&self) -> Value {
|
||||
Value::Number(serde_json::Number::from_f64(*self as f64).unwrap())
|
||||
Value::Number(Number::from_f64(*self as f64).unwrap())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub async fn test_enum_derive_and_item_attributes() {
|
|||
}
|
||||
|
||||
assert_eq!(
|
||||
serde_json::from_str::<TestStruct>(r#"{ "value" : "Other" }"#).unwrap(),
|
||||
from_value::<TestStruct>(value!({"value": "Other"})).unwrap(),
|
||||
TestStruct { value: Test::Real }
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,14 +7,13 @@ use serde::forward_to_deserialize_any;
|
|||
use std::collections::BTreeMap;
|
||||
use std::{fmt, vec};
|
||||
|
||||
/// This type represents errors that can occur when deserializing.
|
||||
#[derive(Debug)]
|
||||
pub enum DeserializerError {
|
||||
Custom(String),
|
||||
}
|
||||
pub struct DeserializerError(String);
|
||||
|
||||
impl de::Error for DeserializerError {
|
||||
fn custom<T: fmt::Display>(msg: T) -> Self {
|
||||
DeserializerError::Custom(msg.to_string())
|
||||
DeserializerError(msg.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,15 +25,15 @@ impl std::error::Error for DeserializerError {
|
|||
|
||||
impl fmt::Display for DeserializerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
DeserializerError::Custom(ref msg) => write!(f, "{}", msg),
|
||||
match self {
|
||||
DeserializerError(msg) => write!(f, "{}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<de::value::Error> for DeserializerError {
|
||||
fn from(e: de::value::Error) -> DeserializerError {
|
||||
DeserializerError::Custom(e.to_string())
|
||||
DeserializerError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +101,7 @@ impl<'de> de::Deserializer<'de> for ConstValue {
|
|||
ConstValue::Null => visitor.visit_unit(),
|
||||
ConstValue::Number(v) => v
|
||||
.deserialize_any(visitor)
|
||||
.map_err(|err| DeserializerError::Custom(err.to_string())),
|
||||
.map_err(|err| DeserializerError(err.to_string())),
|
||||
ConstValue::String(v) => visitor.visit_str(&v),
|
||||
ConstValue::Boolean(v) => visitor.visit_bool(v),
|
||||
ConstValue::Enum(v) => visitor.visit_str(v.as_str()),
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
//! Value for GraphQL. Used in the [`async-graphql`](https://crates.io/crates/async-graphql) crate.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
mod de;
|
||||
mod macros;
|
||||
mod ser;
|
||||
|
|
|
@ -5,15 +5,14 @@ use std::collections::BTreeMap;
|
|||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
/// This type represents errors that can occur when serializing.
|
||||
#[derive(Debug)]
|
||||
pub enum SerializerError {
|
||||
Custom(String),
|
||||
}
|
||||
pub struct SerializerError(String);
|
||||
|
||||
impl fmt::Display for SerializerError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
SerializerError::Custom(ref s) => fmt.write_str(s),
|
||||
SerializerError(ref s) => fmt.write_str(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ impl Error for SerializerError {
|
|||
|
||||
impl ser::Error for SerializerError {
|
||||
fn custom<T: fmt::Display>(msg: T) -> SerializerError {
|
||||
SerializerError::Custom(msg.to_string())
|
||||
SerializerError(msg.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,9 +95,7 @@ impl ser::Serializer for Serializer {
|
|||
}
|
||||
|
||||
fn serialize_char(self, _v: char) -> Result<Self::Ok, Self::Error> {
|
||||
Err(SerializerError::Custom(
|
||||
"char is not supported.".to_string(),
|
||||
))
|
||||
Err(SerializerError("char is not supported.".to_string()))
|
||||
}
|
||||
|
||||
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
||||
|
@ -106,9 +103,7 @@ impl ser::Serializer for Serializer {
|
|||
}
|
||||
|
||||
fn serialize_bytes(self, _v: &[u8]) -> Result<Self::Ok, Self::Error> {
|
||||
Err(SerializerError::Custom(
|
||||
"bytes is not supported.".to_string(),
|
||||
))
|
||||
Err(SerializerError("bytes is not supported.".to_string()))
|
||||
}
|
||||
|
||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
||||
|
@ -389,7 +384,7 @@ impl ser::SerializeStructVariant for SerializeStructVariant {
|
|||
}
|
||||
|
||||
fn key_must_be_a_string() -> SerializerError {
|
||||
SerializerError::Custom("Key must be a string".to_string())
|
||||
SerializerError("Key must be a string".to_string())
|
||||
}
|
||||
|
||||
struct MapKeySerializer;
|
||||
|
|
Loading…
Reference in New Issue
Block a user