-
Notifications
You must be signed in to change notification settings - Fork 46
Fix: Accept all valid Float value inputs on coerce_variable_value
#1002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
630f60b
b9098bb
a06f2d6
892891a
2174352
c5f4bac
a62c087
a4c357e
23d67b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
#[test] | ||
fn test_graphql_float_variable_coercion() { | ||
// Small schema with a Float in the input object | ||
let sdl = r#" | ||
type Car { id: ID! kilometers: Float! } | ||
input CarInput { kilometers: Float! } | ||
type Query { getCarById(id: ID!): Car } | ||
type Mutation { insertACar(car: CarInput!): Car! | ||
} | ||
"#; | ||
|
||
let parsed_schema = Schema::parse_and_validate(sdl, "sdl").unwrap(); | ||
|
||
let executable_mutation = ExecutableDocument::parse_and_validate( | ||
&parsed_schema, | ||
"mutation MyCarInsertMutation($car: CarInput!){ insertACar(car:$car) { id kilometers } }", | ||
"MyCarInsertMutation", | ||
) | ||
.unwrap(); | ||
|
||
let operation = executable_mutation | ||
.operations | ||
.get(Some("MyCarInsertMutation")) | ||
.unwrap(); | ||
|
||
let kilometers_value = 3000; | ||
|
||
// Provide an integer for a Float field | ||
let input_variables = serde_json_bytes::json!({ "car": { "kilometers": kilometers_value } }); | ||
let map = match input_variables { | ||
serde_json_bytes::Value::Object(m) => m, | ||
_ => unreachable!(), | ||
}; | ||
|
||
|
||
// Coerce and validate. | ||
let coerced = coerce_variable_values(&parsed_schema, operation, &map).unwrap(); | ||
let vars_for_exec = coerced.into_inner(); | ||
|
||
// ---- Assertions ---- | ||
let car = vars_for_exec | ||
.get("car") | ||
.and_then(|value| value.as_object()) | ||
.expect("coerced `car` object"); | ||
assert_eq!( | ||
car.get("kilometers").unwrap(), | ||
kilometers_value, | ||
"kilometers should be present and a valid amount." | ||
); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.