async-graphql/src/lib.rs

274 lines
10 KiB
Rust
Raw Normal View History

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
//!
//! * [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 ...)
//! * 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
//!
//! ## Crate features
2020-09-26 03:25:21 +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).
//! - `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).
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)
//!
//! ## 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]
//! ```
//!
//! ## Benchmarks
//!
2020-06-02 00:57:45 +00:00
//! Ensure that there is no CPU-heavy process in background!
//!
//! ```shell script
2020-06-02 00:57:45 +00:00
//! cd benchmark
//! cargo bench
//! ```
//!
//! 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
#![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)]
#![deny(clippy::redundant_closure_for_method_calls)]
#![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)]
#![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)]
#![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
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;
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
#[doc(hidden)]
2020-09-19 05:14:59 +00:00
pub mod registry;
#[doc(hidden)]
pub use async_stream;
#[doc(hidden)]
2020-09-14 01:46:22 +00:00
pub use async_trait;
#[doc(hidden)]
pub use context::ContextSelectionSet;
#[doc(hidden)]
2020-10-16 06:49:22 +00:00
pub use futures_util;
#[doc(hidden)]
pub use indexmap;
#[doc(hidden)]
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;
pub use async_graphql_value::{
2020-10-12 01:28:51 +00:00
from_value, to_value, value, ConstValue as Value, DeserializerError, Name, Number,
SerializerError, Variables,
};
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,
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,
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};
#[doc(no_inline)]
pub use resolver_utils::{ContainerType, EnumType, ScalarType};
2020-09-17 08:39:55 +00:00
pub use response::{BatchResponse, Response};
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
/// 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")]
pub use async_graphql_derive::Enum;
2021-11-20 03:16:48 +00:00
#[doc = include_str!("docs/input_object.md")]
pub use async_graphql_derive::InputObject;
2021-11-20 03:16:48 +00:00
#[doc = include_str!("docs/interface.md")]
pub use async_graphql_derive::Interface;
2021-11-20 03:16:48 +00:00
#[doc = include_str!("docs/merged_object.md")]
pub use async_graphql_derive::MergedObject;
2021-11-20 03:16:48 +00:00
#[doc = include_str!("docs/merged_subscription.md")]
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;