Make imports consistent

This commit is contained in:
Koxiaet 2020-10-15 07:38:10 +01:00
parent cc115ff1a7
commit 93c886af07
68 changed files with 279 additions and 190 deletions

View File

@ -10,7 +10,8 @@ use std::sync::Arc;
use fnv::FnvHashMap;
use serde::ser::{SerializeSeq, Serializer};
use serde::{Deserialize, Serialize};
use serde::de::{Deserialize, Deserializer};
use serde::Serialize;
use crate::extensions::Extensions;
use crate::parser::types::{
@ -24,7 +25,7 @@ use crate::{
use async_graphql_value::{Name, Value as InputValue};
/// Variables of a query.
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
#[derive(Debug, Clone, Default, Serialize)]
#[serde(transparent)]
pub struct Variables(pub BTreeMap<Name, Value>);
@ -38,6 +39,12 @@ impl Display for Variables {
}
}
impl<'de> Deserialize<'de> for Variables {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Self(<Option<BTreeMap<Name, Value>>>::deserialize(deserializer)?.unwrap_or_default()))
}
}
impl Variables {
/// Get the variables from a GraphQL value.
///
@ -127,7 +134,8 @@ pub type Context<'a> = ContextBase<'a, &'a Positioned<Field>>;
///
/// This is a borrowed form of [`PathSegment`](enum.PathSegment.html) used during execution instead
/// of passed back when errors occur.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize)]
#[serde(untagged)]
pub enum QueryPathSegment<'a> {
/// We are currently resolving an element in a list.
Index(usize),
@ -150,14 +158,7 @@ pub struct QueryPathNode<'a> {
impl<'a> serde::Serialize for QueryPathNode<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut seq = serializer.serialize_seq(None)?;
self.for_each(|segment| match segment {
QueryPathSegment::Index(idx) => {
seq.serialize_element(&idx).ok();
}
QueryPathSegment::Name(name) => {
seq.serialize_element(name).ok();
}
});
self.try_for_each(|segment| seq.serialize_element(segment))?;
seq.end()
}
}
@ -165,21 +166,21 @@ impl<'a> serde::Serialize for QueryPathNode<'a> {
impl<'a> Display for QueryPathNode<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut first = true;
self.for_each(|segment| {
self.try_for_each(|segment| {
if !first {
write!(f, ".").ok();
}
match segment {
QueryPathSegment::Index(idx) => {
write!(f, "{}", *idx).ok();
}
QueryPathSegment::Name(name) => {
write!(f, "{}", name).ok();
}
write!(f, ".")?;
}
first = false;
});
Ok(())
match segment {
QueryPathSegment::Index(idx) => {
write!(f, "{}", *idx)
}
QueryPathSegment::Name(name) => {
write!(f, "{}", name)
}
}
})
}
}
@ -204,7 +205,7 @@ impl<'a> QueryPathNode<'a> {
res.push(match s {
QueryPathSegment::Name(name) => name.to_string(),
QueryPathSegment::Index(idx) => idx.to_string(),
})
});
});
res
}
@ -215,14 +216,27 @@ impl<'a> QueryPathNode<'a> {
}
pub(crate) fn for_each<F: FnMut(&QueryPathSegment<'a>)>(&self, mut f: F) {
self.for_each_ref(&mut f);
let _ = self.try_for_each::<std::convert::Infallible, _>(|segment| {
f(segment);
Ok(())
});
}
fn for_each_ref<F: FnMut(&QueryPathSegment<'a>)>(&self, f: &mut F) {
pub(crate) fn try_for_each<E, F: FnMut(&QueryPathSegment<'a>) -> Result<(), E>>(
&self,
mut f: F,
) -> Result<(), E> {
self.try_for_each_ref(&mut f)
}
fn try_for_each_ref<E, F: FnMut(&QueryPathSegment<'a>) -> Result<(), E>>(
&self,
f: &mut F,
) -> Result<(), E> {
if let Some(parent) = &self.parent {
parent.for_each_ref(f);
parent.try_for_each_ref(f)?;
}
f(&self.segment);
f(&self.segment)
}
}
@ -252,7 +266,7 @@ impl<'a> Iterator for Parents<'a> {
impl<'a> std::iter::FusedIterator for Parents<'a> {}
/// The unique id of the current resolusion.
/// The unique id of the current resolution.
#[derive(Debug, Clone, Copy)]
pub struct ResolveId {
/// The unique ID of the parent resolution.

View File

@ -1,10 +1,12 @@
use crate::{parser, InputValueType, Pos, Value};
use serde::Serialize;
use std::collections::BTreeMap;
use std::fmt::{self, Debug, Display, Formatter};
use std::marker::PhantomData;
use serde::Serialize;
use thiserror::Error;
use crate::{parser, InputValueType, Pos, Value};
/// Extensions to the error.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default)]
#[serde(transparent)]
@ -34,10 +36,7 @@ pub struct ServerError {
}
fn error_extensions_is_empty(values: &Option<ErrorExtensionValues>) -> bool {
match values {
Some(values) => values.0.is_empty(),
None => true,
}
values.as_ref().map_or(false, |values| values.0.is_empty())
}
impl ServerError {
@ -94,6 +93,9 @@ impl From<parser::Error> for ServerError {
}
/// A segment of path to a resolver.
///
/// This is like [`QueryPathSegment`](enum.QueryPathSegment.html), but owned and used as a part of
/// errors instead of during execution.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(untagged)]
pub enum PathSegment {
@ -268,7 +270,7 @@ impl From<multer::Error> for ParseRequestError {
}
}
/// An error which can be extended into a `FieldError`.
/// An error which can be extended into a `Error`.
pub trait ErrorExtensions: Sized {
/// Convert the error to a `Error`.
fn extend(&self) -> Error;
@ -299,7 +301,7 @@ impl ErrorExtensions for Error {
impl<E: std::fmt::Display> ErrorExtensions for &E {
fn extend(&self) -> Error {
Error {
message: format!("{}", self),
message: self.to_string(),
extensions: None,
}
}

View File

@ -1,10 +1,12 @@
//! Apollo persisted queries extension.
use std::sync::Arc;
use futures::lock::Mutex;
use serde::Deserialize;
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory};
use crate::{from_value, Request, ServerError, ServerResult};
use futures::lock::Mutex;
use serde::Deserialize;
use std::sync::Arc;
#[derive(Deserialize)]
struct PersistedQuery {

View File

@ -1,11 +1,13 @@
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory, ResolveInfo};
use crate::{value, Value, Variables};
use chrono::{DateTime, Utc};
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use std::collections::BTreeMap;
use std::ops::Deref;
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer};
use chrono::{DateTime, Utc};
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory, ResolveInfo};
use crate::{value, Value, Variables};
struct PendingResolve {
path: Vec<String>,
field_name: String,
@ -29,7 +31,7 @@ impl Deref for ResolveStat {
}
impl Serialize for ResolveStat {
fn serialize<S: Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("path", &self.path)?;
map.serialize_entry("fieldName", &self.field_name)?;

View File

@ -1,8 +1,10 @@
use std::fmt::{self, Display, Formatter};
use log::{error, info, trace};
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory, ResolveInfo};
use crate::parser::types::{ExecutableDocument, OperationType, Selection};
use crate::{PathSegment, ServerError, Variables};
use log::{error, info, trace};
use std::fmt::{self, Display, Formatter};
/// Logger extension
#[cfg_attr(feature = "nightly", doc(cfg(feature = "log")))]

View File

@ -9,8 +9,13 @@ mod logger;
#[cfg(feature = "tracing")]
mod tracing;
use std::any::{Any, TypeId};
use std::collections::BTreeMap;
use crate::context::{QueryPathNode, ResolveId};
use crate::{Data, Request, Result, ServerError, ServerResult, Variables};
use crate::parser::types::ExecutableDocument;
use crate::{Error, Name, Value};
#[cfg(feature = "apollo_tracing")]
pub use self::apollo_tracing::ApolloTracing;
@ -18,10 +23,6 @@ pub use self::apollo_tracing::ApolloTracing;
pub use self::logger::Logger;
#[cfg(feature = "tracing")]
pub use self::tracing::Tracing;
use crate::parser::types::ExecutableDocument;
use crate::{Error, Name, Value};
use std::any::{Any, TypeId};
use std::collections::BTreeMap;
pub(crate) type BoxExtension = Box<dyn Extension>;

View File

@ -1,8 +1,10 @@
use std::collections::BTreeMap;
use tracing::{span, Level, Span};
use crate::extensions::{Extension, ExtensionContext, ExtensionFactory, ResolveInfo};
use crate::{ServerError, Variables};
use async_graphql_parser::types::ExecutableDocument;
use std::collections::BTreeMap;
use tracing::{span, Level, Span};
use crate::parser::types::ExecutableDocument;
/// Tracing extension
///

View File

@ -6,16 +6,17 @@ mod multipart;
mod playground_source;
mod websocket;
use futures::io::AsyncRead;
use futures::AsyncReadExt;
use crate::{BatchRequest, ParseRequestError, Request};
pub use graphiql_source::graphiql_source;
#[cfg(feature = "multipart")]
pub use multipart::MultipartOptions;
pub use playground_source::{playground_source, GraphQLPlaygroundConfig};
pub use websocket::WebSocket;
use crate::{BatchRequest, ParseRequestError, Request};
use futures::io::AsyncRead;
use futures::AsyncReadExt;
#[cfg(feature = "multipart")]
#[cfg_attr(feature = "nightly", doc(cfg(feature = "multipart")))]
/// Receive a GraphQL request from a content type and body.

View File

@ -1,13 +1,15 @@
use crate::{BatchRequest, ParseRequestError, UploadValue};
use std::collections::HashMap;
use std::io::{self, Seek, SeekFrom, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
use bytes::Bytes;
use futures::io::AsyncRead;
use futures::stream::Stream;
use multer::{Constraints, Multipart, SizeLimit};
use pin_project_lite::pin_project;
use std::collections::HashMap;
use std::io::{self, Seek, SeekFrom, Write};
use std::pin::Pin;
use std::task::{Context, Poll};
use crate::{BatchRequest, ParseRequestError, UploadValue};
/// Options for `receive_multipart`.
#[derive(Default, Clone, Copy)]

View File

@ -1,6 +1,7 @@
use serde::Serialize;
use std::collections::HashMap;
use serde::Serialize;
/// Generate the page for GraphQL Playground
///
/// # Example

View File

@ -1,14 +1,16 @@
//! WebSocket transport for subscription
use crate::{Data, Error, ObjectType, Request, Response, Result, Schema, SubscriptionType};
use futures::Stream;
use pin_project_lite::pin_project;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use futures::Stream;
use pin_project_lite::pin_project;
use serde::{Deserialize, Serialize};
use crate::{Data, Error, ObjectType, Request, Response, Result, Schema, SubscriptionType};
pin_project! {
/// A GraphQL connection over websocket.
///

View File

@ -1,6 +1,7 @@
use std::collections::HashMap;
use crate::parser::types::{Field, FragmentDefinition, Selection, SelectionSet};
use crate::{Name, Positioned};
use std::collections::HashMap;
/// A selection performed by a query.
pub struct Lookahead<'a> {

View File

@ -1,6 +1,5 @@
use crate::model::{__InputValue, __Type};
use crate::{registry, Object};
use itertools::Itertools;
pub struct __Field<'a> {
pub registry: &'a registry::Registry,
@ -26,7 +25,7 @@ impl<'a> __Field<'a> {
registry: self.registry,
input_value,
})
.collect_vec()
.collect()
}
#[graphql(name = "type")]

View File

@ -1,6 +1,5 @@
use crate::model::{__Directive, __Type};
use crate::{registry, Object};
use itertools::Itertools;
pub struct __Schema<'a> {
pub registry: &'a registry::Registry,
@ -11,12 +10,12 @@ pub struct __Schema<'a> {
impl<'a> __Schema<'a> {
/// A list of all types supported by this server.
async fn types(&self) -> Vec<__Type<'a>> {
let mut types = self
let mut types: Vec<_> = self
.registry
.types
.values()
.map(|ty| (ty.name(), __Type::new_simple(self.registry, ty)))
.collect_vec();
.collect();
types.sort_by(|a, b| a.0.cmp(b.0));
types.into_iter().map(|(_, ty)| ty).collect()
}
@ -49,7 +48,7 @@ impl<'a> __Schema<'a> {
/// A list of all directives supported by this server.
async fn directives(&self) -> Vec<__Directive<'a>> {
let mut directives = self
let mut directives: Vec<_> = self
.registry
.directives
.values()
@ -57,7 +56,7 @@ impl<'a> __Schema<'a> {
registry: &self.registry,
directive,
})
.collect_vec();
.collect();
directives.sort_by(|a, b| a.directive.name.cmp(b.directive.name));
directives
}

View File

@ -1,6 +1,5 @@
use crate::model::{__EnumValue, __Field, __InputValue, __TypeKind};
use crate::{registry, Object};
use itertools::Itertools;
enum TypeDetail<'a> {
Named(&'a registry::MetaType),
@ -106,7 +105,7 @@ impl<'a> __Type<'a> {
registry: self.registry,
field,
})
.collect_vec()
.collect()
})
} else {
None

View File

@ -1,7 +1,9 @@
use crate::registry::{MetaField, MetaInputValue, MetaType, Registry};
use itertools::Itertools;
use std::fmt::Write;
use itertools::Itertools;
use crate::registry::{MetaField, MetaInputValue, MetaType, Registry};
impl Registry {
pub fn export_sdl(&self, federation: bool) -> String {
let mut sdl = String::new();

View File

@ -1,13 +1,15 @@
mod cache_control;
mod export_sdl;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use indexmap::map::IndexMap;
use indexmap::set::IndexSet;
use crate::parser::types::{BaseType as ParsedBaseType, Type as ParsedType};
use crate::validators::InputValueValidator;
use crate::{model, Any, Type, Value};
use indexmap::map::IndexMap;
use indexmap::set::IndexSet;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
pub use cache_control::CacheControl;

View File

@ -1,9 +1,11 @@
use crate::{Data, ParseRequestError, UploadValue, Value, Variables};
use serde::{Deserialize, Deserializer};
use std::any::Any;
use std::collections::HashMap;
use std::fmt::{self, Debug, Formatter};
use serde::{Deserialize, Deserializer};
use crate::{Data, ParseRequestError, UploadValue, Value, Variables};
/// GraphQL request.
///
/// This can be deserialized from a structure of the query string, the operation name and the
@ -20,10 +22,10 @@ pub struct Request {
pub operation_name: Option<String>,
/// The variables of the request.
#[serde(default, deserialize_with = "deserialize_variables")]
#[serde(default)]
pub variables: Variables,
/// Uploads
/// Uploads sent with the request.
#[serde(skip)]
pub uploads: Vec<UploadValue>,
@ -38,12 +40,6 @@ pub struct Request {
pub extensions: HashMap<String, Value>,
}
fn deserialize_variables<'de, D: Deserializer<'de>>(
deserializer: D,
) -> std::result::Result<Variables, D::Error> {
Ok(Option::<Variables>::deserialize(deserializer)?.unwrap_or_default())
}
impl Request {
/// Create a request object with query source.
pub fn new(query: impl Into<String>) -> Self {
@ -104,6 +100,7 @@ impl Debug for Request {
.field("query", &self.query)
.field("operation_name", &self.operation_name)
.field("variables", &self.variables)
.field("extensions", &self.extensions)
.finish()
}
}
@ -137,16 +134,16 @@ impl BatchRequest {
}
}
fn deserialize_non_empty_vec<'de, D, T>(deserializer: D) -> std::result::Result<Vec<T>, D::Error>
fn deserialize_non_empty_vec<'de, D, T>(deserializer: D) -> Result<Vec<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
{
use serde::de::Error as _;
let v = Vec::<T>::deserialize(deserializer)?;
let v = <Vec<T>>::deserialize(deserializer)?;
if v.is_empty() {
Err(D::Error::invalid_length(0, &"a positive integer"))
Err(D::Error::invalid_length(0, &"a non-empty sequence"))
} else {
Ok(v)
}

View File

@ -1,3 +1,7 @@
use std::collections::BTreeMap;
use std::future::Future;
use std::pin::Pin;
use crate::extensions::{ErrorLogger, ExtensionContext, ResolveInfo};
use crate::parser::types::Selection;
use crate::registry::MetaType;
@ -5,9 +9,6 @@ use crate::{
Context, ContextSelectionSet, Name, OutputValueType, PathSegment, ServerError, ServerResult,
Value,
};
use std::collections::BTreeMap;
use std::future::Future;
use std::pin::Pin;
/// Represents a GraphQL container object.
///

View File

@ -1,6 +1,7 @@
use crate::{CacheControl, Result, ServerError, Value};
use serde::Serialize;
use crate::{CacheControl, Result, ServerError, Value};
/// Query response
#[derive(Debug, Default, Serialize)]
pub struct Response {

View File

@ -1,3 +1,13 @@
use std::any::Any;
use std::collections::BTreeMap;
use std::ops::Deref;
use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
use futures::stream::{self, Stream, StreamExt};
use indexmap::map::IndexMap;
use itertools::Itertools;
use crate::context::{Data, QueryEnvInner, ResolveId};
use crate::extensions::{ErrorLogger, ExtensionContext, ExtensionFactory, Extensions};
use crate::model::__DirectiveLocation;
@ -12,14 +22,6 @@ use crate::{
BatchRequest, BatchResponse, CacheControl, ContextBase, ObjectType, QueryEnv, Request,
Response, ServerError, SubscriptionType, Type, Value, ID,
};
use futures::stream::{self, Stream, StreamExt};
use indexmap::map::IndexMap;
use itertools::Itertools;
use std::any::Any;
use std::collections::BTreeMap;
use std::ops::Deref;
use std::sync::atomic::AtomicUsize;
use std::sync::Arc;
/// Schema builder
pub struct SchemaBuilder<Query, Mutation, Subscription> {

View File

@ -1,9 +1,11 @@
use std::pin::Pin;
use futures::{Stream, StreamExt};
use crate::parser::types::{Selection, TypeCondition};
use crate::{
Context, ContextSelectionSet, Name, PathSegment, ServerError, ServerResult, Type, Value,
};
use futures::{Stream, StreamExt};
use std::pin::Pin;
/// A GraphQL subscription object
pub trait SubscriptionType: Type {

View File

@ -1,3 +1,8 @@
use std::borrow::Cow;
use futures::{Stream, StreamExt, TryStreamExt};
use indexmap::map::IndexMap;
use crate::connection::edge::Edge;
use crate::connection::page_info::PageInfo;
use crate::parser::types::Field;
@ -7,9 +12,6 @@ use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, Result,
ServerResult, Type, Value,
};
use futures::{Stream, StreamExt, TryStreamExt};
use indexmap::map::IndexMap;
use std::borrow::Cow;
/// Connection type
///

View File

@ -1,8 +1,9 @@
use crate::ID;
use std::convert::Infallible;
use std::fmt::Display;
use std::num::ParseIntError;
use crate::ID;
/// Cursor type
///
/// A custom scalar that serializes as a string.

View File

@ -1,3 +1,7 @@
use std::borrow::Cow;
use indexmap::map::IndexMap;
use crate::connection::EmptyFields;
use crate::parser::types::Field;
use crate::resolver_utils::{resolve_container, ContainerType};
@ -6,8 +10,6 @@ use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerResult,
Type, Value,
};
use indexmap::map::IndexMap;
use std::borrow::Cow;
/// The edge type output by the data source
pub struct Edge<C, T, E> {

View File

@ -5,13 +5,14 @@ mod cursor;
mod edge;
mod page_info;
use std::fmt::Display;
use std::future::Future;
use crate::{Result, SimpleObject};
pub use connection_type::Connection;
pub use cursor::CursorType;
pub use edge::Edge;
use futures::Future;
pub use page_info::PageInfo;
use std::fmt::Display;
/// Empty additional fields
#[derive(SimpleObject)]

View File

@ -1,10 +1,11 @@
use std::borrow::Cow;
use crate::parser::types::Field;
use crate::resolver_utils::ContainerType;
use crate::{
registry, Context, ContextSelectionSet, ObjectType, OutputValueType, Positioned, ServerError,
ServerResult, Type, Value,
};
use std::borrow::Cow;
/// Empty mutation
///

View File

@ -1,8 +1,10 @@
use crate::{registry, Context, ServerError, ServerResult, SubscriptionType, Type, Value};
use futures::{stream, Stream};
use std::borrow::Cow;
use std::pin::Pin;
use futures::{stream, Stream};
use crate::{registry, Context, ServerError, ServerResult, SubscriptionType, Type, Value};
/// Empty subscription
///
/// Only the parameters used to construct the Schema, representing an unconfigured subscription.

View File

@ -1,10 +1,11 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use bson::oid::ObjectId;
#[cfg(feature = "chrono")]
use bson::DateTime as UtcDateTime;
#[cfg(feature = "chrono")]
use chrono::{DateTime, Utc};
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(internal)]
impl ScalarType for ObjectId {
fn parse(value: Value) -> InputValueResult<Self> {

View File

@ -1,13 +1,12 @@
use crate::{InputValueError, InputValueResult, Result, ScalarType, Value};
use async_graphql_derive::Scalar;
use chrono_tz::Tz;
use std::str::FromStr;
use crate::{InputValueError, InputValueResult, Result, ScalarType, Value, Scalar};
#[Scalar(internal, name = "TimeZone")]
impl ScalarType for Tz {
fn parse(value: Value) -> InputValueResult<Self> {
match value {
Value::String(s) => Ok(Tz::from_str(&s)?),
Value::String(s) => Ok(s.parse()?),
_ => Err(InputValueError::expected_type(value)),
}
}

View File

@ -1,6 +1,7 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use chrono::{DateTime, FixedOffset, Local, Utc};
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
/// Implement the DateTime<FixedOffset> scalar
///
/// The input/output is a string in RFC3339 format.

View File

@ -1,8 +1,9 @@
use std::collections::BTreeMap;
use crate::{
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType,
Value,
};
use std::collections::BTreeMap;
/// A scalar that can represent any JSON Object value.
#[Scalar(internal, name = "JSONObject")]

View File

@ -1,8 +1,9 @@
use std::collections::{BTreeMap, HashMap};
use crate::{
InputValueError, InputValueResult, InputValueType, Name, OutputValueType, Scalar, ScalarType,
Value,
};
use std::collections::{BTreeMap, HashMap};
/// A scalar that can represent any JSON Object value.
#[Scalar(internal, name = "JSONObject")]

View File

@ -1,11 +1,12 @@
use std::borrow::Cow;
use std::collections::BTreeSet;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, ServerResult, Type, Value,
};
use std::borrow::Cow;
use std::collections::BTreeSet;
impl<T: Type> Type for BTreeSet<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,13 +1,14 @@
use std::borrow::Cow;
use std::cmp::Eq;
use std::collections::HashSet;
use std::hash::Hash;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, Result, ServerResult, Type, Value,
};
use std::borrow::Cow;
use std::cmp::Eq;
use std::collections::HashSet;
use std::hash::Hash;
impl<T: Type> Type for HashSet<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,11 +1,12 @@
use std::borrow::Cow;
use std::collections::LinkedList;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, ServerResult, Type, Value,
};
use std::borrow::Cow;
use std::collections::LinkedList;
impl<T: Type> Type for LinkedList<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,9 +1,10 @@
use std::borrow::Cow;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, OutputValueType, Positioned, ServerResult, Type, Value,
};
use std::borrow::Cow;
impl<'a, T: Type + 'a> Type for &'a [T] {
fn type_name() -> Cow<'static, str> {

View File

@ -1,10 +1,11 @@
use std::borrow::Cow;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, Result, ServerResult, Type, Value,
};
use std::borrow::Cow;
impl<T: Type> Type for Vec<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,11 +1,12 @@
use std::borrow::Cow;
use std::collections::VecDeque;
use crate::parser::types::Field;
use crate::resolver_utils::resolve_list;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, ServerResult, Type, Value,
};
use std::borrow::Cow;
use std::collections::VecDeque;
impl<T: Type> Type for VecDeque<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,6 +1,7 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(internal)]
impl ScalarType for NaiveDate {
fn parse(value: Value) -> InputValueResult<Self> {

View File

@ -1,8 +1,9 @@
use crate::{InputValueError, InputValueResult, Number, Scalar, ScalarType, Value};
use std::num::{
NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8,
};
use crate::{InputValueError, InputValueResult, Number, Scalar, ScalarType, Value};
/// The `Int` scalar type represents non-fractional whole numeric values.
#[Scalar(internal, name = "Int")]
impl ScalarType for NonZeroI8 {

View File

@ -1,9 +1,10 @@
use std::borrow::Cow;
use crate::parser::types::Field;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, InputValueType,
OutputValueType, Positioned, ServerResult, Type, Value,
};
use std::borrow::Cow;
impl<T: Type> Type for Option<T> {
fn type_name() -> Cow<'static, str> {

View File

@ -1,9 +1,10 @@
use std::borrow::Cow;
use crate::parser::types::Field;
use crate::{
registry, ContextSelectionSet, InputValueError, InputValueResult, OutputValueType, Positioned,
Scalar, ScalarType, ServerResult, Type, Value,
};
use std::borrow::Cow;
/// The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.
#[Scalar(internal)]

View File

@ -1,6 +1,7 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use url::Url;
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(internal)]
impl ScalarType for Url {
fn parse(value: Value) -> InputValueResult<Self> {

View File

@ -1,6 +1,7 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use uuid::Uuid;
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[Scalar(internal, name = "UUID")]
impl ScalarType for Uuid {
fn parse(value: Value) -> InputValueResult<Self> {

View File

@ -1,11 +1,13 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
#[cfg(feature = "bson")]
use bson::oid::{self, ObjectId};
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::num::ParseIntError;
use std::ops::{Deref, DerefMut};
#[cfg(feature = "bson")]
use bson::oid::{self, ObjectId};
use serde::{Deserialize, Serialize};
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
/// ID scalar
///
/// The input is a `&str`, `String`, `usize` or `uuid::UUID`, and the output is a string.
@ -45,7 +47,7 @@ macro_rules! try_from_integers {
impl TryFrom<ID> for $ty {
type Error = ParseIntError;
fn try_from(id: ID) -> std::result::Result<Self, Self::Error> {
fn try_from(id: ID) -> Result<Self, Self::Error> {
id.0.parse()
}
}
@ -59,7 +61,7 @@ try_from_integers!(i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, isize, usiz
impl TryFrom<ID> for uuid::Uuid {
type Error = uuid::Error;
fn try_from(id: ID) -> std::result::Result<Self, Self::Error> {
fn try_from(id: ID) -> Result<Self, Self::Error> {
uuid::Uuid::parse_str(&id.0)
}
}

View File

@ -1,13 +1,15 @@
use std::borrow::Cow;
use std::ops::{Deref, DerefMut};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use crate::parser::types::Field;
use crate::registry::{MetaType, Registry};
use crate::{
from_value, to_value, ContextSelectionSet, InputValueResult, OutputValueType, Positioned,
Scalar, ScalarType, ServerResult, Type, Value,
};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::ops::{Deref, DerefMut};
/// A scalar that can represent any JSON value.
///

View File

@ -1,7 +1,9 @@
use crate::{registry, InputValueError, InputValueResult, InputValueType, Type, Value};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::{registry, InputValueError, InputValueResult, InputValueType, Type, Value};
/// Similar to `Option`, but it has three states, `undefined`, `null` and `x`.
///
/// **Reference:** <https://spec.graphql.org/June2018/#sec-Null-Value>
@ -132,7 +134,7 @@ impl<T: InputValueType> InputValueType for MaybeUndefined<T> {
}
impl<T: Serialize> Serialize for MaybeUndefined<T> {
fn serialize<S: Serializer>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
MaybeUndefined::Value(value) => value.serialize(serializer),
_ => serializer.serialize_none(),

View File

@ -1,3 +1,7 @@
use std::borrow::Cow;
use indexmap::IndexMap;
use crate::parser::types::Field;
use crate::registry::{MetaType, Registry};
use crate::resolver_utils::resolve_container;
@ -5,8 +9,6 @@ use crate::{
CacheControl, ContainerType, Context, ContextSelectionSet, ObjectType, OutputValueType,
Positioned, ServerResult, SimpleObject, Type, Value,
};
use indexmap::IndexMap;
use std::borrow::Cow;
#[doc(hidden)]
pub struct MergedObject<A, B>(pub A, pub B);

View File

@ -1,3 +1,7 @@
use std::borrow::Cow;
use indexmap::map::IndexMap;
use crate::model::{__Schema, __Type};
use crate::parser::types::Field;
use crate::resolver_utils::{resolve_container, ContainerType};
@ -6,9 +10,6 @@ use crate::{
ServerError, ServerResult, SimpleObject, Type, Value,
};
use indexmap::map::IndexMap;
use std::borrow::Cow;
/// Federation service
#[derive(SimpleObject)]
#[graphql(internal, name = "_Service")]

View File

@ -1,8 +1,10 @@
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
use num_traits::Num;
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use serde::{Deserialize, Serialize};
use num_traits::Num;
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
/// A numeric value represented by a string.
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
#[serde(transparent)]

View File

@ -1,9 +1,11 @@
use crate::{registry, Context, InputValueError, InputValueResult, InputValueType, Type, Value};
use futures::AsyncRead;
use std::borrow::Cow;
use std::fs::File;
use std::io::Read;
use futures::AsyncRead;
use crate::{registry, Context, InputValueError, InputValueResult, InputValueType, Type, Value};
/// A file upload value.
pub struct UploadValue {
/// The name of the file.

View File

@ -1,3 +1,5 @@
use indexmap::map::IndexMap;
use crate::context::QueryPathNode;
use crate::parser::types::{Directive, Field};
use crate::registry::MetaInputValue;
@ -5,7 +7,6 @@ use crate::validation::utils::is_valid_input_value;
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Positioned, QueryPathSegment};
use async_graphql_value::Value;
use indexmap::map::IndexMap;
#[derive(Default)]
pub struct ArgumentsOfCorrectType<'a> {

View File

@ -1,10 +1,11 @@
use indexmap::map::IndexMap;
use crate::parser::types::{Directive, Field};
use crate::registry::MetaInputValue;
use crate::validation::suggestion::make_suggestion;
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Positioned};
use async_graphql_value::Value;
use indexmap::map::IndexMap;
enum ArgsType<'a> {
Directive(&'a str),

View File

@ -1,7 +1,8 @@
use std::collections::{HashMap, HashSet};
use crate::parser::types::{ExecutableDocument, FragmentDefinition, FragmentSpread};
use crate::validation::visitor::{RuleError, Visitor, VisitorContext};
use crate::{Name, Pos, Positioned};
use std::collections::{HashMap, HashSet};
struct CycleDetector<'a> {
visited: HashSet<&'a str>,

View File

@ -1,3 +1,5 @@
use std::collections::{HashMap, HashSet};
use crate::parser::types::{
ExecutableDocument, FragmentDefinition, FragmentSpread, OperationDefinition, VariableDefinition,
};
@ -5,7 +7,6 @@ use crate::validation::utils::{referenced_variables, Scope};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Pos, Positioned};
use async_graphql_value::Value;
use std::collections::{HashMap, HashSet};
#[derive(Default)]
pub struct NoUndefinedVariables<'a> {

View File

@ -1,10 +1,11 @@
use std::collections::{HashMap, HashSet};
use crate::parser::types::{
ExecutableDocument, FragmentDefinition, FragmentSpread, OperationDefinition,
};
use crate::validation::utils::Scope;
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Pos, Positioned};
use std::collections::{HashMap, HashSet};
#[derive(Default)]
pub struct NoUnusedFragments<'a> {

View File

@ -1,3 +1,5 @@
use std::collections::{HashMap, HashSet};
use crate::parser::types::{
ExecutableDocument, FragmentDefinition, FragmentSpread, OperationDefinition, VariableDefinition,
};
@ -5,7 +7,6 @@ use crate::validation::utils::{referenced_variables, Scope};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Pos, Positioned};
use async_graphql_value::Value;
use std::collections::{HashMap, HashSet};
#[derive(Default)]
pub struct NoUnusedVariables<'a> {

View File

@ -1,7 +1,8 @@
use std::collections::HashMap;
use crate::parser::types::{Field, Selection, SelectionSet};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::Positioned;
use std::collections::HashMap;
#[derive(Default)]
pub struct OverlappingFieldsCanBeMerged;

View File

@ -1,7 +1,8 @@
use std::collections::HashMap;
use crate::parser::types::{ExecutableDocument, FragmentSpread, InlineFragment, TypeCondition};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::Positioned;
use std::collections::HashMap;
#[derive(Default)]
pub struct PossibleFragmentSpreads<'a> {

View File

@ -1,8 +1,9 @@
use std::collections::HashSet;
use crate::parser::types::{Directive, Field};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Positioned};
use async_graphql_value::Value;
use std::collections::HashSet;
#[derive(Default)]
pub struct UniqueArgumentNames<'a> {

View File

@ -1,7 +1,8 @@
use std::collections::HashSet;
use crate::parser::types::{OperationDefinition, VariableDefinition};
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Positioned};
use std::collections::HashSet;
#[derive(Default)]
pub struct UniqueVariableNames<'a> {

View File

@ -1,3 +1,5 @@
use std::collections::{HashMap, HashSet};
use crate::parser::types::{
ExecutableDocument, FragmentDefinition, FragmentSpread, OperationDefinition, VariableDefinition,
};
@ -6,7 +8,6 @@ use crate::validation::utils::Scope;
use crate::validation::visitor::{Visitor, VisitorContext};
use crate::{Name, Pos, Positioned};
use async_graphql_value::Value;
use std::collections::{HashMap, HashSet};
#[derive(Default)]
pub struct VariableInAllowedPosition<'a> {

View File

@ -1,6 +1,7 @@
use itertools::Itertools;
use std::collections::HashMap;
use itertools::Itertools;
fn levenshtein_distance(s1: &str, s2: &str) -> usize {
let mut column = (0..=s1.len()).collect_vec();
for (x, rx) in s2.bytes().enumerate() {

View File

@ -2,10 +2,11 @@
#![allow(dead_code)]
#![allow(unreachable_code)]
use once_cell::sync::Lazy;
use crate::parser::types::ExecutableDocument;
use crate::validation::visitor::{visit, RuleError, Visitor, VisitorContext};
use crate::*;
use once_cell::sync::Lazy;
#[derive(InputObject)]
#[graphql(internal)]

View File

@ -1,7 +1,8 @@
use std::collections::HashSet;
use crate::context::QueryPathNode;
use crate::{registry, QueryPathSegment};
use async_graphql_value::{ConstValue, Value};
use std::collections::HashSet;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Scope<'a> {

View File

@ -1,3 +1,6 @@
use std::collections::HashMap;
use std::fmt::{self, Display, Formatter};
use crate::parser::types::{
Directive, ExecutableDocument, Field, FragmentDefinition, FragmentSpread, InlineFragment,
OperationDefinition, OperationType, Selection, SelectionSet, TypeCondition, VariableDefinition,
@ -5,8 +8,6 @@ use crate::parser::types::{
use crate::registry::{self, MetaType, MetaTypeName};
use crate::{Name, Pos, Positioned, ServerError, Variables};
use async_graphql_value::Value;
use std::collections::HashMap;
use std::fmt::{self, Display, Formatter};
pub(crate) struct VisitorContext<'a> {
pub(crate) registry: &'a registry::Registry,

View File

@ -1,8 +1,9 @@
use crate::validators::InputValueValidator;
use crate::Value;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::validators::InputValueValidator;
use crate::Value;
/// String minimum length validator
pub struct StringMinLength {
/// Must be greater than or equal to this value.