Make all tests pass.
This commit is contained in:
parent
e50f1c9200
commit
ca84859f46
|
@ -12,10 +12,6 @@ jobs:
|
|||
name: Deploy book on gh-pages
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.46
|
||||
override: true
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Install mdBook
|
||||
|
|
|
@ -15,8 +15,9 @@ jobs:
|
|||
- uses: actions/checkout@v1
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.46
|
||||
toolchain: 1.46.0
|
||||
override: true
|
||||
components: clippy, rustfmt
|
||||
- name: Check format
|
||||
run: cargo fmt --all -- --check
|
||||
- name: Check with clippy
|
||||
|
|
|
@ -12,7 +12,7 @@ jobs:
|
|||
- uses: actions/checkout@v1
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.46
|
||||
toolchain: 1.46.0
|
||||
override: true
|
||||
- name: Install libsqlite3-dev
|
||||
run: |
|
||||
|
|
|
@ -39,7 +39,7 @@ jobs:
|
|||
steps:
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.46
|
||||
toolchain: 1.46.0
|
||||
override: true
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
|
|
@ -196,9 +196,7 @@ impl<'q> FromQuery<'q> for GQLRequest {
|
|||
let decoded = value.url_decode().map_err(|e| e.to_string())?;
|
||||
let json_value = serde_json::from_str::<serde_json::Value>(&decoded)
|
||||
.map_err(|e| e.to_string())?;
|
||||
variables = Variables::parse_from_json(json_value)
|
||||
.map_err(|e| e.to_string())?
|
||||
.into();
|
||||
variables = Variables::parse_from_json(json_value).into();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pub use async_graphql::http::GQLResponse;
|
||||
use async_graphql::{ObjectType, QueryResponse, Schema, SubscriptionType};
|
||||
use async_graphql_parser::{parse_query, query::Document};
|
||||
use async_graphql_parser::{parse_query, types::Document};
|
||||
use async_std::task;
|
||||
|
||||
#[cfg(feature = "jemalloc")]
|
||||
|
|
|
@ -30,13 +30,13 @@ impl Display for Variables {
|
|||
|
||||
impl Variables {
|
||||
/// Parse variables from JSON object.
|
||||
// TODO: Is this supposed to be able to return an error?
|
||||
pub fn parse_from_json(value: serde_json::Value) -> Result<Self> {
|
||||
Ok(if let Value::Object(obj) = value.into() {
|
||||
/// If this `value` is not a `JsonObject`, then an empty `Variables` instance will be returned.
|
||||
pub fn parse_from_json(value: serde_json::Value) -> Self {
|
||||
if let Value::Object(obj) = value.into() {
|
||||
Self(obj)
|
||||
} else {
|
||||
Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn variable_path(&mut self, path: &str) -> Option<&mut Value> {
|
||||
|
|
|
@ -45,9 +45,7 @@ impl IntoQueryBuilder for GQLRequest {
|
|||
builder = builder.operation_name(operation_name);
|
||||
}
|
||||
if let Some(variables) = self.variables {
|
||||
if let Ok(variables) = Variables::parse_from_json(variables) {
|
||||
builder = builder.variables(variables);
|
||||
}
|
||||
builder = builder.variables(Variables::parse_from_json(variables));
|
||||
}
|
||||
Ok(builder)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use crate::{
|
|||
CacheControl, Error, ObjectType, Pos, QueryEnv, QueryError, QueryResponse, Result,
|
||||
SubscriptionType, Type, Variables, ID,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use futures::channel::mpsc;
|
||||
use futures::Stream;
|
||||
use indexmap::map::IndexMap;
|
||||
|
|
|
@ -86,8 +86,7 @@ impl ConnectionTransport for WebSocketTransport {
|
|||
if let Ok(request) = serde_json::from_value::<GQLRequest>(payload) {
|
||||
let variables = request
|
||||
.variables
|
||||
.map(|value| Variables::parse_from_json(value).ok())
|
||||
.flatten()
|
||||
.map(|value| Variables::parse_from_json(value))
|
||||
.unwrap_or_default();
|
||||
match schema
|
||||
.create_subscription_stream(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::parser::types::OperationDefinition;
|
||||
use crate::parser::types::{OperationDefinition, OperationType};
|
||||
use crate::validation::visitor::{Visitor, VisitorContext};
|
||||
use crate::Positioned;
|
||||
|
||||
|
@ -16,11 +16,14 @@ impl<'a> Visitor<'a> for UploadFile {
|
|||
.registry
|
||||
.concrete_type_by_parsed_type(&var.node.var_type.node)
|
||||
{
|
||||
if ty.name() == "Upload" {
|
||||
ctx.report_error(
|
||||
vec![var.pos],
|
||||
"The Upload type is only allowed to be defined on a mutation",
|
||||
);
|
||||
if operation_definition.node.ty != OperationType::Mutation && ty.name() == "Upload"
|
||||
{
|
||||
if ty.name() == "Upload" {
|
||||
ctx.report_error(
|
||||
vec![var.pos],
|
||||
"The Upload type is only allowed to be defined on a mutation",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,13 +24,10 @@ pub async fn test_variables() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(
|
||||
Variables::parse_from_json(serde_json::json!({
|
||||
"intVal": 10,
|
||||
"intListVal": [1, 2, 3, 4, 5],
|
||||
}))
|
||||
.unwrap(),
|
||||
);
|
||||
.variables(Variables::parse_from_json(serde_json::json!({
|
||||
"intVal": 10,
|
||||
"intListVal": [1, 2, 3, 4, 5],
|
||||
})));
|
||||
let resp = query.execute(&schema).await.unwrap();
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
|
@ -90,7 +87,7 @@ pub async fn test_variable_no_value() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(Variables::parse_from_json(serde_json::json!({})).unwrap());
|
||||
.variables(Variables::parse_from_json(serde_json::json!({})));
|
||||
let resp = query.execute(&schema).await.unwrap();
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
|
@ -119,12 +116,9 @@ pub async fn test_variable_null() {
|
|||
}
|
||||
"#,
|
||||
)
|
||||
.variables(
|
||||
Variables::parse_from_json(serde_json::json!({
|
||||
"intVal": null,
|
||||
}))
|
||||
.unwrap(),
|
||||
);
|
||||
.variables(Variables::parse_from_json(serde_json::json!({
|
||||
"intVal": null,
|
||||
})));
|
||||
let resp = query.execute(&schema).await.unwrap();
|
||||
assert_eq!(
|
||||
resp.data,
|
||||
|
@ -172,12 +166,9 @@ pub async fn test_variable_in_input_object() {
|
|||
test(input: {value: $value })
|
||||
}"#;
|
||||
let resp = QueryBuilder::new(query)
|
||||
.variables(
|
||||
Variables::parse_from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
}))
|
||||
.unwrap(),
|
||||
)
|
||||
.variables(Variables::parse_from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
})))
|
||||
.execute(&schema)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -196,12 +187,9 @@ pub async fn test_variable_in_input_object() {
|
|||
test2(input: [{value: $value }, {value: $value }])
|
||||
}"#;
|
||||
let resp = QueryBuilder::new(query)
|
||||
.variables(
|
||||
Variables::parse_from_json(serde_json::json!({
|
||||
"value": 3,
|
||||
}))
|
||||
.unwrap(),
|
||||
)
|
||||
.variables(Variables::parse_from_json(serde_json::json!({
|
||||
"value": 3,
|
||||
})))
|
||||
.execute(&schema)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -220,12 +208,9 @@ pub async fn test_variable_in_input_object() {
|
|||
test(input: {value: $value })
|
||||
}"#;
|
||||
let resp = QueryBuilder::new(query)
|
||||
.variables(
|
||||
Variables::parse_from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
}))
|
||||
.unwrap(),
|
||||
)
|
||||
.variables(Variables::parse_from_json(serde_json::json!({
|
||||
"value": 10,
|
||||
})))
|
||||
.execute(&schema)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in New Issue