Crate async_graphql
source ·Expand description
§A GraphQL server library implemented in Rust
§Documentation
- Book
- 中文文档
- Docs
- GitHub repository
- Cargo package
- Minimum supported Rust version: 1.56.1 or later
§Features
- Fully supports async/await
- Type safety
- Rustfmt friendly (Procedural Macro)
- Custom scalars
- Minimal overhead
- Easy integration (poem, actix_web, tide, warp, rocket …)
- File upload (Multipart request)
- Subscriptions (WebSocket transport)
- Custom extensions
- Apollo Tracing extension
- Limit query complexity/depth
- Error Extensions
- Apollo Federation(v2)
- Batch Queries
- Apollo Persisted Queries
§Crate features
This crate offers the following features, all of which are not activated by default:
- apollo_tracing: Enable the Apollo tracing extension.
- apollo_persisted_queries: Enable the [Apollo persisted queries extension](extensions/apollo_persisted_queries/struct. ApolloPersistedQueries.html).
- log: Enable the logger extension.
- tracing: Enable the tracing extension.
- opentelemetry: Enable the OpenTelemetry extension.
- unblock: Support asynchronous reader for Upload
- bson: Integrate with the- bsoncrate.
- chrono: Integrate with the- chronocrate.
- chrono-tz: Integrate with the- chrono-tzcrate.
- url: Integrate with the- urlcrate.
- uuid: Integrate with the- uuidcrate.
- string_number: Enable the StringNumber.
- dataloader: Support DataLoader.
- secrecy: Integrate with the- secrecycrate.
- decimal: Integrate with the- rust_decimalcrate.
- bigdecimal: Integrate with the- bigdecimalcrate.
- cbor: Support for serde_cbor.
- smol_str: Integrate with the- smol_strcrate.
- hashbrown: Integrate with the- hashbrowncrate.
- time: Integrate with the- timecrate.
- tokio-sync: Integrate with the- tokio::sync::RwLockand- tokio::sync::Mutex.
- fast_chemail: Integrate with the- fast_chemailcrate.
- tempfile: Save the uploaded content in the temporary file.
- dynamic-schema: Support dynamic schema.
- graphiql: Enables the GraphiQL IDE integration
- playground: Enables the GraphQL playground IDE integration
§Integrations
- Poem async-graphql-poem
- Actix-web async-graphql-actix-web
- Warp async-graphql-warp
- Tide async-graphql-tide
- Rocket async-graphql-rocket
- Axum async-graphql-axum
§License
Licensed under either of
- Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
§References
- GraphQL
- GraphQL Multipart Request
- GraphQL Cursor Connections Specification
- GraphQL over WebSocket Protocol
- Apollo Tracing
- Apollo Federation
§Examples
All examples are in the sub-repository, located in the examples directory.
Run an example:
git submodule update # update the examples repo
cd examples && cargo run --bin [name]
§Benchmarks
Ensure that there is no CPU-heavy process in background!
cd benchmark
cargo bench
Now a HTML report is available at benchmark/target/criterion/report.
Re-exports§
- pub use base::ComplexObject;
- pub use base::Description;
- pub use custom_directive::CustomDirectiveFactory;
- pub use custom_directive::TypeDirective;
- pub use extensions::ResolveFut;
- pub use parser::Pos;
- pub use parser::Positioned;
- pub use resolver_utils::ContainerType;
- pub use resolver_utils::EnumType;
- pub use resolver_utils::ScalarType;
- pub use schema::SchemaEnv;
- pub use validation::VisitorContext;
- pub use async_graphql_parser as parser;
- pub use context::*;
- pub use types::*;
Modules§
- Query context.
- dataloaderdataloaderBatch loading support, used to solve N+1 problem.
- dynamicdynamic-schemaSuppport for dynamic schema
- Extensions for schema
- A helper module that supports HTTP
- Utilities for implementingOutputType::resolve.
- Useful GraphQL types.
Macros§
- Define a scalar
- Construct aConstValue.
Structs§
- Cache control value
- This type represents errors that can occur when deserializing.
- An error with a message and optional extensions.
- Extensions to the error.
- An error parsing an input value.
- A selection performed by a query.
- A GraphQL name.
- Represents a JSON number, whether integer or floating point.
- GraphQL request.
- Query response
- Options for SDL export
- GraphQL schema.
- Schema builder
- This type represents errors that can occur when serializing.
- An error in a GraphQL server.
- Validation results.
- Variables of a query.
Enums§
- Batch support for GraphQL requests, which is either a single query, or an array of queries
- Response for batchable queries
- Introspection mode
- An error parsing the request.
- A segment of path to a resolver.
- Validation mode
- A resolved GraphQL value, for example1or"Hello World!".
Traits§
- Represents a custom directive.
- Represents a custom input value validator.
- An error which can be extended into aError.
- Represents a GraphQL executor
- Field guard
- An extension trait forGuard.
- A GraphQL input object.
- Represents a GraphQL input type.
- A GraphQL interface.
- A GraphQL object.
- A GraphQL oneof input object.
- Represents a GraphQL output type.
- Extend aResult’s error value withErrorExtensions.
- A GraphQL subscription object
- Used to specify the GraphQL Type name.
- A GraphQL interface.
Functions§
- Interpret aConstValueas an instance of typeT.
- Convert aTintoConstValuewhich is an enum that can represent any valid GraphQL data.
Type Aliases§
- An alias of async_graphql::Error. Present for backward compatibility reasons.
- An alias of async_graphql::Result. Present for backward compatibility reasons.
- An error parsing a value of typeT.
- An alias forResult<T, Error>.
- Alias forResult<T, ServerError>.
Attribute Macros§
- Define a complex GraphQL object for SimpleObject’s complex field resolver.
- Define a directive for query.
- Define a GraphQL object with methods
- Define a Scalar
- Define a GraphQL subscription
Derive Macros§
- Attach a description toObject,ScalarorSubscription.
- Define a GraphQL enum
- Define a GraphQL input object
- Define a GraphQL interface
- Define a merged object with multiple object types.
- Define a merged subscription with multiple subscription types.
- Define a NewType Scalar
- Define a GraphQL oneof input object
- Define a GraphQL object with fields
- Define a GraphQL union