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_actixcrate)axum(juniper_axumcrate)hyper(juniper_hypercrate)rocket(juniper_rocketcrate)warp(juniper_warpcrate)
§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::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::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;pub use arcstr;
Modules§
- executor
- Resolve the document to values
- http
- Utilities for building HTTP endpoints in a library-agnostic manner
- integrations
- Provides GraphQLType implementations for some external types
- marker
- Marker traits for GraphQL types.
- meta
- Types used to describe a
GraphQLschema - parser
- Query parser and language utilities
- tests
- Library tests and fixtures
- validation
- Query validation related methods and data structures
Macros§
- assert_
field - Asserts validness of [
Field] [Arguments] and returned [Type]. - assert_
field_ args - Asserts validness of the [
Field]s arguments. See spec for more info. - assert_
implemented_ for - Asserts that
#[graphql_interface(for = ...)]has all the types referencing this interface in theimpl = ...attribute argument. - assert_
interfaces_ impls - Asserts that
impl = ...attribute argument has all the types referencing this GraphQL type in#[graphql_interface(for = ...)]. - assert_
subtype - Asserts validness of a [
Field] return type. - assert_
transitive_ impls - Asserts that all transitive interfaces (the ones implemented by the
$interface) are also implemented by the$implementor. - checked_
hash - Ensures that the given
$impl_tyimplements [Field] and returns a [fnv1a128] hash for it, otherwise panics with understandable message. - const_
concat - Concatenates
conststrs in aconstcontext. - format_
type - Formats the given [
Type] and [WrappedValue] into a readable GraphQL type name. - graphql_
input_ value - Constructs
InputValues via JSON-like syntax. - graphql_
value - Constructs
Values via JSON-like syntax. - graphql_
vars - Constructs
Variablesvia JSON-like syntax.
Structs§
- ArcStr
- A better atomically-reference counted string type.
- Arguments
- Field argument container
- Empty
Mutation - Utility type to define read-only schemas
- Empty
Subscription - Utillity type to define read-only schemas
- Execution
Output - Represents the result of executing a GraphQL operation (after parsing and validating has been done).
- ID
- An ID as defined by the GraphQL specification
- Object
- An Object value
- Operation
- Root
Node - Root query node of a schema
- Scalar
- Transparent wrapper over a value, indicating it being a
ScalarValue. - Schema
Type - Metadata for a schema
- Type
- Type literal in a syntax tree.
- Wrong
Input Scalar Type Error - Error of a
ScalarValuenot matching the expected type.
Enums§
- Default
Scalar Value - The default
ScalarValuerepresentation injuniper. - GraphQL
Error - An error that prevented query execution
- Input
Value - 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.
- Introspection
Format - The desired GraphQL introspection format for the canonical query (https://github.com/graphql/graphql-js/blob/90bd6ff72625173dd39a1f82cfad9336cfad8f65/src/utilities/getIntrospectionQuery.ts#L62)
- Nullable
Nullablecan be used in situations where you need to distinguish between an implicitly and explicitly null input value.- Operation
Type - Selection
- Entry in a GraphQL selection set
- Type
Kind - GraphQL type kind
- Value
- Serializable value returned from query and field execution.
Traits§
- AnyExt
- Extension of
Anyfor using its methods directly on the value withoutdyn. - Extract
Type From Stream - This trait is used in
juniper::graphql_subscriptionmacro to get stream’s item type that implementsGraphQLValuefrom type alias provided by user. - From
Input Value - Parsing of an unstructured
InputValueinto a Rust data type. - From
Scalar Value - Parsing of a
ScalarValueinto a Rust data type. - GraphQL
Interface - Maker trait for GraphQL interfaces.
- GraphQL
Object - Maker trait for GraphQL objects.
- GraphQL
Subscription Type - Extension of
GraphQLTypetrait with asynchronous subscription execution logic. - GraphQL
Subscription Value - Extension of
GraphQLValuetrait with asynchronous subscription execution logic. It should be used withGraphQLValuein order to implement subscription resolvers on GraphQL objects. - GraphQL
Type - Primary trait used to expose Rust types in a GraphQL schema.
- GraphQL
Type Async - Extension of
GraphQLTypetrait with asynchronous queries/mutations resolvers. - GraphQL
Union - Maker trait for GraphQL unions.
- GraphQL
Value - Primary trait used to resolve GraphQL values.
- GraphQL
Value Async - Extension of
GraphQLValuetrait with asynchronous queries/mutations resolvers. - Into
Field Result - Trait for wrapping
StreamintoOkif it’s notResult. - Into
Input Value - Conversion into an
InputValue. - Into
Value - Conversion into a
Value. - Parse
Scalar Value - A trait used to convert a
ScalarTokeninto a certain scalar value type - Scalar
Value - Type that could be used as internal representation of scalar values (e.g. inside
Valueand [InputValue]). - Subscription
Connection - Single subscription connection.
- Subscription
Coordinator - Global subscription coordinator trait.
- ToInput
Value - Losslessly clones a Rust data type into an
InputValue. - ToScalar
Value - Conversion of a Rust data type into a
ScalarValue. - TryTo
Primitive - Fallible representation of a
ScalarValueas one of the types it consists of, or derived ones from them.
Functions§
- execute
- Execute a query in a provided schema
- execute_
sync - Execute a query synchronously in a provided schema
- introspect
- Execute the reference introspection query in the provided schema
- resolve_
into_ stream - Resolve subscription into
ValuesStream
Type Aliases§
- BoxFuture
- An owned dynamically typed
Futurefor use in cases where you can’t statically type your result or need to add some indirection. - Local
BoxFuture BoxFuture, but without theSendrequirement.- Parse
Scalar Result - The result of converting a string into a scalar value
Attribute Macros§
- graphql_
interface #[graphql_interface]macro for generating a GraphQL interface implementation for traits and its implementers.- graphql_
object #[graphql_object]macro for generating a GraphQL object implementation for structs with computable field resolvers (declared via a regular Rustimplblock).- graphql_
scalar #[graphql_scalar]macro.is interchangeable with the#[derive(GraphQLScalar)]macro, and is used for deriving a GraphQL scalar implementation.- graphql_
subscription #[graphql_subscription]macro for generating a GraphQL subscription implementation for structs with computable field resolvers (declared via a regular Rustimplblock).- graphql_
union #[graphql_union]macro for deriving a GraphQL union implementation for traits.
Derive Macros§
- GraphQL
Enum #[derive(GraphQLEnum)]macro for deriving a GraphQL enum implementation for Rust enums.- GraphQL
Input Object #[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.- GraphQL
Interface #[derive(GraphQLInterface)]macro for generating a GraphQL interface implementation for traits and its implementers.- GraphQL
Object #[derive(GraphQLObject)]macro for deriving a GraphQL object implementation for structs.- GraphQL
Scalar #[derive(GraphQLScalar)]macro for deriving a GraphQL scalar implementation.- GraphQL
Union #[derive(GraphQLUnion)]macro for deriving a GraphQL union implementation for enums and structs.- Scalar
Value #[derive(ScalarValue)]macro for deriving aScalarValueimplementation.