2020-05-25 21:37:46 +00:00
|
|
|
//! # A GraphQL server library implemented in Rust
|
2020-03-01 13:56:14 +00:00
|
|
|
//!
|
|
|
|
//! <div align="center">
|
|
|
|
//! <!-- CI -->
|
2020-04-28 07:41:31 +00:00
|
|
|
//! <img src="https://github.com/async-graphql/async-graphql/workflows/CI/badge.svg" />
|
2020-04-05 08:22:13 +00:00
|
|
|
//! <!-- codecov -->
|
2020-09-20 05:34:49 +00:00
|
|
|
//! <img src="https://codecov.io/gh/async-graphql/async-graphql/branch/master/graph/badge.svg" />
|
2020-03-01 13:56:14 +00:00
|
|
|
//! <!-- Crates version -->
|
|
|
|
//! <a href="https://crates.io/crates/async-graphql">
|
|
|
|
//! <img src="https://img.shields.io/crates/v/async-graphql.svg?style=flat-square"
|
|
|
|
//! alt="Crates.io version" />
|
|
|
|
//! </a>
|
|
|
|
//! <!-- Downloads -->
|
|
|
|
//! <a href="https://crates.io/crates/async-graphql">
|
|
|
|
//! <img src="https://img.shields.io/crates/d/async-graphql.svg?style=flat-square"
|
|
|
|
//! alt="Download" />
|
|
|
|
//! </a>
|
|
|
|
//! <!-- docs.rs docs -->
|
|
|
|
//! <a href="https://docs.rs/async-graphql">
|
|
|
|
//! <img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
|
|
|
|
//! alt="docs.rs docs" />
|
|
|
|
//! </a>
|
2020-11-07 13:26:10 +00:00
|
|
|
//! <a href="https://github.com/rust-secure-code/safety-dance/">
|
|
|
|
//! <img src="https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square"
|
|
|
|
//! alt="Unsafe Rust forbidden" />
|
|
|
|
//! </a>
|
2020-03-01 13:56:14 +00:00
|
|
|
//! </div>
|
|
|
|
//!
|
|
|
|
//! ## Documentation
|
|
|
|
//!
|
2021-01-06 14:06:01 +00:00
|
|
|
//! * [Feature Comparison](https://github.com/async-graphql/async-graphql/blob/master/feature-comparison.md)
|
2020-05-10 01:41:13 +00:00
|
|
|
//! * [Book](https://async-graphql.github.io/async-graphql/en/index.html)
|
|
|
|
//! * [中文文档](https://async-graphql.github.io/async-graphql/zh-CN/index.html)
|
|
|
|
//! * [Docs](https://docs.rs/async-graphql)
|
2020-04-28 07:41:31 +00:00
|
|
|
//! * [GitHub repository](https://github.com/async-graphql/async-graphql)
|
2020-03-01 13:56:14 +00:00
|
|
|
//! * [Cargo package](https://crates.io/crates/async-graphql)
|
2021-11-03 10:42:41 +00:00
|
|
|
//! * Minimum supported Rust version: 1.56.1 or later
|
2020-03-01 13:56:14 +00:00
|
|
|
//!
|
2020-03-04 06:27:00 +00:00
|
|
|
//! ## Features
|
|
|
|
//!
|
2020-07-07 08:41:29 +00:00
|
|
|
//! * Fully supports async/await
|
2020-03-17 11:11:14 +00:00
|
|
|
//! * Type safety
|
|
|
|
//! * Rustfmt friendly (Procedural Macro)
|
2020-07-07 08:41:29 +00:00
|
|
|
//! * Custom scalars
|
2020-03-17 11:11:14 +00:00
|
|
|
//! * Minimal overhead
|
2021-08-23 15:16:31 +00:00
|
|
|
//! * Easy integration ([poem](https://crates.io/crates/poem), actix_web, tide, warp, rocket ...)
|
2020-08-31 18:18:02 +00:00
|
|
|
//! * File upload (Multipart request)
|
2020-07-07 08:41:29 +00:00
|
|
|
//! * Subscriptions (WebSocket transport)
|
|
|
|
//! * Custom extensions
|
2020-03-26 03:34:28 +00:00
|
|
|
//! * Apollo Tracing extension
|
|
|
|
//! * Limit query complexity/depth
|
2020-03-31 03:19:18 +00:00
|
|
|
//! * Error Extensions
|
2020-04-10 02:26:08 +00:00
|
|
|
//! * Apollo Federation
|
2020-09-17 08:39:55 +00:00
|
|
|
//! * Batch Queries
|
2020-09-30 03:44:18 +00:00
|
|
|
//! * Apollo Persisted Queries
|
2020-03-04 06:27:00 +00:00
|
|
|
//!
|
2021-03-22 02:39:17 +00:00
|
|
|
//! ## Crate features
|
2020-09-26 03:25:21 +00:00
|
|
|
//!
|
2021-03-22 02:39:17 +00:00
|
|
|
//! This crate offers the following features, all of which are not activated by default:
|
2020-12-15 07:12:05 +00:00
|
|
|
//!
|
2020-09-26 03:25:21 +00:00
|
|
|
//! - `apollo_tracing`: Enable the [Apollo tracing extension](extensions/struct.ApolloTracing.html).
|
2020-09-30 03:44:18 +00:00
|
|
|
//! - `apollo_persisted_queries`: Enable the [Apollo persisted queries extension](extensions/apollo_persisted_queries/struct.ApolloPersistedQueries.html).
|
2020-09-26 03:25:21 +00:00
|
|
|
//! - `log`: Enable the [logger extension](extensions/struct.Logger.html).
|
|
|
|
//! - `tracing`: Enable the [tracing extension](extensions/struct.Tracing.html).
|
2021-03-22 02:39:17 +00:00
|
|
|
//! - `opentelemetry`: Enable the [OpenTelemetry extension](extensions/struct.OpenTelemetry.html).
|
2020-09-26 03:25:21 +00:00
|
|
|
//! - `unblock`: Support [asynchronous reader for Upload](types/struct.Upload.html)
|
|
|
|
//! - `bson`: Integrate with the [`bson` crate](https://crates.io/crates/bson).
|
|
|
|
//! - `chrono`: Integrate with the [`chrono` crate](https://crates.io/crates/chrono).
|
|
|
|
//! - `chrono-tz`: Integrate with the [`chrono-tz` crate](https://crates.io/crates/chrono-tz).
|
|
|
|
//! - `url`: Integrate with the [`url` crate](https://crates.io/crates/url).
|
|
|
|
//! - `uuid`: Integrate with the [`uuid` crate](https://crates.io/crates/uuid).
|
2020-12-15 07:12:05 +00:00
|
|
|
//! - `string_number`: Enable the [StringNumber](types/struct.StringNumber.html).
|
2020-12-21 06:21:10 +00:00
|
|
|
//! - `dataloader`: Support [DataLoader](dataloader/struct.DataLoader.html).
|
2021-07-01 20:52:37 +00:00
|
|
|
//! - `decimal`: Integrate with the [`rust_decimal` crate](https://crates.io/crates/rust_decimal).
|
2021-09-02 11:39:45 +00:00
|
|
|
//! - `cbor`: Support for [serde_cbor](https://crates.io/crates/serde_cbor).
|
2021-11-30 01:46:18 +00:00
|
|
|
//! - `smol_str`: Integrate with the [`smol_str` crate](https://crates.io/crates/smol_str).
|
2020-09-26 03:25:21 +00:00
|
|
|
//!
|
2020-03-18 03:15:02 +00:00
|
|
|
//! ## Integrations
|
|
|
|
//!
|
2021-11-19 00:10:47 +00:00
|
|
|
//! * Poem [async-graphql-poem](https://crates.io/crates/async-graphql-poem)
|
|
|
|
//! * Actix-web [async-graphql-actix-web](https://crates.io/crates/async-graphql-actix-web)
|
2020-04-14 03:44:49 +00:00
|
|
|
//! * Warp [async-graphql-warp](https://crates.io/crates/async-graphql-warp)
|
2020-05-02 02:46:02 +00:00
|
|
|
//! * Tide [async-graphql-tide](https://crates.io/crates/async-graphql-tide)
|
2021-11-19 00:10:47 +00:00
|
|
|
//! * Rocket [async-graphql-rocket](https://github.com/async-graphql/async-graphql/tree/master/integrations/rocket)
|
|
|
|
//! * Axum [async-graphql-axum](https://github.com/async-graphql/async-graphql/tree/master/integrations/axum)
|
2020-03-18 03:15:02 +00:00
|
|
|
//!
|
2020-03-04 06:27:00 +00:00
|
|
|
//! ## License
|
|
|
|
//!
|
|
|
|
//! Licensed under either of
|
|
|
|
//!
|
|
|
|
//! * Apache License, Version 2.0,
|
2020-09-15 18:32:13 +00:00
|
|
|
//! (./LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
|
|
//! * MIT license (./LICENSE-MIT or <http://opensource.org/licenses/MIT>)
|
2020-03-04 06:27:00 +00:00
|
|
|
//! at your option.
|
|
|
|
//!
|
2020-03-01 13:56:14 +00:00
|
|
|
//! ## References
|
|
|
|
//!
|
|
|
|
//! * [GraphQL](https://graphql.org)
|
2020-03-20 03:56:08 +00:00
|
|
|
//! * [GraphQL Multipart Request](https://github.com/jaydenseric/graphql-multipart-request-spec)
|
|
|
|
//! * [GraphQL Cursor Connections Specification](https://facebook.github.io/relay/graphql/connections.htm)
|
|
|
|
//! * [GraphQL over WebSocket Protocol](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md)
|
2020-03-26 07:27:35 +00:00
|
|
|
//! * [Apollo Tracing](https://github.com/apollographql/apollo-tracing)
|
2020-04-10 02:28:27 +00:00
|
|
|
//! * [Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction)
|
2020-05-20 11:39:00 +00:00
|
|
|
//!
|
|
|
|
//! ## Examples
|
|
|
|
//!
|
2020-10-16 01:21:16 +00:00
|
|
|
//! All examples are in the [sub-repository](https://github.com/async-graphql/examples), located in the examples directory.
|
|
|
|
//!
|
|
|
|
//! **Run an example:**
|
|
|
|
//!
|
|
|
|
//! ```shell
|
|
|
|
//! git submodule update # update the examples repo
|
|
|
|
//! cd examples && cargo run --bin [name]
|
|
|
|
//! ```
|
2020-05-20 11:39:00 +00:00
|
|
|
//!
|
|
|
|
//! ## Benchmarks
|
|
|
|
//!
|
2020-06-02 00:57:45 +00:00
|
|
|
//! Ensure that there is no CPU-heavy process in background!
|
|
|
|
//!
|
2020-05-20 11:39:00 +00:00
|
|
|
//! ```shell script
|
2020-06-02 00:57:45 +00:00
|
|
|
//! cd benchmark
|
|
|
|
//! cargo bench
|
2020-05-20 11:39:00 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
2020-08-31 18:18:02 +00:00
|
|
|
//! Now a HTML report is available at `benchmark/target/criterion/report`.
|
2020-06-02 00:57:45 +00:00
|
|
|
//!
|
2020-03-20 03:56:08 +00:00
|
|
|
|
2020-10-22 06:38:35 +00:00
|
|
|
#![deny(clippy::all)]
|
|
|
|
// #![deny(clippy::pedantic)]
|
|
|
|
#![deny(clippy::inefficient_to_string)]
|
|
|
|
#![deny(clippy::match_wildcard_for_single_variants)]
|
|
|
|
#![allow(clippy::module_name_repetitions)]
|
|
|
|
#![allow(clippy::similar_names)]
|
|
|
|
#![allow(clippy::if_not_else)]
|
|
|
|
#![allow(clippy::doc_markdown)]
|
|
|
|
#![allow(clippy::must_use_candidate)]
|
|
|
|
#![allow(clippy::missing_errors_doc)]
|
|
|
|
#![allow(clippy::needless_pass_by_value)]
|
2020-10-23 08:10:00 +00:00
|
|
|
#![deny(clippy::redundant_closure_for_method_calls)]
|
2020-10-22 06:38:35 +00:00
|
|
|
#![allow(clippy::option_if_let_else)]
|
|
|
|
#![allow(clippy::match_same_arms)]
|
|
|
|
#![allow(clippy::default_trait_access)]
|
|
|
|
#![allow(clippy::map_flatten)]
|
|
|
|
#![allow(clippy::map_unwrap_or)]
|
|
|
|
#![allow(clippy::explicit_iter_loop)]
|
|
|
|
#![allow(clippy::too_many_lines)]
|
|
|
|
#![allow(clippy::cast_sign_loss)]
|
|
|
|
#![allow(clippy::unused_self)]
|
|
|
|
#![allow(clippy::cast_lossless)]
|
|
|
|
#![allow(clippy::cast_possible_truncation)]
|
|
|
|
#![allow(clippy::implicit_hasher)]
|
|
|
|
// #![deny(clippy::nursery)]
|
|
|
|
#![allow(clippy::use_self)]
|
|
|
|
#![allow(clippy::missing_const_for_fn)]
|
|
|
|
#![allow(clippy::needless_borrow)]
|
|
|
|
#![allow(clippy::future_not_send)]
|
|
|
|
#![allow(clippy::redundant_pub_crate)]
|
|
|
|
#![allow(clippy::cognitive_complexity)]
|
|
|
|
#![allow(clippy::useless_let_if_seq)]
|
2020-03-20 03:56:08 +00:00
|
|
|
#![warn(missing_docs)]
|
2020-05-31 03:54:07 +00:00
|
|
|
#![allow(clippy::trivially_copy_pass_by_ref)]
|
2021-03-26 13:07:45 +00:00
|
|
|
#![allow(clippy::upper_case_acronyms)]
|
2020-05-20 00:18:28 +00:00
|
|
|
#![recursion_limit = "256"]
|
2020-05-29 09:29:15 +00:00
|
|
|
#![forbid(unsafe_code)]
|
2021-03-22 02:39:17 +00:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
2020-03-01 13:56:14 +00:00
|
|
|
|
2020-03-03 03:48:00 +00:00
|
|
|
mod base;
|
2021-11-19 10:49:37 +00:00
|
|
|
mod custom_directive;
|
2020-03-01 10:54:34 +00:00
|
|
|
mod error;
|
2021-11-16 06:51:20 +00:00
|
|
|
mod guard;
|
2020-05-14 14:13:28 +00:00
|
|
|
mod look_ahead;
|
2020-03-03 11:15:18 +00:00
|
|
|
mod model;
|
2020-09-10 08:39:43 +00:00
|
|
|
mod request;
|
|
|
|
mod response;
|
2020-03-03 11:15:18 +00:00
|
|
|
mod schema;
|
2020-03-17 09:26:59 +00:00
|
|
|
mod subscription;
|
2020-03-08 12:35:36 +00:00
|
|
|
mod validation;
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-10-15 05:55:30 +00:00
|
|
|
pub mod context;
|
2020-12-20 13:15:56 +00:00
|
|
|
#[cfg(feature = "dataloader")]
|
2021-03-22 05:27:24 +00:00
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "dataloader")))]
|
2020-12-20 13:15:56 +00:00
|
|
|
pub mod dataloader;
|
2020-10-15 05:56:17 +00:00
|
|
|
pub mod extensions;
|
2020-09-19 05:14:59 +00:00
|
|
|
pub mod http;
|
2020-09-23 18:50:35 +00:00
|
|
|
pub mod resolver_utils;
|
2020-09-13 09:38:19 +00:00
|
|
|
pub mod types;
|
2021-11-14 13:09:14 +00:00
|
|
|
#[doc(hidden)]
|
2020-09-14 01:46:22 +00:00
|
|
|
pub mod validators;
|
2020-03-21 01:32:13 +00:00
|
|
|
|
2020-09-12 13:47:11 +00:00
|
|
|
#[doc(hidden)]
|
2020-09-19 05:14:59 +00:00
|
|
|
pub mod registry;
|
2020-09-27 07:32:55 +00:00
|
|
|
|
2020-05-12 08:27:06 +00:00
|
|
|
#[doc(hidden)]
|
2020-09-13 17:52:36 +00:00
|
|
|
pub use async_stream;
|
|
|
|
#[doc(hidden)]
|
2020-09-14 01:46:22 +00:00
|
|
|
pub use async_trait;
|
|
|
|
#[doc(hidden)]
|
2020-09-19 17:10:46 +00:00
|
|
|
pub use context::ContextSelectionSet;
|
|
|
|
#[doc(hidden)]
|
2020-10-16 06:49:22 +00:00
|
|
|
pub use futures_util;
|
2020-04-06 05:49:39 +00:00
|
|
|
#[doc(hidden)]
|
2020-05-16 02:05:48 +00:00
|
|
|
pub use indexmap;
|
|
|
|
#[doc(hidden)]
|
2020-09-27 07:32:55 +00:00
|
|
|
pub use static_assertions;
|
|
|
|
#[doc(hidden)]
|
2020-09-19 05:14:59 +00:00
|
|
|
pub use subscription::SubscriptionType;
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-09-19 05:14:59 +00:00
|
|
|
pub use async_graphql_parser as parser;
|
2020-10-11 12:24:31 +00:00
|
|
|
pub use async_graphql_value::{
|
2020-10-12 01:28:51 +00:00
|
|
|
from_value, to_value, value, ConstValue as Value, DeserializerError, Name, Number,
|
2021-02-27 13:52:43 +00:00
|
|
|
SerializerError, Variables,
|
2020-10-11 12:24:31 +00:00
|
|
|
};
|
2020-09-29 23:45:48 +00:00
|
|
|
pub use base::{
|
2021-03-17 12:51:30 +00:00
|
|
|
ComplexObject, Description, InputObjectType, InputType, InterfaceType, ObjectType, OutputType,
|
2021-11-09 10:52:10 +00:00
|
|
|
UnionType,
|
2020-09-29 23:45:48 +00:00
|
|
|
};
|
2021-11-19 10:49:37 +00:00
|
|
|
pub use custom_directive::{CustomDirective, CustomDirectiveFactory};
|
2020-04-14 01:53:17 +00:00
|
|
|
pub use error::{
|
2021-11-07 11:11:17 +00:00
|
|
|
Error, ErrorExtensionValues, ErrorExtensions, InputValueError, InputValueResult,
|
2021-11-16 03:05:50 +00:00
|
|
|
ParseRequestError, PathSegment, Result, ResultExt, ServerError, ServerResult,
|
2020-04-14 01:53:17 +00:00
|
|
|
};
|
2021-11-19 10:49:37 +00:00
|
|
|
pub use extensions::ResolveFut;
|
2021-11-16 06:51:20 +00:00
|
|
|
pub use guard::{Guard, GuardExt};
|
2020-05-14 14:13:28 +00:00
|
|
|
pub use look_ahead::Lookahead;
|
2020-03-22 08:45:59 +00:00
|
|
|
pub use registry::CacheControl;
|
2020-09-17 08:39:55 +00:00
|
|
|
pub use request::{BatchRequest, Request};
|
2020-10-15 05:55:30 +00:00
|
|
|
#[doc(no_inline)]
|
2020-10-01 02:05:16 +00:00
|
|
|
pub use resolver_utils::{ContainerType, EnumType, ScalarType};
|
2020-09-17 08:39:55 +00:00
|
|
|
pub use response::{BatchResponse, Response};
|
2020-05-19 08:24:15 +00:00
|
|
|
pub use schema::{Schema, SchemaBuilder, SchemaEnv};
|
2020-12-18 15:58:03 +00:00
|
|
|
pub use validation::{ValidationMode, ValidationResult, VisitorContext};
|
2021-11-15 03:08:56 +00:00
|
|
|
pub use validators::CustomValidator;
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2020-10-15 05:56:17 +00:00
|
|
|
pub use context::*;
|
2020-09-19 05:14:59 +00:00
|
|
|
#[doc(no_inline)]
|
|
|
|
pub use parser::{Pos, Positioned};
|
2020-09-23 19:23:15 +00:00
|
|
|
pub use types::*;
|
2020-09-19 05:14:59 +00:00
|
|
|
|
2020-10-15 05:55:30 +00:00
|
|
|
/// An alias of [async_graphql::Error](struct.Error.html). Present for backward compatibility
|
|
|
|
/// reasons.
|
|
|
|
pub type FieldError = Error;
|
|
|
|
|
|
|
|
/// An alias of [async_graphql::Result](type.Result.html). Present for backward compatibility
|
|
|
|
/// reasons.
|
|
|
|
pub type FieldResult<T> = Result<T>;
|
|
|
|
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/complex_object.md")]
|
2021-03-17 12:51:30 +00:00
|
|
|
pub use async_graphql_derive::ComplexObject;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/description.md")]
|
|
|
|
pub use async_graphql_derive::Description;
|
|
|
|
#[doc = include_str!("docs/directive.md")]
|
|
|
|
pub use async_graphql_derive::Directive;
|
|
|
|
#[doc = include_str!("docs/enum.md")]
|
2020-09-18 00:52:13 +00:00
|
|
|
pub use async_graphql_derive::Enum;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/input_object.md")]
|
2020-09-18 00:52:13 +00:00
|
|
|
pub use async_graphql_derive::InputObject;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/interface.md")]
|
2020-09-18 00:52:13 +00:00
|
|
|
pub use async_graphql_derive::Interface;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/merged_object.md")]
|
2020-09-18 00:52:13 +00:00
|
|
|
pub use async_graphql_derive::MergedObject;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/merged_subscription.md")]
|
2020-09-18 00:52:13 +00:00
|
|
|
pub use async_graphql_derive::MergedSubscription;
|
2021-11-20 03:16:48 +00:00
|
|
|
#[doc = include_str!("docs/newtype.md")]
|
|
|
|
pub use async_graphql_derive::NewType;
|
|
|
|
#[doc = include_str!("docs/object.md")]
|
|
|
|
pub use async_graphql_derive::Object;
|
|
|
|
#[doc = include_str!("docs/scalar.md")]
|
|
|
|
pub use async_graphql_derive::Scalar;
|
|
|
|
#[doc = include_str!("docs/simple_object.md")]
|
|
|
|
pub use async_graphql_derive::SimpleObject;
|
|
|
|
#[doc = include_str!("docs/subscription.md")]
|
|
|
|
pub use async_graphql_derive::Subscription;
|
|
|
|
#[doc = include_str!("docs/union.md")]
|
|
|
|
pub use async_graphql_derive::Union;
|