# async-graphql **a high-performance graphql server library that's fully specification compliant** [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) • [GitHub repository](https://github.com/async-graphql/async-graphql) • [Cargo package](https://crates.io/crates/async-graphql) --- ![ci status](https://github.com/async-graphql/async-graphql/workflows/CI/badge.svg) [![code coverage](https://codecov.io/gh/async-graphql/async-graphql/branch/master/graph/badge.svg)](https://codecov.io/gh/async-graphql/async-graphql/) [![Unsafe Rust forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) [![Crates.io version](https://img.shields.io/crates/v/async-graphql.svg)](https://crates.io/crates/async-graphql) [![docs.rs docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://docs.rs/async-graphql) [![downloads](https://img.shields.io/crates/d/async-graphql.svg)](https://crates.io/crates/async-graphql) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/async-graphql/async-graphql/compare) _This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust._

Static schema

```rs use std::error::Error;

use asyncgraphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Object, Schema}; use asyncgraphql_poem::*; use poem::{listener::TcpListener, web::Html, *};

struct Query;

[Object]

impl Query { async fn howdy(&self) -> &'static str { "partner" } }

[handler]

async fn graphiql() -> impl IntoResponse { Html(GraphiQLSource::build().finish()) }

[tokio::main]

async fn main() -> Result<(), Box> { // create the schema let schema = Schema::build(Query, EmptyMutation, EmptySubscription).finish();

// start the http server
let app = Route::new().at("/", get(graphiql).post(GraphQL::new(schema)));
println!("GraphiQL: http://localhost:8000");
Server::new(TcpListener::bind("0.0.0.0:8000"))
    .run(app)
    .await?;
Ok(())

} ```

Dynamic schema

Requires the dynamic-schema feature to be enabled.

```rs use std::error::Error;

use asyncgraphql::{dynamic::*, http::GraphiQLSource}; use asyncgraphql_poem::*; use poem::{listener::TcpListener, web::Html, *};

[handler]

async fn graphiql() -> impl IntoResponse { Html(GraphiQLSource::build().finish()) }

[tokio::main]

async fn main() -> Result<(), Box> { let query = Object::new("Query").field(Field::new( "howdy", TypeRef::namednn(TypeRef::STRING), || FieldFuture::new(async { "partner" }), ));

// create the schema
let schema = Schema::build(query, None, None).register(query).finish()?;

// start the http server
let app = Route::new().at("/", get(graphiql).post(GraphQL::new(schema)));
println!("GraphiQL: http://localhost:8000");
Server::new(TcpListener::bind("0.0.0.0:8000"))
    .run(app)
    .await?;
Ok(())

} ```

Features

Note: Minimum supported Rust version: 1.68.0 or later

Examples

All examples are in the sub-repository, located in the examples directory.

shell git submodule update # update the examples repo cd examples && cargo run --bin [name]

Integrations

Integrations are what glue async-graphql with your web server, here are provided ones, or you can build your own!

Crate features

This crate offers the following features. Most are not activated by default, except the integrations of GraphiQL (graphiql) and GraphQL Playground (playground):

| feature | enables | |:-------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | apollo_tracing | Enable the Apollo tracing extension. | | apollo_persisted_queries | Enable the Apollo persisted queries extension. | | 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 bson crate. | | chrono | Integrate with the chrono crate. | | chrono-tz | Integrate with the chrono-tz crate. | | url | Integrate with the url crate. | | uuid | Integrate with the uuid crate. | | uuid08 | Integrate with the uuid 0.8 crate. | | string_number | Enable the StringNumber. | | dataloader | Support DataLoader. | | secrecy | Integrate with the secrecy crate. | | decimal | Integrate with the rust_decimal crate. | | bigdecimal | Integrate with the bigdecimal crate. | | cbor | Support for serde_cbor. | | smol_str | Integrate with the smol_str crate. | | hashbrown | Integrate with the hashbrown crate. | | time | Integrate with the time crate. | | tokio-sync | Integrate with the tokio::sync::RwLock and tokio::sync::Mutex. | | fast_chemail | Integrate with the fast_chemail crate. | | 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 |

Observability

One of the tools used to monitor your graphql server in production is Apollo Studio. Apollo Studio is a cloud platform that helps you build, monitor, validate, and secure your organization's data graph. Add the extension crate async_graphql_apollo_studio_extension to make this avaliable.

Who's using async-graphql in production?

Community Showcase

Blog Posts

References

License

Licensed under either of