- Notifications
You must be signed in to change notification settings - Fork0
A GraphQL server library implemented in Rust
License
vstepanyuk/async-graphql
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
a high-performance graphql server library that's fully specification compliant
Book •中文文档 •Docs •GitHub repository •Cargo package
This crate uses#![forbid(unsafe_code)]
to ensure everything is implemented in 100% safe Rust.
use std::error::Error;use async_graphql::{http::GraphiQLSource,EmptyMutation,EmptySubscription,Object,Schema};use async_graphql_poem::*;use poem::{listener::TcpListener, web::Html,*};structQuery;#[Object]implQuery{asyncfnhowdy(&self) ->&'staticstr{"partner"}}#[handler]asyncfngraphiql() ->implIntoResponse{Html(GraphiQLSource::build().finish())}#[tokio::main]asyncfnmain() ->Result<(),Box<dynError>>{// create the schemalet schema =Schema::build(Query,EmptyMutation,EmptySubscription).finish();// start the http serverlet 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(())}
Requires thedynamic-schema
feature to be enabled.
use std::error::Error;use async_graphql::{dynamic::*, http::GraphiQLSource};use async_graphql_poem::*;use poem::{listener::TcpListener, web::Html,*};#[handler]asyncfngraphiql() ->implIntoResponse{Html(GraphiQLSource::build().finish())}#[tokio::main]asyncfnmain() ->Result<(),Box<dynError>>{let query =Object::new("Query").field(Field::new("howdy",TypeRef::named_nn(TypeRef::STRING), |_|FieldFuture::new(async{"partner"}),));// create the schemalet schema =Schema::build(query,None,None).register(query).finish()?;// start the http serverlet 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(())}
I strongly recommend limiting thecomplexity and depth of queries in a production environment to avoid possible DDos attacks.
- Static and dynamic schemas are fully supported
- Fully supports async/await
- Type safety
- Rustfmt friendly (Procedural Macro)
- Custom scalars
- Minimal overhead
- Easy integration (poem,axum,actix-web,tide,warp,rocket ...)
- Upload files (Multipart request)
- Subscriptions (WebSocket transport)
- Custom extensions
- Error extensions
- Limit query complexity/depth
- Batch queries
- Apollo Persisted Queries
- Apollo Tracing extension
- Apollo Federation(v2)
Note: Minimum supported Rust version: 1.86.0 or later
All examples are in thesub-repository, located in the examples directory.
git submodule update# update the examples repocd examples&& cargo run --bin [name]
For more information, see thesub-repository README.md.
Integrations are what glueasync-graphql
with your web server, here are provided ones, or you can build your own!
- Poemasync-graphql-poem
- Actix-webasync-graphql-actix-web
- Warpasync-graphql-warp
- Tideasync-graphql-tide
- Rocketasync-graphql-rocket
- Axumasync-graphql-axum
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 theApollo tracing extension. |
apollo_persisted_queries | Enable theApollo persisted queries extension. |
boxed-trait | Enablesasync-trait for all traits. |
bson | Integrate with thebson crate. |
bigdecimal | Integrate with thebigdecimal crate. |
cbor | Support forserde_cbor. |
chrono | Integrate with thechrono crate. |
chrono-tz | Integrate with thechrono-tz crate. |
dataloader | SupportDataLoader. |
decimal | Integrate with therust_decimal crate. |
dynamic-schema | Support dynamic schema |
fast_chemail | Integrate with thefast_chemail crate. |
graphiql | Enables theGraphiQL IDE integration |
hashbrown | Integrate with thehashbrown crate. |
log | Enable theLogger extension. |
opentelemetry | Enable theOpenTelemetry extension. |
playground | Enables theGraphQL playground IDE integration |
rawvalue | Support raw values fromserde_json |
secrecy | Integrate with thesecrecy crate. |
smol_str | Integrate with thesmol_str crate. |
string_number | Enable theStringNumber. |
time | Integrate with thetime crate. |
tracing | Enable theTracing extension. |
tempfile | Save the uploaded content in the temporary file. |
tokio-sync | Integrate with thetokio::sync::RwLock andtokio::sync::Mutex . |
unblock | SupportAsynchronous reader for Upload |
uuid | Integrate with theuuid crate. |
url | Integrate with theurl crate. |
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 crateasync_graphql_apollo_studio_extension
to make this available.
- Vector
- DiveDB
- Kairos Sports tech
- AxieInfinity
- Nando's
- Prima.it
- VoxJar
- Zenly
- Brevz
- thorndyke
- My Data My Consent
- rust-actix-graphql-sqlx-postgresqlUsing GraphQL with Rust and Apollo Federation
- entity-rs A simplistic framework based on TAO, Facebook's distributed database for Social Graph.
- vimwiki-server Provides graphql server to inspect and manipulate vimwiki files.
- Diana Diana is a GraphQL system for Rust that's designed to work as simply as possible out of the box, without sacrificing configuration ability.
- cindythink
- sudograph
- Async GraphQL with Rust
- GraphQL in Rust
- How to implement a Rust micro-service using Rocket, GraphQL, PostgreSQL
- Running GraphQL on Lambda with Rust
- GraphQL
- GraphQL Multipart Request
- Multipart HTTP protocol for GraphQL subscriptions
- GraphQL Cursor Connections Specification
- GraphQL over WebSocket Protocol
- Apollo Tracing
- Apollo Federation
Licensed under either of
- Apache License, Version 2.0,(LICENSE-APACHE orhttp://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT orhttp://opensource.org/licenses/MIT)at your option.
About
A GraphQL server library implemented in Rust
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Rust99.8%
- Handlebars0.2%