Expand description
§Juniper (GraphQL server library for Rust)
GraphQL is a data query language developed by Facebook and intended to serve mobile and web application frontends.
Juniper makes it possible to write GraphQL servers in Rust that are type-safe and blazingly fast. We also try to make declaring and resolving GraphQL schemas as convenient as Rust will allow.
Juniper doesn’t include a web server - instead it provides building blocks to make integration with existing servers straightforward, including embedded GraphiQL and/or GraphQL Playground for easy debugging.
§Getting Started
The best place to get started is Juniper Book, which contains guides with plenty of examples, covering all features of Juniper.
To get started quickly and get a feel for Juniper, check out the “Quickstart” section.
For specific information about macros, types and the Juniper API, the API docs is the best place to look.
§Features
Juniper supports the full GraphQL query language according to October 2021 GraphQL specification, including interfaces, unions, schema introspection, and validations. It does not, however, support the schema language.
As an exception to other GraphQL libraries for other languages, Juniper builds non-null
types by default. A field of type Vec<Episode>
will be converted into [Episode!]!
. The corresponding Rust type for e.g. [Episode]
would be Option<Vec<Option<Episode>>>
.
§Integrations
§Types
Juniper provides out-of-the-box integration for some very common Rust crates to make building schemas a breeze. The types from these crates will be usable in your schemas automatically after enabling the correspondent self-titled Cargo feature:
§Web server frameworks
actix-web
(juniper_actix
crate)axum
(juniper_axum
crate)hyper
(juniper_hyper
crate)rocket
(juniper_rocket
crate)warp
(juniper_warp
crate)
§API stability
Juniper has not reached 1.0 yet, thus some API instability should be expected.
§License
This project is licensed under BSD 2-Clause License.
Re-exports§
pub use crate::util::to_camel_case;
pub use crate::ast::Definition;
pub use crate::ast::Document;
pub use crate::executor::Applies;
pub use crate::executor::Context;
pub use crate::executor::ExecutionError;
pub use crate::executor::ExecutionResult;
pub use crate::executor::Executor;
pub use crate::executor::FieldError;
pub use crate::executor::FieldResult;
pub use crate::executor::FromContext;
pub use crate::executor::IntoFieldError;
pub use crate::executor::IntoResolvable;
pub use crate::executor::LookAheadArgument;
pub use crate::executor::LookAheadChildren;
pub use crate::executor::LookAheadList;
pub use crate::executor::LookAheadObject;
pub use crate::executor::LookAheadSelection;
pub use crate::executor::LookAheadValue;
pub use crate::executor::OwnedExecutor;
pub use crate::executor::Registry;
pub use crate::executor::ValuesStream;
pub use crate::executor::Variables;
pub use crate::parser::ParseError;
pub use crate::parser::ScalarToken;
pub use crate::parser::Span;
pub use crate::parser::Spanning;
pub use crate::validation::RuleError;
Modules§
- Resolve the document to values
- Utilities for building HTTP endpoints in a library-agnostic manner
- Provides GraphQLType implementations for some external types
- Marker traits for GraphQL types.
- Types used to describe a
GraphQL
schema - Query parser and language utilities
- Library tests and fixtures
- Query validation related methods and data structures
Macros§
- Asserts validness of [
Field
] [Arguments
] and returned [Type
]. - Asserts validness of the [
Field
]s arguments. See spec for more info. - Asserts that
#[graphql_interface(for = ...)]
has all the types referencing this interface in theimpl = ...
attribute argument. - Asserts that
impl = ...
attribute argument has all the types referencing this GraphQL type in#[graphql_interface(for = ...)]
. - Asserts validness of a [
Field
] return type. - Asserts that all transitive interfaces (the ones implemented by the
$interface
) are also implemented by the$implementor
. - Ensures that the given
$impl_ty
implements [Field
] and returns a [fnv1a128
] hash for it, otherwise panics with understandable message. - Formats the given [
Type
] and [WrappedValue
] into a readable GraphQL type name. - Constructs
InputValue
s via JSON-like syntax. - Constructs
Value
s via JSON-like syntax. - Constructs
Variables
via JSON-like syntax.
Structs§
- Field argument container
- Utility type to define read-only schemas
- Utillity type to define read-only schemas
- Represents the result of executing a GraphQL operation (after parsing and validating has been done).
- An ID as defined by the GraphQL specification
- An Object value
- Root query node of a schema
- Metadata for a schema
Enums§
- The default
ScalarValue
representation injuniper
. - An error that prevented query execution
- A JSON-like value that can be passed into the query execution, either out-of-band, or in-band as default variable values. These are not constant and might contain variables.
- The desired GraphQL introspection format for the canonical query (https://github.com/graphql/graphql-js/blob/90bd6ff72625173dd39a1f82cfad9336cfad8f65/src/utilities/getIntrospectionQuery.ts#L62)
Nullable
can be used in situations where you need to distinguish between an implicitly and explicitly null input value.- Entry in a GraphQL selection set
- A type literal in the syntax tree
- GraphQL type kind
- Serializable value returned from query and field execution.
Traits§
- This trait is used in
juniper::graphql_subscription
macro to get stream’s item type that implementsGraphQLValue
from type alias provided by user. - Parsing of an unstructured input value into a Rust data type.
- Maker trait for GraphQL interfaces.
- Maker trait for GraphQL objects.
- Extension of
GraphQLType
trait with asynchronous subscription execution logic. - Extension of
GraphQLValue
trait with asynchronous subscription execution logic. It should be used withGraphQLValue
in order to implement subscription resolvers on GraphQL objects. - Primary trait used to expose Rust types in a GraphQL schema.
- Extension of
GraphQLType
trait with asynchronous queries/mutations resolvers. - Maker trait for GraphQL unions.
- Primary trait used to resolve GraphQL values.
- Extension of
GraphQLValue
trait with asynchronous queries/mutations resolvers. - A trait used to convert a
ScalarToken
into a certain scalar value type - A trait marking a type that could be used as internal representation of scalar values in juniper
- Single subscription connection.
- Global subscription coordinator trait.
- Losslessly clones a Rust data type into an InputValue.
Functions§
- Execute a query in a provided schema
- Execute a query synchronously in a provided schema
- Execute the reference introspection query in the provided schema
- Resolve subscription into
ValuesStream
Type Aliases§
- An owned dynamically typed
Future
for use in cases where you can’t statically type your result or need to add some indirection. BoxFuture
, but without theSend
requirement.- The result of converting a string into a scalar value
Attribute Macros§
#[graphql_interface]
macro for generating a GraphQL interface implementation for traits and its implementers.#[graphql_object]
macro for generating a GraphQL object implementation for structs with computable field resolvers (declared via a regular Rustimpl
block).#[graphql_scalar]
macro.is interchangeable with#[derive(
GraphQLScalar
)]
macro, and is used for deriving a GraphQL scalar implementation.#[graphql_subscription]
macro for generating a GraphQL subscription implementation for structs with computable field resolvers (declared via a regular Rustimpl
block).#[graphql_union]
macro for deriving a GraphQL union implementation for traits.
Derive Macros§
#[derive(GraphQLEnum)]
macro for deriving a GraphQL enum implementation for Rust enums.#[derive(GraphQLInputObject)]
macro for deriving a GraphQL input object implementation for a Rust struct. Each non-ignored field type must itself be GraphQL input object or a GraphQL scalar.#[derive(GraphQLInterface)]
macro for generating a GraphQL interface implementation for traits and its implementers.#[derive(GraphQLObject)]
macro for deriving a GraphQL object implementation for structs.#[derive(GraphQLScalar)]
macro for deriving a GraphQL scalar implementation.#[derive(GraphQLUnion)]
macro for deriving a GraphQL union implementation for enums and structs.#[derive(ScalarValue)]
macro for deriving aScalarValue
implementation.