Fix the rest of the rocket stuff
This commit is contained in:
parent
1e348ea1bd
commit
47e7003a7b
2 changed files with 27 additions and 19 deletions
|
@ -12,7 +12,7 @@ repository = "https://github.com/graphql-rust/juniper"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
async = [ "juniper/async", "futures03" ]
|
async = [ "juniper/async" ]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.2" }
|
serde = { version = "1.0.2" }
|
||||||
|
@ -20,7 +20,7 @@ serde_json = { version = "1.0.2" }
|
||||||
serde_derive = { version = "1.0.2" }
|
serde_derive = { version = "1.0.2" }
|
||||||
juniper = { version = "0.14.0", default-features = false, path = "../juniper"}
|
juniper = { version = "0.14.0", default-features = false, path = "../juniper"}
|
||||||
|
|
||||||
futures03 = { version = "0.3.0-alpha.18", optional = true, package = "futures-preview", features = ["compat"] }
|
futures03 = { version = "0.3.0-alpha.18", package = "futures-preview", features = ["compat"] }
|
||||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
|
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
|
||||||
|
|
||||||
[dev-dependencies.juniper]
|
[dev-dependencies.juniper]
|
||||||
|
|
|
@ -38,12 +38,11 @@ Check the LICENSE file for details.
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/juniper_rocket/0.2.0")]
|
#![doc(html_root_url = "https://docs.rs/juniper_rocket/0.2.0")]
|
||||||
#![feature(decl_macro, proc_macro_hygiene)]
|
#![feature(decl_macro, proc_macro_hygiene)]
|
||||||
|
|
||||||
#![cfg_attr(feature = "async", feature(async_await, async_closure))]
|
#![cfg_attr(feature = "async", feature(async_await, async_closure))]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
io::{Cursor, Read},
|
io::Cursor,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rocket::{
|
use rocket::{
|
||||||
|
@ -63,6 +62,9 @@ use juniper::{
|
||||||
ScalarValue,
|
ScalarValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "async")]
|
||||||
|
use juniper::GraphQLTypeAsync;
|
||||||
|
|
||||||
#[cfg(feature = "async")]
|
#[cfg(feature = "async")]
|
||||||
use futures03::future::{FutureExt, TryFutureExt};
|
use futures03::future::{FutureExt, TryFutureExt};
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ use futures03::future::{FutureExt, TryFutureExt};
|
||||||
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
|
#[serde(bound = "InputValue<S>: Deserialize<'de>")]
|
||||||
enum GraphQLBatchRequest<S = DefaultScalarValue>
|
enum GraphQLBatchRequest<S = DefaultScalarValue>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Sync + Send,
|
||||||
{
|
{
|
||||||
Single(http::GraphQLRequest<S>),
|
Single(http::GraphQLRequest<S>),
|
||||||
Batch(Vec<http::GraphQLRequest<S>>),
|
Batch(Vec<http::GraphQLRequest<S>>),
|
||||||
|
@ -81,7 +83,7 @@ where
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum GraphQLBatchResponse<'a, S = DefaultScalarValue>
|
enum GraphQLBatchResponse<'a, S = DefaultScalarValue>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Sync + Send,
|
||||||
{
|
{
|
||||||
Single(http::GraphQLResponse<'a, S>),
|
Single(http::GraphQLResponse<'a, S>),
|
||||||
Batch(Vec<http::GraphQLResponse<'a, S>>),
|
Batch(Vec<http::GraphQLResponse<'a, S>>),
|
||||||
|
@ -89,7 +91,7 @@ where
|
||||||
|
|
||||||
impl<S> GraphQLBatchRequest<S>
|
impl<S> GraphQLBatchRequest<S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Send + Sync,
|
||||||
for<'b> &'b S: ScalarRefValue<'b>,
|
for<'b> &'b S: ScalarRefValue<'b>,
|
||||||
{
|
{
|
||||||
pub fn execute<'a, CtxT, QueryT, MutationT>(
|
pub fn execute<'a, CtxT, QueryT, MutationT>(
|
||||||
|
@ -118,11 +120,14 @@ where
|
||||||
pub async fn execute_async<'a, CtxT, QueryT, MutationT>(
|
pub async fn execute_async<'a, CtxT, QueryT, MutationT>(
|
||||||
&'a self,
|
&'a self,
|
||||||
root_node: &'a RootNode<'_, QueryT, MutationT, S>,
|
root_node: &'a RootNode<'_, QueryT, MutationT, S>,
|
||||||
context: &CtxT,
|
context: &'a CtxT,
|
||||||
) -> GraphQLBatchResponse<'a, S>
|
) -> GraphQLBatchResponse<'a, S>
|
||||||
where
|
where
|
||||||
QueryT: GraphQLType<S, Context = CtxT>,
|
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
||||||
MutationT: GraphQLType<S, Context = CtxT>,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
|
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
||||||
|
MutationT::TypeInfo: Send + Sync,
|
||||||
|
CtxT: Send + Sync,
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
&GraphQLBatchRequest::Single(ref request) => {
|
&GraphQLBatchRequest::Single(ref request) => {
|
||||||
|
@ -135,7 +140,7 @@ where
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
GraphQLBatchResponse::Batch(futures03::future::join_all(futures).await)
|
GraphQLBatchResponse::Batch(futures03::future::join_all(futures).await)
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +156,7 @@ where
|
||||||
|
|
||||||
impl<'a, S> GraphQLBatchResponse<'a, S>
|
impl<'a, S> GraphQLBatchResponse<'a, S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Send + Sync,
|
||||||
{
|
{
|
||||||
fn is_ok(&self) -> bool {
|
fn is_ok(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
@ -171,7 +176,7 @@ where
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct GraphQLRequest<S = DefaultScalarValue>(GraphQLBatchRequest<S>)
|
pub struct GraphQLRequest<S = DefaultScalarValue>(GraphQLBatchRequest<S>)
|
||||||
where
|
where
|
||||||
S: ScalarValue;
|
S: ScalarValue + Send + Sync;
|
||||||
|
|
||||||
/// Simple wrapper around the result of executing a GraphQL query
|
/// Simple wrapper around the result of executing a GraphQL query
|
||||||
pub struct GraphQLResponse(pub Status, pub String);
|
pub struct GraphQLResponse(pub Status, pub String);
|
||||||
|
@ -190,7 +195,7 @@ pub fn playground_source(graphql_endpoint_url: &str) -> content::Html<String> {
|
||||||
|
|
||||||
impl<S> GraphQLRequest<S>
|
impl<S> GraphQLRequest<S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Sync + Send,
|
||||||
for<'b> &'b S: ScalarRefValue<'b>,
|
for<'b> &'b S: ScalarRefValue<'b>,
|
||||||
{
|
{
|
||||||
/// Execute an incoming GraphQL query
|
/// Execute an incoming GraphQL query
|
||||||
|
@ -222,8 +227,11 @@ where
|
||||||
context: &CtxT,
|
context: &CtxT,
|
||||||
) -> GraphQLResponse
|
) -> GraphQLResponse
|
||||||
where
|
where
|
||||||
QueryT: GraphQLType<S, Context = CtxT>,
|
QueryT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
||||||
MutationT: GraphQLType<S, Context = CtxT>,
|
QueryT::TypeInfo: Send + Sync,
|
||||||
|
MutationT: GraphQLTypeAsync<S, Context = CtxT> + Send + Sync,
|
||||||
|
MutationT::TypeInfo: Send + Sync,
|
||||||
|
CtxT: Send + Sync,
|
||||||
{
|
{
|
||||||
let response = self.0.execute_async(root_node, context).await;
|
let response = self.0.execute_async(root_node, context).await;
|
||||||
let status = if response.is_ok() {
|
let status = if response.is_ok() {
|
||||||
|
@ -301,7 +309,7 @@ impl GraphQLResponse {
|
||||||
|
|
||||||
impl<'f, S> FromForm<'f> for GraphQLRequest<S>
|
impl<'f, S> FromForm<'f> for GraphQLRequest<S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Send + Sync,
|
||||||
{
|
{
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
|
@ -372,7 +380,7 @@ where
|
||||||
|
|
||||||
impl<'v, S> FromFormValue<'v> for GraphQLRequest<S>
|
impl<'v, S> FromFormValue<'v> for GraphQLRequest<S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Send + Sync,
|
||||||
{
|
{
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
|
@ -387,7 +395,7 @@ const BODY_LIMIT: u64 = 1024 * 100;
|
||||||
|
|
||||||
impl<S> FromDataSimple for GraphQLRequest<S>
|
impl<S> FromDataSimple for GraphQLRequest<S>
|
||||||
where
|
where
|
||||||
S: ScalarValue,
|
S: ScalarValue + Send + Sync,
|
||||||
{
|
{
|
||||||
type Error = String;
|
type Error = String;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue