gqlrs
a high-performance graphql server library that's fully specification compliant
Repository • Upstream Book • Upstream 中文文档 • Upstream Docs • Upstream Cargo package
This crate uses #![forbid(unsafe_code)] to ensure everything is implemented in 100% safe Rust.
About this project
gqlrs is a rebranded clone of the upstream async-graphql project.
This repository keeps an explicit reference to the original project while using the gqlrs name for this codebase and package metadata.
For compatibility with the existing Rust API and examples, many code snippets still import the crate under the async_graphql alias. When depending on the rebranded package directly, use Cargo's package key if you want to keep that alias:
[]
= { = "gqlrs", = "0.1.0" }
Static schema
use Error;
use ;
use *;
use ;
;
async
async
Dynamic schema
Requires the dynamic-schema feature to be enabled.
use Error;
use ;
use *;
use ;
async
async
⚠️Security
I strongly recommend limiting the complexity and depth of queries in a production environment to avoid possible DDos attacks.
Features
- 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, 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.89.0 or later
Examples
All examples are in the sub-repository, located in the examples directory.
git submodule update # update the examples repo
cd examples && cargo run --bin [name]
For more information, see the sub-repository README.md.
Integrations
Integrations are what glue gqlrs with your web server, here are provided ones, or you can build your own!
- Poem
gqlrs-poem - Actix-web
gqlrs-actix-web - Warp
gqlrs-warp - Rocket
gqlrs-rocket - Axum
gqlrs-axum
Crate features
This crate offers the following features. Most are not activated by default, except the integrations of GraphiQL (graphiql):
| feature | enables |
|---|---|
apollo_tracing |
Enable the Apollo tracing extension. |
apollo_persisted_queries |
Enable the Apollo persisted queries extension. |
boxed-trait |
Enables async-trait for all traits. |
chrono |
Integrate with the chrono crate. |
chrono-tz |
Integrate with the chrono-tz crate. |
dataloader |
Support DataLoader. |
decimal |
Integrate with the rust_decimal crate. |
dynamic-schema |
Support dynamic schema |
fast-check |
Generate minimal derive macro stubs for faster cargo check and rust-analyzer feedback during development. |
graphiql |
Enables the GraphiQL IDE integration |
log |
Enable the Logger extension. |
rawvalue |
Support raw values from serde_json |
secrecy |
Integrate with the secrecy crate. |
string_number |
Enable the StringNumber. |
time |
Integrate with the time crate. |
tracing |
Enable the Tracing extension. |
tempfile |
Save the uploaded content in the temporary file. |
unblock |
Support Asynchronous reader for Upload |
uuid |
Integrate with the uuid crate. |
url |
Integrate with the url crate. |
Extra Extensions
Additional extensions are available in the gqlrs-extras crate. These extensions require additional dependencies and are maintained separately.
See the extras crate README for more information.
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 available.
Who's using upstream async-graphql in production?
- Vector
- DiveDB
- Kairos Sports tech
- AxieInfinity
- Nando's
- Prima.it
- VoxJar
- Zenly
- Brevz
- thorndyke
- My Data My Consent
Community Showcase
- rust-actix-graphql-sqlx-postgresql Using 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
- grpc_graphql_gateway is an open-source protoc plugin that generates GraphQL execution server code from your gRPC/Protocol Buffers definitions.
Blog Posts
- Async GraphQL with Rust
- GraphQL in Rust
- How to implement a Rust micro-service using Rocket, GraphQL, PostgreSQL
- Running GraphQL on Lambda with Rust
References
- GraphQL
- GraphQL Multipart Request
- Multipart HTTP protocol for GraphQL subscriptions
- GraphQL Cursor Connections Specification
- GraphQL over WebSocket Protocol
- Apollo Tracing
- Apollo Federation
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.