Juniper - fast & type-safe GraphQL Servers in Rust
Tags: graphql, rust, webdev, beginners
Published: 2020-09-08 05:49:02

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](https://github.com/graphql-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](https://github.com/davidpdrsn/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 server runs 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](https://dev-to-uploads.s3.amazonaws.com/i/fqon3qfm10ik11kou3ni.png)

Simple mutation example with its result:
![Mutation and its result example](https://dev-to-uploads.s3.amazonaws.com/i/ekp7yxw6f4wwj43rlze9.png)

If you are looking for more advanced usage examples make sure to visit [juniper-advanced](https://github.com/actix/examples/tree/master/juniper-advanced) example repo.

##### Source: [github.com/actix/examples](https://github.com/actix/examples/tree/master/juniper)

---

## Want to speed up your GraphQL schema development?

*GraphQL Editor* is a supportive tool for both advanced GraphQL users as well as those taking their first steps with GraphQL APIs. Our all-in-one development environment for GraphQL will help you build, manage & deploy your GraphQL API much faster. **[Try GraphQL Editor for free!](https://graphqleditor.com)**


[![GraphQL Editor](https://dev-to-uploads.s3.amazonaws.com/i/a7qwlawx8v594fs2bq0a.gif)](https://graphqleditor.com/)