Log in to GraphQL EditorGet started
Juniper - fast & type-safe GraphQL Servers in Rust

Tomek Poniatowicz

9/7/2020

Juniper - fast & type-safe GraphQL Servers in Rust

GraphQL started being developed internally at Facebook back in 2012, before being publicly released as open-source in 2015. GraphQL is a query language for APIs, its main advantage is allowing clients to query exactly for the type of data that is required. The definitions of all the data clients can query through the service are stored in GraphQL schema. Each field in the schema is attached to a function, called a resolver, which gets called to produce the values when a query is executed.

GraphQL is language-agnostic which makes it fairly easy to be adopted across different technologies, one of its successful implementations is done in Rust, by a library called Juniper.

Code- first, fast & type-safe GraphQL Servers in Rust

Juniper is a code-first approach that allows you to write type-safe and super fast GraphQL servers in Rust, keeping declaring and resolving GraphQL schemas as easy as possible.

GraphQL query language is fully supported, including interfaces, unions, schema introspection, validations, as well as some basic Rust crates integrations allowing you to use popular Rust types as uuid, url, chrono, or bson out of the box.

As previously mentioned Juniper is a code-first library, if you prefer the schema-first approach you can use juniper-from-schema to auto-generate resolvers for your GraphQL schema.

Although Juniper does not provide a built-in web server functionality it comes with building blocks to make integration with your servers as seamless as possible, as well as optionally providing pre-built integration for popular Rust web frameworks like:

  • Actix,
  • Hyper,
  • Iron,
  • Rocket,
  • Warp.

Example of Juniper integration for Actix

Below you can find a sample Juniper integration with the Actix web framework. The servers run on 127.0.0.1:8080 and has built-in GraphiQL for easier testing. Star it with:

cd examples/juniper
cargo run (or ``cargo watch -x run``)

Simple query example: Query and its result example

Simple mutation example with its result: Mutation and its result example

If you are looking for more advanced usage examples make sure to visit juniper-advancedexample repo.

Source: github.com/actix/examples

Check out our other blogposts

Unlocking the Power of React 19
Tomasz Gajda
Tomasz Gajda
Unlocking the Power of React 19
1 min read
23 days ago
Zeus update - GraphQL spread operator
Michał Tyszkiewicz
Michał Tyszkiewicz
Zeus update - GraphQL spread operator
1 min read
2 months ago
What is GraphQL Zeus?
Michał Tyszkiewicz
Michał Tyszkiewicz
What is GraphQL Zeus?
1 min read
2 months ago

Ready for take-off?

Elevate your work with our editor that combines world-class visual graph, documentation and API console

Get Started with GraphQL Editor