Merge remote-tracking branch 'upstream/master' into async-await

This commit is contained in:
Christian Legnitto 2020-01-20 22:47:05 -08:00
commit 7681f42933
8 changed files with 60 additions and 51 deletions

View file

@ -4,7 +4,13 @@ version = "0.1.0"
publish = false
edition = "2018"
[dev-dependencies]
[features]
async = ["juniper/async", "futures"]
[dependencies]
juniper = { path = "../../juniper" }
futures = { version = "=0.3.1", optional = true }
[dev-dependencies]
serde_json = { version = "1" }
fnv = "1.0.3"
fnv = "1.0.3"

View file

@ -25,6 +25,11 @@
- Fix incorrect validation with non-executed operations [#455](https://github.com/graphql-rust/juniper/issues/455)
- Correctly handle raw identifiers in field and argument names.
# [[0.14.2] 2019-12-16](https://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.2)
- Fix incorrect validation with non-executed operations [#455](https://github.com/graphql-rust/juniper/issues/455)
- Correctly handle raw identifiers in field and argument names.
# [[0.14.1] 2019-10-24](https://github.com/graphql-rust/juniper/releases/tag/juniper-0.14.1)
- Fix panic when an invalid scalar is used by a client [#434](https://github.com/graphql-rust/juniper/pull/434)

View file

@ -742,9 +742,9 @@ where
}
#[cfg(feature = "async")]
pub async fn execute_validated_query_async<'a, QueryT, MutationT, CtxT, S>(
document: Document<'a, S>,
operation_name: Option<&str>,
pub async fn execute_validated_query_async<'a, 'b, QueryT, MutationT, CtxT, S>(
document: &'b Document<'a, S>,
operation: &'b Spanning<Operation<'_, S>>,
root_node: &RootNode<'a, QueryT, MutationT, S>,
variables: &Variables<S>,
context: &CtxT,
@ -758,36 +758,14 @@ where
CtxT: Send + Sync,
{
let mut fragments = vec![];
let mut operation = None;
for def in document {
for def in document.iter() {
match def {
Definition::Operation(op) => {
if operation_name.is_none() && operation.is_some() {
return Err(GraphQLError::MultipleOperationsProvided);
}
let move_op = operation_name.is_none()
|| op.item.name.as_ref().map(|s| s.item) == operation_name;
if move_op {
operation = Some(op);
}
}
Definition::Fragment(f) => fragments.push(f),
_ => (),
};
}
let op = match operation {
Some(op) => op,
None => return Err(GraphQLError::UnknownOperationName),
};
if op.item.operation_type == OperationType::Subscription {
return Err(GraphQLError::IsSubscription);
}
let default_variable_values = op.item.variable_definitions.map(|defs| {
let default_variable_values = operation.item.variable_definitions.as_ref().map(|defs| {
defs.item
.items
.iter()
@ -816,7 +794,7 @@ where
final_vars = &all_vars;
}
let root_type = match op.item.operation_type {
let root_type = match operation.item.operation_type {
OperationType::Query => root_node.schema.query_type(),
OperationType::Mutation => root_node
.schema
@ -831,16 +809,16 @@ where
.map(|f| (f.item.name.item, &f.item))
.collect(),
variables: final_vars,
current_selection_set: Some(&op.item.selection_set[..]),
current_selection_set: Some(&operation.item.selection_set[..]),
parent_selection_set: None,
current_type: root_type,
schema: &root_node.schema,
context,
errors: &errors,
field_path: FieldPath::Root(op.start),
field_path: FieldPath::Root(operation.start),
};
value = match op.item.operation_type {
value = match operation.item.operation_type {
OperationType::Query => {
executor
.resolve_into_value_async(&root_node.query_info, &root_node)

View file

@ -111,9 +111,7 @@ fn async_simple() {
"fieldAsyncPlain": "field_async_plain",
"fieldSync": "field_sync",
"user": {
"kind": "USER",
// "name": "user1",
// "delayed": true,
"name": "user1",
},
}),
);

View file

@ -48,14 +48,14 @@ pub fn graphiql_source(graphql_endpoint_url: &str) -> String {
<head>
<title>GraphQL</title>
{stylesheet_source}
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/graphiql@0.17.2/graphiql.min.css">
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/graphiql@0.17.5/graphiql.min.css">
</head>
<body>
<div id="app"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/16.10.2/umd/react.production.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/react-dom/16.10.2/umd/react-dom.production.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/graphiql@0.17.2/graphiql.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/graphiql@0.17.5/graphiql.min.js"></script>
<script>var GRAPHQL_URL = '{graphql_url}';</script>
{fetcher_source}
</body>

View file

@ -250,16 +250,6 @@ where
{
let document = parse_document_source(document_source, &root_node.schema)?;
{
let mut ctx = ValidatorContext::new(&root_node.schema, &document);
visit_all_rules(&mut ctx, &document);
let errors = ctx.into_errors();
if !errors.is_empty() {
return Err(GraphQLError::ValidationError(errors));
}
}
let operation = get_operation(&document, operation_name)?;
{
@ -270,7 +260,7 @@ where
}
}
executor::execute_validated_query_async(document, operation_name, root_node, variables, context)
executor::execute_validated_query_async(&document, operation, root_node, variables, context)
.await
}

View file

@ -110,7 +110,36 @@ fn impl_scalar_struct(
None => quote!(),
};
#[cfg(feature = "async")]
let _async = quote!(
impl <__S> #crate_name::GraphQLTypeAsync<__S> for #ident
where
__S: #crate_name::ScalarValue + Send + Sync,
Self: #crate_name::GraphQLType<__S> + Send + Sync,
Self::Context: Send + Sync,
Self::TypeInfo: Send + Sync,
{
fn resolve_async<'a>(
&'a self,
info: &'a Self::TypeInfo,
selection_set: Option<&'a [#crate_name::Selection<__S>]>,
executor: &'a #crate_name::Executor<Self::Context, __S>,
) -> #crate_name::BoxFuture<'a, #crate_name::ExecutionResult<__S>> {
use #crate_name::GraphQLType;
use futures::future;
let v = self.resolve(info, selection_set, executor);
Box::pin(future::ready(v))
}
}
);
#[cfg(not(feature = "async"))]
let _async = quote!();
quote!(
#_async
impl<S> #crate_name::GraphQLType<S> for #ident
where
S: #crate_name::ScalarValue,

View file

@ -863,6 +863,7 @@ impl GraphQLTypeDefiniton {
Err(e) => Err(e),
}
};
use futures::future;
future::FutureExt::boxed(f)
},
)
@ -879,6 +880,7 @@ impl GraphQLTypeDefiniton {
Err(e) => Err(e),
}
};
use futures::future;
future::FutureExt::boxed(f)
)
} else {
@ -888,6 +890,7 @@ impl GraphQLTypeDefiniton {
Ok(None) => Ok(#juniper_crate_name::Value::null()),
Err(e) => Err(e),
};
use futures::future;
future::FutureExt::boxed(future::ready(v))
)
};
@ -927,7 +930,7 @@ impl GraphQLTypeDefiniton {
) -> #juniper_crate_name::BoxFuture<'b, #juniper_crate_name::ExecutionResult<#scalar>>
where #scalar: Send + Sync,
{
use futures::future;
//use futures::future;
use #juniper_crate_name::GraphQLType;
match field {
#( #resolve_matches_async )*