finchers_juniper/lib.rs
1// FIXME: remove this feature gate as soon as the rustc version used in docs.rs is updated
2#![cfg_attr(finchers_inject_extern_prelude, feature(extern_prelude))]
3
4//! A set of extensions for supporting Juniper integration.
5//!
6//! # Examples
7//!
8//! ```
9//! #[macro_use]
10//! extern crate finchers;
11//! # use finchers::prelude::*;
12//! extern crate finchers_juniper;
13//! #[macro_use]
14//! extern crate juniper;
15//!
16//! use juniper::{EmptyMutation, RootNode};
17//!
18//! // The contextual information used when GraphQL query executes.
19//! //
20//! // Typically it contains a connection retrieved from pool
21//! // or credential information extracted from HTTP headers.
22//! struct MyContext {
23//! // ...
24//! }
25//! impl juniper::Context for MyContext {}
26//!
27//! struct Query {}
28//! graphql_object!(Query: MyContext |&self| {
29//! field apiVersion() -> &str { "1.0" }
30//! // ...
31//! });
32//!
33//! # fn main() {
34//! let schema = RootNode::new(
35//! Query {},
36//! EmptyMutation::<MyContext>::new(),
37//! );
38//!
39//! // An endpoint which acquires a GraphQL context from request.
40//! let fetch_graphql_context =
41//! endpoint::unit().map(|| MyContext { /* ... */ });
42//!
43//! // Build an endpoint which handles GraphQL requests.
44//! let endpoint = path!(@get / "graphql" /)
45//! .and(fetch_graphql_context)
46//! .wrap(finchers_juniper::execute::nonblocking(schema));
47//! # drop(move || {
48//! # finchers::server::start(endpoint).serve("127.0.0.1:4000")
49//! # });
50//! # }
51//! ```
52
53#![doc(html_root_url = "https://docs.rs/finchers-juniper/0.2.1")]
54#![warn(
55 missing_docs,
56 missing_debug_implementations,
57 nonstandard_style,
58 rust_2018_idioms,
59 unused,
60)]
61// #![warn(rust_2018_compatibility)]
62#![cfg_attr(test, deny(warnings))]
63#![cfg_attr(test, doc(test(attr(deny(warnings)))))]
64
65extern crate bytes;
66extern crate failure;
67extern crate finchers;
68#[macro_use]
69extern crate futures;
70extern crate juniper;
71#[macro_use]
72extern crate log;
73extern crate percent_encoding;
74#[macro_use]
75extern crate serde;
76extern crate http;
77extern crate serde_json;
78extern crate serde_qs;
79
80#[cfg(test)]
81#[macro_use]
82extern crate matches;
83
84pub mod execute;
85pub mod graphiql;
86pub mod request;
87
88pub use graphiql::graphiql_source;
89pub use request::graphql_request;