[][src]Crate juniper_iron


This repository contains the Iron web framework integration for Juniper, a GraphQL implementation for Rust.

For documentation, including guides and examples, check out Juniper.

A basic usage example can also be found in the Api documentation.

Integrating with Iron

For example, continuing from the schema created above and using Iron to expose the schema on an HTTP endpoint supporting both GET and POST requests:

use iron::prelude::*;
use juniper_iron::GraphQLHandler;
use juniper::{Context, EmptyMutation, EmptySubscription};

// This function is executed for every request. Here, we would realistically
// provide a database connection or similar. For this example, we'll be
// creating the database from scratch.
fn context_factory(_: &mut Request) -> IronResult<Database> {
    Ok(Database {
        users: vec![
            ( "1000".to_owned(), User {
                id: "1000".to_owned(), name: "Robin".to_owned(),
                friend_ids: vec!["1001".to_owned()] } ),
            ( "1001".to_owned(), User {
                id: "1001".to_owned(), name: "Max".to_owned(),
                friend_ids: vec!["1000".to_owned()] } ),

impl Context for Database {}

fn main() {
    // GraphQLHandler takes a context factory function, the root object,
    // and the mutation object. If we don't have any mutations to expose, we
    // can use the empty tuple () to indicate absence.
    let graphql_endpoint = GraphQLHandler::new(

    // Start serving the schema at the root on port 8080.

See the the GraphQLHandler documentation for more information on what request methods are supported.



Handler that executes GraphQL queries in the given schema


Handler that renders GraphiQL - a graphical query editor interface


Handler that renders GraphQL Playground - a graphical query editor interface