Skip to main content

Crate gqlrs

Crate gqlrs 

Source
Expand description

§A GraphQL server library implemented in Rust

§Documentation

§Features

  • Fully supports async/await
  • Type safety
  • Rustfmt friendly (Procedural Macro)
  • Custom scalars
  • Minimal overhead
  • Easy integration (poem, actix_web, 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
  • Relay Persisted Queries

§Crate features

This crate offers the following features, all of which are not activated by default:

featureenables
apollo_tracingEnable the Apollo tracing extension.
apollo_persisted_queriesEnable the Apollo persisted queries extension.
relay_persisted_queriesEnable the Relay persisted queries extension.
boxed-traitEnables async-trait for all traits.
no_sendRemoves Send + Sync bounds from traits and futures. Enables the crate for use in single-threaded runtimes such as Cloudflare Workers.
chronoIntegrate with the chrono crate.
chrono-tzIntegrate with the chrono-tz crate.
dataloaderSupport DataLoader.
decimalIntegrate with the rust_decimal crate.
dynamic-schemaSupport dynamic schema
fast-checkGenerate minimal derive macro stubs for faster cargo check and rust-analyzer feedback during development.
fast_chemailIntegrate with the fast_chemail crate.
graphiqlEnables the GraphiQL IDE integration
jiffIntegrate with the jiff crate.
logEnable the Logger extension.
opentelemetryEnable the OpenTelemetry extension.
rawvalueSupport raw values from serde_json
secrecyIntegrate with the secrecy crate.
string_numberEnable the StringNumber.
timeIntegrate with the time crate.
tracingEnable the Tracing extension.
tempfileSave the uploaded content in the temporary file.
unblockSupport Asynchronous reader for Upload
uuidIntegrate with the uuid crate.
urlIntegrate with the url crate.
wide-integer-scalarsEnable GraphQL Int scalar implementations for Rust integer types that can hold values outside the signed 32-bit GraphQL Int range.

§Integrations

  • Poem gqlrs-poem
  • Actix-web gqlrs-actix-web
  • Warp gqlrs-warp
  • Rocket gqlrs-rocket
  • Axum gqlrs-axum

§License

Licensed under either of

§References

§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::InputObjectType;
pub use base::InputType;
pub use base::InterfaceType;
pub use base::ObjectType;
pub use base::OneofObjectType;
pub use base::OutputType;
pub use base::OutputTypeMarker;
pub use base::TypeName;
pub use base::UnionType;
pub use custom_directive::CustomDirective;
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::IntrospectionMode;
pub use schema::Schema;
pub use schema::SchemaBuilder;
pub use sendable::MaybeSend;
pub use sendable::MaybeSync;
pub use validation::ValidationMode;
pub use validation::ValidationResult;
pub use async_graphql_parser as parser;
pub use context::*;
pub use types::*;

Modules§

context
Query context.
dataloaderdataloader
Batch loading support, used to solve N+1 problem.
dynamicdynamic-schema
Support for dynamic schema
extensions
Extensions for schema
http
A helper module that supports HTTP
resolver_utils
Utilities for implementing OutputType::resolve.
runtime
Runtime abstraction traits
sendable
Conditional Send/Sync bounds for single-threaded runtime support.
types
Useful GraphQL types.

Macros§

scalar
Define a scalar
value
Construct a ConstValue.

Structs§

CacheControl
Cache control value
DeserializerError
This type represents errors that can occur when deserializing.
Error
An error with a message and optional extensions.
ErrorExtensionValues
Extensions to the error.
Extensions
Extensions of a query.
InputValueError
An error parsing an input value.
Lookahead
A selection performed by a query.
Name
A GraphQL name.
Number
Represents a JSON number, whether integer or floating point.
Request
GraphQL request.
Response
Query response
SDLExportOptions
Options for SDL export
Schema
GraphQL schema.
SchemaBuilder
Schema builder
SerializerError
This type represents errors that can occur when serializing.
ServerError
An error in a GraphQL server.
ValidationResult
Validation results.
ValidatorAdaptervalidator
Adapter that bridges the validator::Validate trait to async-graphql’s CustomValidator.
Variables
Variables of a query.

Enums§

BatchRequest
Batch support for GraphQL requests, which is either a single query, or an array of queries
BatchResponse
Response for batchable queries
IntrospectionMode
Introspection mode
ParseRequestError
An error parsing the request.
PathSegment
A segment of path to a resolver.
ValidationMode
Validation mode
Value
A resolved GraphQL value, for example 1 or "Hello World!".

Traits§

CustomDirective
Represents a custom directive.
CustomValidator
Represents a custom input value validator.
CustomValidatorWithContext
Represents a custom input value validator that has access to the request context.
ErrorExtensions
An error which can be extended into a Error.
Executor
Represents a GraphQL executor
Guard
Field guard
GuardExt
An extension trait for Guard.
InputObjectType
A GraphQL input object.
InputType
Represents a GraphQL input type.
InterfaceType
A GraphQL interface.
IntoError
A trait for types that can be converted into a GraphQL [Error].
ObjectType
A GraphQL object.
OneofObjectType
A GraphQL oneof input object.
OutputType
Represents a GraphQL output type.
OutputTypeMarker
Marker trait for GraphQL output type metadata.
ResultExt
Extend a Result’s error value with ErrorExtensions.
SubscriptionType
A GraphQL subscription object
TypeName
Used to specify the GraphQL Type name.
UnionType
A GraphQL interface.
ValidatorExtvalidator
Extension trait for converting validator::ValidationErrors into InputValueError.

Functions§

from_value
Interpret a ConstValue as an instance of type T.
to_value
Convert a T into ConstValue which is an enum that can represent any valid GraphQL data.

Type Aliases§

ErrorFormatterno_send
FieldError
An alias of gqlrs::Error. Present for backward compatibility reasons.
FieldResult
An alias of gqlrs::Result. Present for backward compatibility reasons.
InputValueResult
An error parsing a value of type T.
Result
An alias for Result<T, Error>.
ServerResult
Alias for Result<T, ServerError>.

Attribute Macros§

ComplexInterface
Define resolvers for an interface type at the interface level.
ComplexObject
Define a complex GraphQL object for SimpleObject’s complex field resolver.
Directive
Define a directive for query.
Object
Define a GraphQL object with methods
Scalar
Define a Scalar
Subscription
Define a GraphQL subscription
TypeDirective

Derive Macros§

Description
Attach a description to Object, Scalar or Subscription.
Enum
Define a GraphQL enum
InputObject
Define a GraphQL input object
Interface
Define a GraphQL interface
MergedObject
Define a merged object with multiple object types.
MergedSubscription
Define a merged subscription with multiple subscription types.
NewType
Define a NewType Scalar
OneofObject
Define a GraphQL oneof input object
SimpleObject
Define a GraphQL object with fields
Union
Define a GraphQL union